@@ -50,6 +50,7 @@ use rustc_middle::{bug, span_bug};
5050use rustc_session:: lint;
5151use rustc_session:: lint:: { BuiltinLintDiagnostics , LintBuffer } ;
5252use rustc_session:: Session ;
53+ use rustc_span:: edition:: Edition ;
5354use rustc_span:: hygiene:: { ExpnId , ExpnKind , MacroKind , SyntaxContext , Transparency } ;
5455use rustc_span:: source_map:: Spanned ;
5556use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -763,10 +764,13 @@ impl<'a> NameBinding<'a> {
763764 }
764765
765766 fn is_variant ( & self ) -> bool {
766- matches ! ( self . kind, NameBindingKind :: Res (
767+ matches ! (
768+ self . kind,
769+ NameBindingKind :: Res (
767770 Res :: Def ( DefKind :: Variant | DefKind :: Ctor ( CtorOf :: Variant , ..) , _) ,
768771 _,
769- ) )
772+ )
773+ )
770774 }
771775
772776 fn is_extern_crate ( & self ) -> bool {
@@ -1630,8 +1634,13 @@ impl<'a> Resolver<'a> {
16301634 & mut self ,
16311635 scope_set : ScopeSet ,
16321636 parent_scope : & ParentScope < ' a > ,
1633- ident : Ident ,
1634- mut visitor : impl FnMut ( & mut Self , Scope < ' a > , /*use_prelude*/ bool , Ident ) -> Option < T > ,
1637+ ctxt : SyntaxContext ,
1638+ mut visitor : impl FnMut (
1639+ & mut Self ,
1640+ Scope < ' a > ,
1641+ /*use_prelude*/ bool ,
1642+ SyntaxContext ,
1643+ ) -> Option < T > ,
16351644 ) -> Option < T > {
16361645 // General principles:
16371646 // 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -1674,7 +1683,7 @@ impl<'a> Resolver<'a> {
16741683 // 4c. Standard library prelude (de-facto closed, controlled).
16751684 // 6. Language prelude: builtin attributes (closed, controlled).
16761685
1677- let rust_2015 = ident . span . rust_2015 ( ) ;
1686+ let rust_2015 = ctxt . edition ( ) == Edition :: Edition2015 ;
16781687 let ( ns, macro_kind, is_absolute_path) = match scope_set {
16791688 ScopeSet :: All ( ns, _) => ( ns, None , false ) ,
16801689 ScopeSet :: AbsolutePath ( ns) => ( ns, None , true ) ,
@@ -1687,7 +1696,7 @@ impl<'a> Resolver<'a> {
16871696 TypeNS | ValueNS => Scope :: Module ( module) ,
16881697 MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
16891698 } ;
1690- let mut ident = ident . normalize_to_macros_2_0 ( ) ;
1699+ let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
16911700 let mut use_prelude = !module. no_implicit_prelude ;
16921701
16931702 loop {
@@ -1723,7 +1732,7 @@ impl<'a> Resolver<'a> {
17231732 } ;
17241733
17251734 if visit {
1726- if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude, ident ) {
1735+ if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude, ctxt ) {
17271736 return break_result;
17281737 }
17291738 }
@@ -1753,17 +1762,17 @@ impl<'a> Resolver<'a> {
17531762 } ,
17541763 Scope :: CrateRoot => match ns {
17551764 TypeNS => {
1756- ident . span . adjust ( ExpnId :: root ( ) ) ;
1765+ ctxt . adjust ( ExpnId :: root ( ) ) ;
17571766 Scope :: ExternPrelude
17581767 }
17591768 ValueNS | MacroNS => break ,
17601769 } ,
17611770 Scope :: Module ( module) => {
17621771 use_prelude = !module. no_implicit_prelude ;
1763- match self . hygienic_lexical_parent ( module, & mut ident . span ) {
1772+ match self . hygienic_lexical_parent ( module, & mut ctxt ) {
17641773 Some ( parent_module) => Scope :: Module ( parent_module) ,
17651774 None => {
1766- ident . span . adjust ( ExpnId :: root ( ) ) ;
1775+ ctxt . adjust ( ExpnId :: root ( ) ) ;
17671776 match ns {
17681777 TypeNS => Scope :: ExternPrelude ,
17691778 ValueNS => Scope :: StdLibPrelude ,
@@ -1888,16 +1897,18 @@ impl<'a> Resolver<'a> {
18881897 ident = normalized_ident;
18891898 let mut poisoned = None ;
18901899 loop {
1900+ let mut span_data = ident. span . data ( ) ;
18911901 let opt_module = if let Some ( node_id) = record_used_id {
18921902 self . hygienic_lexical_parent_with_compatibility_fallback (
18931903 module,
1894- & mut ident . span ,
1904+ & mut span_data . ctxt ,
18951905 node_id,
18961906 & mut poisoned,
18971907 )
18981908 } else {
1899- self . hygienic_lexical_parent ( module, & mut ident . span )
1909+ self . hygienic_lexical_parent ( module, & mut span_data . ctxt )
19001910 } ;
1911+ ident. span = span_data. span ( ) ;
19011912 module = unwrap_or ! ( opt_module, break ) ;
19021913 let adjusted_parent_scope = & ParentScope { module, ..* parent_scope } ;
19031914 let result = self . resolve_ident_in_module_unadjusted (
@@ -1971,10 +1982,10 @@ impl<'a> Resolver<'a> {
19711982 fn hygienic_lexical_parent (
19721983 & mut self ,
19731984 module : Module < ' a > ,
1974- span : & mut Span ,
1985+ ctxt : & mut SyntaxContext ,
19751986 ) -> Option < Module < ' a > > {
1976- if !module. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) ) {
1977- return Some ( self . macro_def_scope ( span . remove_mark ( ) ) ) ;
1987+ if !module. expansion . outer_expn_is_descendant_of ( * ctxt) {
1988+ return Some ( self . macro_def_scope ( ctxt . remove_mark ( ) ) ) ;
19781989 }
19791990
19801991 if let ModuleKind :: Block ( ..) = module. kind {
@@ -1987,11 +1998,11 @@ impl<'a> Resolver<'a> {
19871998 fn hygienic_lexical_parent_with_compatibility_fallback (
19881999 & mut self ,
19892000 module : Module < ' a > ,
1990- span : & mut Span ,
2001+ ctxt : & mut SyntaxContext ,
19912002 node_id : NodeId ,
19922003 poisoned : & mut Option < NodeId > ,
19932004 ) -> Option < Module < ' a > > {
1994- if let module @ Some ( ..) = self . hygienic_lexical_parent ( module, span ) {
2005+ if let module @ Some ( ..) = self . hygienic_lexical_parent ( module, ctxt ) {
19952006 return module;
19962007 }
19972008
@@ -2016,7 +2027,7 @@ impl<'a> Resolver<'a> {
20162027 let ext = self . get_macro_by_def_id ( def_id) ;
20172028 if ext. builtin_name . is_none ( )
20182029 && ext. macro_kind ( ) == MacroKind :: Derive
2019- && parent. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) )
2030+ && parent. expansion . outer_expn_is_descendant_of ( * ctxt)
20202031 {
20212032 * poisoned = Some ( node_id) ;
20222033 return module. parent ;
0 commit comments