-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pprust::item_to_string incorrectly prints ident for macro invocation items #24995
Comments
Triage: Is this an issue after all? We have For the posteriority, by the way, the following is a modern rendition of the example code (tested with #![feature(rustc_private)]
extern crate syntax;
use syntax::ast;
use syntax::codemap::{DUMMY_SP, respan};
use syntax::parse::token;
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::tokenstream;
fn main() {
let item = P(ast::Item {
ident: token::gensym_ident("DUMMY"),
id: ast::DUMMY_NODE_ID,
attrs: vec![],
node: ast::ItemKind::Mac(
respan(
DUMMY_SP,
ast::Mac_ {
path: ast::Path{ span: DUMMY_SP, global: false,
segments: vec![ast::PathSegment{
identifier: token::gensym_ident("my_macro"),
parameters: ast::PathParameters::none()
}]
},
tts: vec![tokenstream::TokenTree::Token(
DUMMY_SP,
token::Token::Literal(
token::Lit::Str_(
token::gensym("abc")
), None))]
}
)
),
vis: ast::Visibility::Inherited,
span: DUMMY_SP,
});
println!("{}", pprust::item_to_string(&item));
} |
I cannot reproduce this today, so I'm going to close. Edit: That is, the code examples don't compile -- and there's been some major churn in this area with macros 1.1 / 2.0 impending. |
pprust::item_to_string
outputs theItem
'sident
. Usually theident
is a zeroname
, and thus doesn't show anything, but a user generated AST may have anident
, which is then shown.The
Item
documentation isn't clear about how to generate a dummy name, and there is noDUMMY_IDENT
orDUMMY_NAME
, similar to the existingDUMMY_SP
andDUMMY_NODE_ID
.The fix for this is probably just to remove the line. that outputs the
ident
. The output of a visibility should probably also be removed.It might be useful to have a
DUMMY_IDENT
const orsyntax::ast::Ident::dummy()
function to generate a dummy ident, and/or aDUMMY_NAME
const.Playpen
The text was updated successfully, but these errors were encountered: