Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use syntax::source_map::{SourceMap, Spanned};
use syntax::parse::ParseSess;
use syntax::print::pp::{self, Breaks};
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
use syntax::print::pprust::{Comments, PrintState};
use syntax::print::pprust::{self, Comments, PrintState};
use syntax::symbol::kw;
use syntax::util::parser::{self, AssocOp, Fixity};
use syntax_pos::{self, BytePos, FileName};
Expand Down Expand Up @@ -90,6 +90,15 @@ impl<'a> PrintState<'a> for State<'a> {
fn comments(&mut self) -> &mut Option<Comments<'a>> {
&mut self.comments
}

fn print_ident(&mut self, ident: ast::Ident) {
self.s.word(pprust::ast_ident_to_string(ident, ident.is_raw_guess()));
self.ann.post(self, AnnNode::Name(&ident.name))
}

fn print_generic_args(&mut self, args: &ast::GenericArgs, _colons_before_params: bool) {
span_bug!(args.span(), "AST generic args printed by HIR pretty-printer");
}
}

pub const INDENT_UNIT: usize = 4;
Expand Down Expand Up @@ -1442,15 +1451,6 @@ impl<'a> State<'a> {
self.s.word(i.to_string())
}

pub fn print_ident(&mut self, ident: ast::Ident) {
if ident.is_raw_guess() {
self.s.word(format!("r#{}", ident.name));
} else {
self.s.word(ident.as_str().to_string());
}
self.ann.post(self, AnnNode::Name(&ident.name))
}

pub fn print_name(&mut self, name: ast::Name) {
self.print_ident(ast::Ident::with_empty_ctxt(name))
}
Expand Down
12 changes: 11 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use crate::symbol::{Ident, Symbol as Name};
pub use crate::util::parser::ExprPrecedence;

use crate::ext::hygiene::{Mark, SyntaxContext};
use crate::parse::token;
use crate::parse::token::{self, DelimToken};
use crate::print::pprust;
use crate::ptr::P;
use crate::source_map::{dummy_spanned, respan, Spanned};
Expand Down Expand Up @@ -1298,6 +1298,16 @@ impl Mac_ {
}
}

impl MacDelimiter {
crate fn to_token(self) -> DelimToken {
match self {
MacDelimiter::Parenthesis => DelimToken::Paren,
MacDelimiter::Bracket => DelimToken::Bracket,
MacDelimiter::Brace => DelimToken::Brace,
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct MacroDef {
pub tokens: TokenStream,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ mod tests {
matches_codepattern,
"matches_codepattern",
pprust::to_string(|s| fake_print_crate(s, &krate)),
"macro_rules! zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)));".to_string());
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
})
}
}
Loading