auto merge of #16419 : huonw/rust/pretty-expanded-hygiene, r=pnkfelix
Different Identifiers and Names can have identical textual representations, but different internal representations, due to the macro hygiene machinery (syntax contexts and gensyms). This provides a way to see these internals by compiling with `--pretty expanded,hygiene`. This is useful for debugging & hacking on macros (e.g. diagnosing https://github.com/rust-lang/rust/issues/15750/https://github.com/rust-lang/rust/issues/15962 likely would've been faster with this functionality). E.g. ```rust #![feature(macro_rules)] // minimal junk #![no_std] macro_rules! foo { ($x: ident) => { y + $x } } fn bar() { foo!(x) } ``` ```rust #![feature(macro_rules)] // minimal junk #![no_std] fn bar /* 61#0 */() { y /* 60#2 */ + x /* 58#3 */ } ```
This commit is contained in:
commit
d398eb76ae
8 changed files with 685 additions and 558 deletions
|
|
@ -33,6 +33,8 @@ use std::io;
|
|||
use std::mem;
|
||||
|
||||
pub enum AnnNode<'a> {
|
||||
NodeIdent(&'a ast::Ident),
|
||||
NodeName(&'a ast::Name),
|
||||
NodeBlock(&'a ast::Block),
|
||||
NodeItem(&'a ast::Item),
|
||||
NodeExpr(&'a ast::Expr),
|
||||
|
|
@ -1729,14 +1731,16 @@ impl<'a> State<'a> {
|
|||
pub fn print_ident(&mut self, ident: ast::Ident) -> IoResult<()> {
|
||||
if self.encode_idents_with_hygiene {
|
||||
let encoded = ident.encode_with_hygiene();
|
||||
word(&mut self.s, encoded.as_slice())
|
||||
try!(word(&mut self.s, encoded.as_slice()))
|
||||
} else {
|
||||
word(&mut self.s, token::get_ident(ident).get())
|
||||
try!(word(&mut self.s, token::get_ident(ident).get()))
|
||||
}
|
||||
self.ann.post(self, NodeIdent(&ident))
|
||||
}
|
||||
|
||||
pub fn print_name(&mut self, name: ast::Name) -> IoResult<()> {
|
||||
word(&mut self.s, token::get_name(name).get())
|
||||
try!(word(&mut self.s, token::get_name(name).get()));
|
||||
self.ann.post(self, NodeName(&name))
|
||||
}
|
||||
|
||||
pub fn print_for_decl(&mut self, loc: &ast::Local,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue