@@ -42,7 +42,7 @@ use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
42
42
use rustc:: util:: nodemap:: { NodeMap , NodeSet , FxHashMap , FxHashSet , DefIdMap } ;
43
43
44
44
use syntax:: codemap:: { dummy_spanned, respan} ;
45
- use syntax:: ext:: hygiene:: { Mark , SyntaxContext } ;
45
+ use syntax:: ext:: hygiene:: { Mark , MarkKind , SyntaxContext } ;
46
46
use syntax:: ast:: { self , Name , NodeId , Ident , SpannedIdent , FloatTy , IntTy , UintTy } ;
47
47
use syntax:: ext:: base:: SyntaxExtension ;
48
48
use syntax:: ext:: base:: Determinacy :: { self , Determined , Undetermined } ;
@@ -1775,8 +1775,17 @@ impl<'a> Resolver<'a> {
1775
1775
result
1776
1776
}
1777
1777
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 {
1780
1789
Some ( def) => self . macro_def_scope ( def) ,
1781
1790
None => return self . graph_root ,
1782
1791
} ;
@@ -2961,11 +2970,11 @@ impl<'a> Resolver<'a> {
2961
2970
( i == 1 && name == keywords:: Crate . name ( ) &&
2962
2971
path[ 0 ] . node . name == keywords:: CrateRoot . name ( ) ) {
2963
2972
// `::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 ) ) ;
2965
2974
continue
2966
2975
} else if i == 0 && name == keywords:: DollarCrate . name ( ) {
2967
2976
// `$crate::a::b`
2968
- module = Some ( self . resolve_crate_root ( ident. node . ctxt ) ) ;
2977
+ module = Some ( self . resolve_crate_root ( ident. node . ctxt , true ) ) ;
2969
2978
continue
2970
2979
} else if i == 1 && self . session . features . borrow ( ) . extern_absolute_paths &&
2971
2980
path[ 0 ] . node . name == keywords:: CrateRoot . name ( ) &&
0 commit comments