@@ -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 } ;
@@ -759,10 +760,13 @@ impl<'a> NameBinding<'a> {
759760 }
760761
761762 fn is_variant ( & self ) -> bool {
762- matches ! ( self . kind, NameBindingKind :: Res (
763+ matches ! (
764+ self . kind,
765+ NameBindingKind :: Res (
763766 Res :: Def ( DefKind :: Variant | DefKind :: Ctor ( CtorOf :: Variant , ..) , _) ,
764767 _,
765- ) )
768+ )
769+ )
766770 }
767771
768772 fn is_extern_crate ( & self ) -> bool {
@@ -1626,8 +1630,13 @@ impl<'a> Resolver<'a> {
16261630 & mut self ,
16271631 scope_set : ScopeSet ,
16281632 parent_scope : & ParentScope < ' a > ,
1629- ident : Ident ,
1630- mut visitor : impl FnMut ( & mut Self , Scope < ' a > , /*use_prelude*/ bool , Ident ) -> Option < T > ,
1633+ ctxt : SyntaxContext ,
1634+ mut visitor : impl FnMut (
1635+ & mut Self ,
1636+ Scope < ' a > ,
1637+ /*use_prelude*/ bool ,
1638+ SyntaxContext ,
1639+ ) -> Option < T > ,
16311640 ) -> Option < T > {
16321641 // General principles:
16331642 // 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -1670,7 +1679,7 @@ impl<'a> Resolver<'a> {
16701679 // 4c. Standard library prelude (de-facto closed, controlled).
16711680 // 6. Language prelude: builtin attributes (closed, controlled).
16721681
1673- let rust_2015 = ident . span . rust_2015 ( ) ;
1682+ let rust_2015 = ctxt . edition ( ) == Edition :: Edition2015 ;
16741683 let ( ns, macro_kind, is_absolute_path) = match scope_set {
16751684 ScopeSet :: All ( ns, _) => ( ns, None , false ) ,
16761685 ScopeSet :: AbsolutePath ( ns) => ( ns, None , true ) ,
@@ -1683,7 +1692,7 @@ impl<'a> Resolver<'a> {
16831692 TypeNS | ValueNS => Scope :: Module ( module) ,
16841693 MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
16851694 } ;
1686- let mut ident = ident . normalize_to_macros_2_0 ( ) ;
1695+ let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
16871696 let mut use_prelude = !module. no_implicit_prelude ;
16881697
16891698 loop {
@@ -1719,7 +1728,7 @@ impl<'a> Resolver<'a> {
17191728 } ;
17201729
17211730 if visit {
1722- if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude, ident ) {
1731+ if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude, ctxt ) {
17231732 return break_result;
17241733 }
17251734 }
@@ -1749,17 +1758,17 @@ impl<'a> Resolver<'a> {
17491758 } ,
17501759 Scope :: CrateRoot => match ns {
17511760 TypeNS => {
1752- ident . span . adjust ( ExpnId :: root ( ) ) ;
1761+ ctxt . adjust ( ExpnId :: root ( ) ) ;
17531762 Scope :: ExternPrelude
17541763 }
17551764 ValueNS | MacroNS => break ,
17561765 } ,
17571766 Scope :: Module ( module) => {
17581767 use_prelude = !module. no_implicit_prelude ;
1759- match self . hygienic_lexical_parent ( module, & mut ident . span ) {
1768+ match self . hygienic_lexical_parent ( module, & mut ctxt ) {
17601769 Some ( parent_module) => Scope :: Module ( parent_module) ,
17611770 None => {
1762- ident . span . adjust ( ExpnId :: root ( ) ) ;
1771+ ctxt . adjust ( ExpnId :: root ( ) ) ;
17631772 match ns {
17641773 TypeNS => Scope :: ExternPrelude ,
17651774 ValueNS => Scope :: StdLibPrelude ,
@@ -1882,16 +1891,18 @@ impl<'a> Resolver<'a> {
18821891 ident = normalized_ident;
18831892 let mut poisoned = None ;
18841893 loop {
1894+ let mut span_data = ident. span . data ( ) ;
18851895 let opt_module = if let Some ( node_id) = record_used_id {
18861896 self . hygienic_lexical_parent_with_compatibility_fallback (
18871897 module,
1888- & mut ident . span ,
1898+ & mut span_data . ctxt ,
18891899 node_id,
18901900 & mut poisoned,
18911901 )
18921902 } else {
1893- self . hygienic_lexical_parent ( module, & mut ident . span )
1903+ self . hygienic_lexical_parent ( module, & mut span_data . ctxt )
18941904 } ;
1905+ ident. span = span_data. span ( ) ;
18951906 module = unwrap_or ! ( opt_module, break ) ;
18961907 let adjusted_parent_scope = & ParentScope { module, ..* parent_scope } ;
18971908 let result = self . resolve_ident_in_module_unadjusted (
@@ -1965,10 +1976,10 @@ impl<'a> Resolver<'a> {
19651976 fn hygienic_lexical_parent (
19661977 & mut self ,
19671978 module : Module < ' a > ,
1968- span : & mut Span ,
1979+ ctxt : & mut SyntaxContext ,
19691980 ) -> Option < Module < ' a > > {
1970- if !module. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) ) {
1971- return Some ( self . macro_def_scope ( span . remove_mark ( ) ) ) ;
1981+ if !module. expansion . outer_expn_is_descendant_of ( * ctxt) {
1982+ return Some ( self . macro_def_scope ( ctxt . remove_mark ( ) ) ) ;
19721983 }
19731984
19741985 if let ModuleKind :: Block ( ..) = module. kind {
@@ -1981,11 +1992,11 @@ impl<'a> Resolver<'a> {
19811992 fn hygienic_lexical_parent_with_compatibility_fallback (
19821993 & mut self ,
19831994 module : Module < ' a > ,
1984- span : & mut Span ,
1995+ ctxt : & mut SyntaxContext ,
19851996 node_id : NodeId ,
19861997 poisoned : & mut Option < NodeId > ,
19871998 ) -> Option < Module < ' a > > {
1988- if let module @ Some ( ..) = self . hygienic_lexical_parent ( module, span ) {
1999+ if let module @ Some ( ..) = self . hygienic_lexical_parent ( module, ctxt ) {
19892000 return module;
19902001 }
19912002
@@ -2010,7 +2021,7 @@ impl<'a> Resolver<'a> {
20102021 let ext = self . get_macro_by_def_id ( def_id) ;
20112022 if !ext. is_builtin
20122023 && ext. macro_kind ( ) == MacroKind :: Derive
2013- && parent. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) )
2024+ && parent. expansion . outer_expn_is_descendant_of ( * ctxt)
20142025 {
20152026 * poisoned = Some ( node_id) ;
20162027 return module. parent ;
0 commit comments