diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs
index 2b223d92ff198..802d5cfbfc442 100644
--- a/src/librustc_ast_pretty/pprust.rs
+++ b/src/librustc_ast_pretty/pprust.rs
@@ -319,10 +319,7 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
token::NtLifetime(e) => e.to_string(),
token::NtLiteral(ref e) => expr_to_string(e),
token::NtTT(ref tree) => tt_to_string(tree.clone()),
- // FIXME(Centril): merge these variants.
- token::NtImplItem(ref e) | token::NtTraitItem(ref e) => assoc_item_to_string(e),
token::NtVis(ref e) => vis_to_string(e),
- token::NtForeignItem(ref e) => foreign_item_to_string(e),
}
}
@@ -358,10 +355,6 @@ pub fn item_to_string(i: &ast::Item) -> String {
to_string(|s| s.print_item(i))
}
-fn assoc_item_to_string(i: &ast::AssocItem) -> String {
- to_string(|s| s.print_assoc_item(i))
-}
-
pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String {
to_string(|s| s.print_generic_params(generic_params))
}
@@ -404,10 +397,6 @@ pub fn param_to_string(arg: &ast::Param) -> String {
to_string(|s| s.print_param(arg, false))
}
-fn foreign_item_to_string(arg: &ast::ForeignItem) -> String {
- to_string(|s| s.print_foreign_item(arg))
-}
-
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
format!("{}{}", to_string(|s| s.print_visibility(vis)), s)
}
diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs
index bbea066b048d2..8ed7bbf6e1276 100644
--- a/src/librustc_expand/expand.rs
+++ b/src/librustc_expand/expand.rs
@@ -669,12 +669,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
SyntaxExtensionKind::Attr(expander) => {
self.gate_proc_macro_input(&item);
self.gate_proc_macro_attr_item(span, &item);
+ // `Annotatable` can be converted into tokens directly, but we are packing it
+ // into a nonterminal as a piece of AST to make the produced token stream
+ // look nicer in pretty-printed form. This may be no longer necessary.
let item_tok = TokenTree::token(
token::Interpolated(Lrc::new(match item {
Annotatable::Item(item) => token::NtItem(item),
- Annotatable::TraitItem(item) => token::NtTraitItem(item),
- Annotatable::ImplItem(item) => token::NtImplItem(item),
- Annotatable::ForeignItem(item) => token::NtForeignItem(item),
+ Annotatable::TraitItem(item)
+ | Annotatable::ImplItem(item)
+ | Annotatable::ForeignItem(item) => {
+ token::NtItem(P(item.and_then(ast::AssocItem::into_item)))
+ }
Annotatable::Stmt(stmt) => token::NtStmt(stmt.into_inner()),
Annotatable::Expr(expr) => token::NtExpr(expr),
Annotatable::Arm(..)
diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs
index a0b8415b3e17e..bd0b189d4fd4d 100644
--- a/src/librustc_parse/lib.rs
+++ b/src/librustc_parse/lib.rs
@@ -314,9 +314,6 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
Nonterminal::NtItem(ref item) => {
prepend_attrs(sess, &item.attrs, item.tokens.as_ref(), span)
}
- Nonterminal::NtTraitItem(ref item) | Nonterminal::NtImplItem(ref item) => {
- prepend_attrs(sess, &item.attrs, item.tokens.as_ref(), span)
- }
Nonterminal::NtIdent(ident, is_raw) => {
Some(tokenstream::TokenTree::token(token::Ident(ident.name, is_raw), ident.span).into())
}
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs
index d6da627054196..d9e28716c84c7 100644
--- a/src/librustc_parse/parser/item.rs
+++ b/src/librustc_parse/parser/item.rs
@@ -632,16 +632,10 @@ impl<'a> Parser<'a> {
}
pub fn parse_impl_item(&mut self) -> PResult<'a, Option