about summary refs log tree commit diff
path: root/src/libsyntax/ext/base.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-28 02:54:14 +0000
committerbors <bors@rust-lang.org>2018-12-28 02:54:14 +0000
commite8ca35e63dda82a8b5fa8eb72cf3e490a5794a46 (patch)
tree190e1b7ce725d1fdfaf44e49c34a9465d558ac0a /src/libsyntax/ext/base.rs
parentf8caa321c7c7214a6c5415e4b3694e65b4ff73a7 (diff)
parente40d7d9643b810b2bc62f279e1d6f4ad68a35bc2 (diff)
downloadrust-e8ca35e63dda82a8b5fa8eb72cf3e490a5794a46.tar.gz
rust-e8ca35e63dda82a8b5fa8eb72cf3e490a5794a46.zip
Auto merge of #57155 - petrochenkov:dcrate3, r=dtolnay
Resolve `$crate`s for pretty-printing at more appropriate time

Doing it in `BuildReducedGraphVisitor` wasn't a good idea, identifiers wasn't actually visited half of the time.
As a result some `$crate`s weren't resolved and were therefore pretty-printed as `$crate` literally, which turns into two tokens during re-parsing of the pretty-printed text.

Now we are visiting and resolving `$crate` identifiers in an item right before sending that item to a proc macro attribute or derive.

Fixes https://github.com/rust-lang/rust/issues/57089
Diffstat (limited to 'src/libsyntax/ext/base.rs')
-rw-r--r--src/libsyntax/ext/base.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 1efe0b3478d..7e8b7007b22 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -14,6 +14,7 @@ use parse::token;
 use ptr::P;
 use smallvec::SmallVec;
 use symbol::{keywords, Ident, Symbol};
+use visit::Visitor;
 use ThinVec;
 
 use rustc_data_structures::fx::FxHashMap;
@@ -135,6 +136,17 @@ impl Annotatable {
             _ => false,
         }
     }
+
+    pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
+        match self {
+            Annotatable::Item(item) => visitor.visit_item(item),
+            Annotatable::TraitItem(trait_item) => visitor.visit_trait_item(trait_item),
+            Annotatable::ImplItem(impl_item) => visitor.visit_impl_item(impl_item),
+            Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
+            Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
+            Annotatable::Expr(expr) => visitor.visit_expr(expr),
+        }
+    }
 }
 
 // A more flexible ItemDecorator.
@@ -730,6 +742,7 @@ pub trait Resolver {
     fn next_node_id(&mut self) -> ast::NodeId;
     fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
 
+    fn resolve_dollar_crates(&mut self, annotatable: &Annotatable);
     fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
                                             derives: &[Mark]);
     fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc<SyntaxExtension>);
@@ -763,6 +776,7 @@ impl Resolver for DummyResolver {
     fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }
     fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
 
+    fn resolve_dollar_crates(&mut self, _annotatable: &Annotatable) {}
     fn visit_ast_fragment_with_placeholders(&mut self, _invoc: Mark, _fragment: &AstFragment,
                                             _derives: &[Mark]) {}
     fn add_builtin(&mut self, _ident: ast::Ident, _ext: Lrc<SyntaxExtension>) {}