diff --git a/rustfmt-core/src/macros.rs b/rustfmt-core/src/macros.rs index a8a8c28c585..2ddac12bce0 100644 --- a/rustfmt-core/src/macros.rs +++ b/rustfmt-core/src/macros.rs @@ -114,6 +114,20 @@ fn parse_macro_arg(parser: &mut Parser) -> Option { None } +/// Rewrite macro name without using pretty-printer if possible. +fn rewrite_macro_name(path: &ast::Path, extra_ident: Option) -> String { + let name = if path.segments.len() == 1 { + // Avoid using pretty-printer in the common case. + format!("{}!", path.segments[0].identifier) + } else { + format!("{}!", path) + }; + match extra_ident { + Some(ident) if ident != symbol::keywords::Invalid.ident() => format!("{} {}", name, ident), + _ => name, + } +} + pub fn rewrite_macro( mac: &ast::Mac, extra_ident: Option, @@ -132,16 +146,7 @@ pub fn rewrite_macro( let original_style = macro_style(mac, context); - let macro_name = match extra_ident { - None => format!("{}!", mac.node.path), - Some(ident) => { - if ident == symbol::keywords::Invalid.ident() { - format!("{}!", mac.node.path) - } else { - format!("{}! {}", mac.node.path, ident) - } - } - }; + let macro_name = rewrite_macro_name(&mac.node.path, extra_ident); let style = if FORCED_BRACKET_MACROS.contains(&¯o_name[..]) { MacroStyle::Brackets diff --git a/rustfmt-core/src/types.rs b/rustfmt-core/src/types.rs index f6f80ba312b..971717ac253 100644 --- a/rustfmt-core/src/types.rs +++ b/rustfmt-core/src/types.rs @@ -14,7 +14,6 @@ use std::ops::Deref; use config::lists::*; use syntax::ast::{self, FunctionRetTy, Mutability}; use syntax::codemap::{self, BytePos, Span}; -use syntax::print::pprust; use syntax::symbol::keywords; use codemap::SpanUtils; @@ -539,7 +538,7 @@ impl Rewrite for ast::TyParamBound { impl Rewrite for ast::Lifetime { fn rewrite(&self, _: &RewriteContext, _: Shape) -> Option { - Some(pprust::lifetime_to_string(self)) + Some(self.ident.to_string()) } }