@@ -42,7 +42,7 @@ use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
4242use rustc:: util:: nodemap:: { NodeMap , NodeSet , FxHashMap , FxHashSet , DefIdMap } ;
4343
4444use syntax:: codemap:: { dummy_spanned, respan} ;
45- use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
45+ use syntax:: ext:: hygiene:: { Mark , MarkKind , SyntaxContext } ;
4646use syntax:: ast:: { self , Name , NodeId , Ident , SpannedIdent , FloatTy , IntTy , UintTy } ;
4747use syntax:: ext:: base:: SyntaxExtension ;
4848use syntax:: ext:: base:: Determinacy :: { self , Determined , Undetermined } ;
@@ -1775,8 +1775,17 @@ impl<'a> Resolver<'a> {
17751775 result
17761776 }
17771777
1778- fn resolve_crate_root ( & mut self , mut ctxt : SyntaxContext ) -> Module < ' a > {
1779- let module = match ctxt. adjust ( Mark :: root ( ) ) {
1778+ fn resolve_crate_root ( & mut self , mut ctxt : SyntaxContext , legacy : bool ) -> Module < ' a > {
1779+ let mark = if legacy {
1780+ // When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
1781+ // we don't want to pretend that the `macro_rules!` definition is in the `macro`
1782+ // as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
1783+ ctxt. marks ( ) . into_iter ( ) . find ( |& mark| mark. kind ( ) != MarkKind :: Modern )
1784+ } else {
1785+ ctxt = ctxt. modern ( ) ;
1786+ ctxt. adjust ( Mark :: root ( ) )
1787+ } ;
1788+ let module = match mark {
17801789 Some ( def) => self . macro_def_scope ( def) ,
17811790 None => return self . graph_root ,
17821791 } ;
@@ -2961,11 +2970,11 @@ impl<'a> Resolver<'a> {
29612970 ( i == 1 && name == keywords:: Crate . name ( ) &&
29622971 path[ 0 ] . node . name == keywords:: CrateRoot . name ( ) ) {
29632972 // `::a::b` or `::crate::a::b`
2964- module = Some ( self . resolve_crate_root ( ident. node . ctxt . modern ( ) ) ) ;
2973+ module = Some ( self . resolve_crate_root ( ident. node . ctxt , false ) ) ;
29652974 continue
29662975 } else if i == 0 && name == keywords:: DollarCrate . name ( ) {
29672976 // `$crate::a::b`
2968- module = Some ( self . resolve_crate_root ( ident. node . ctxt ) ) ;
2977+ module = Some ( self . resolve_crate_root ( ident. node . ctxt , true ) ) ;
29692978 continue
29702979 } else if i == 1 && self . session . features . borrow ( ) . extern_absolute_paths &&
29712980 path[ 0 ] . node . name == keywords:: CrateRoot . name ( ) &&
0 commit comments