@@ -50,6 +50,7 @@ use rustc_middle::{bug, span_bug};
50
50
use rustc_session:: lint;
51
51
use rustc_session:: lint:: { BuiltinLintDiagnostics , LintBuffer } ;
52
52
use rustc_session:: Session ;
53
+ use rustc_span:: edition:: Edition ;
53
54
use rustc_span:: hygiene:: { ExpnId , ExpnKind , MacroKind , SyntaxContext , Transparency } ;
54
55
use rustc_span:: source_map:: Spanned ;
55
56
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
@@ -759,10 +760,13 @@ impl<'a> NameBinding<'a> {
759
760
}
760
761
761
762
fn is_variant ( & self ) -> bool {
762
- matches ! ( self . kind, NameBindingKind :: Res (
763
+ matches ! (
764
+ self . kind,
765
+ NameBindingKind :: Res (
763
766
Res :: Def ( DefKind :: Variant | DefKind :: Ctor ( CtorOf :: Variant , ..) , _) ,
764
767
_,
765
- ) )
768
+ )
769
+ )
766
770
}
767
771
768
772
fn is_extern_crate ( & self ) -> bool {
@@ -1626,8 +1630,13 @@ impl<'a> Resolver<'a> {
1626
1630
& mut self ,
1627
1631
scope_set : ScopeSet ,
1628
1632
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 > ,
1631
1640
) -> Option < T > {
1632
1641
// General principles:
1633
1642
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -1670,7 +1679,7 @@ impl<'a> Resolver<'a> {
1670
1679
// 4c. Standard library prelude (de-facto closed, controlled).
1671
1680
// 6. Language prelude: builtin attributes (closed, controlled).
1672
1681
1673
- let rust_2015 = ident . span . rust_2015 ( ) ;
1682
+ let rust_2015 = ctxt . edition ( ) == Edition :: Edition2015 ;
1674
1683
let ( ns, macro_kind, is_absolute_path) = match scope_set {
1675
1684
ScopeSet :: All ( ns, _) => ( ns, None , false ) ,
1676
1685
ScopeSet :: AbsolutePath ( ns) => ( ns, None , true ) ,
@@ -1683,7 +1692,7 @@ impl<'a> Resolver<'a> {
1683
1692
TypeNS | ValueNS => Scope :: Module ( module) ,
1684
1693
MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
1685
1694
} ;
1686
- let mut ident = ident . normalize_to_macros_2_0 ( ) ;
1695
+ let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
1687
1696
let mut use_prelude = !module. no_implicit_prelude ;
1688
1697
1689
1698
loop {
@@ -1719,7 +1728,7 @@ impl<'a> Resolver<'a> {
1719
1728
} ;
1720
1729
1721
1730
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 ) {
1723
1732
return break_result;
1724
1733
}
1725
1734
}
@@ -1749,17 +1758,17 @@ impl<'a> Resolver<'a> {
1749
1758
} ,
1750
1759
Scope :: CrateRoot => match ns {
1751
1760
TypeNS => {
1752
- ident . span . adjust ( ExpnId :: root ( ) ) ;
1761
+ ctxt . adjust ( ExpnId :: root ( ) ) ;
1753
1762
Scope :: ExternPrelude
1754
1763
}
1755
1764
ValueNS | MacroNS => break ,
1756
1765
} ,
1757
1766
Scope :: Module ( module) => {
1758
1767
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 ) {
1760
1769
Some ( parent_module) => Scope :: Module ( parent_module) ,
1761
1770
None => {
1762
- ident . span . adjust ( ExpnId :: root ( ) ) ;
1771
+ ctxt . adjust ( ExpnId :: root ( ) ) ;
1763
1772
match ns {
1764
1773
TypeNS => Scope :: ExternPrelude ,
1765
1774
ValueNS => Scope :: StdLibPrelude ,
@@ -1882,16 +1891,18 @@ impl<'a> Resolver<'a> {
1882
1891
ident = normalized_ident;
1883
1892
let mut poisoned = None ;
1884
1893
loop {
1894
+ let mut span_data = ident. span . data ( ) ;
1885
1895
let opt_module = if let Some ( node_id) = record_used_id {
1886
1896
self . hygienic_lexical_parent_with_compatibility_fallback (
1887
1897
module,
1888
- & mut ident . span ,
1898
+ & mut span_data . ctxt ,
1889
1899
node_id,
1890
1900
& mut poisoned,
1891
1901
)
1892
1902
} else {
1893
- self . hygienic_lexical_parent ( module, & mut ident . span )
1903
+ self . hygienic_lexical_parent ( module, & mut span_data . ctxt )
1894
1904
} ;
1905
+ ident. span = span_data. span ( ) ;
1895
1906
module = unwrap_or ! ( opt_module, break ) ;
1896
1907
let adjusted_parent_scope = & ParentScope { module, ..* parent_scope } ;
1897
1908
let result = self . resolve_ident_in_module_unadjusted (
@@ -1965,10 +1976,10 @@ impl<'a> Resolver<'a> {
1965
1976
fn hygienic_lexical_parent (
1966
1977
& mut self ,
1967
1978
module : Module < ' a > ,
1968
- span : & mut Span ,
1979
+ ctxt : & mut SyntaxContext ,
1969
1980
) -> 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 ( ) ) ) ;
1972
1983
}
1973
1984
1974
1985
if let ModuleKind :: Block ( ..) = module. kind {
@@ -1981,11 +1992,11 @@ impl<'a> Resolver<'a> {
1981
1992
fn hygienic_lexical_parent_with_compatibility_fallback (
1982
1993
& mut self ,
1983
1994
module : Module < ' a > ,
1984
- span : & mut Span ,
1995
+ ctxt : & mut SyntaxContext ,
1985
1996
node_id : NodeId ,
1986
1997
poisoned : & mut Option < NodeId > ,
1987
1998
) -> 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 ) {
1989
2000
return module;
1990
2001
}
1991
2002
@@ -2010,7 +2021,7 @@ impl<'a> Resolver<'a> {
2010
2021
let ext = self . get_macro_by_def_id ( def_id) ;
2011
2022
if !ext. is_builtin
2012
2023
&& ext. macro_kind ( ) == MacroKind :: Derive
2013
- && parent. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) )
2024
+ && parent. expansion . outer_expn_is_descendant_of ( * ctxt)
2014
2025
{
2015
2026
* poisoned = Some ( node_id) ;
2016
2027
return module. parent ;
0 commit comments