@@ -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 } ;
@@ -763,10 +764,13 @@ impl<'a> NameBinding<'a> {
763
764
}
764
765
765
766
fn is_variant ( & self ) -> bool {
766
- matches ! ( self . kind, NameBindingKind :: Res (
767
+ matches ! (
768
+ self . kind,
769
+ NameBindingKind :: Res (
767
770
Res :: Def ( DefKind :: Variant | DefKind :: Ctor ( CtorOf :: Variant , ..) , _) ,
768
771
_,
769
- ) )
772
+ )
773
+ )
770
774
}
771
775
772
776
fn is_extern_crate ( & self ) -> bool {
@@ -1630,8 +1634,13 @@ impl<'a> Resolver<'a> {
1630
1634
& mut self ,
1631
1635
scope_set : ScopeSet ,
1632
1636
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 > ,
1635
1644
) -> Option < T > {
1636
1645
// General principles:
1637
1646
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -1674,7 +1683,7 @@ impl<'a> Resolver<'a> {
1674
1683
// 4c. Standard library prelude (de-facto closed, controlled).
1675
1684
// 6. Language prelude: builtin attributes (closed, controlled).
1676
1685
1677
- let rust_2015 = ident . span . rust_2015 ( ) ;
1686
+ let rust_2015 = ctxt . edition ( ) == Edition :: Edition2015 ;
1678
1687
let ( ns, macro_kind, is_absolute_path) = match scope_set {
1679
1688
ScopeSet :: All ( ns, _) => ( ns, None , false ) ,
1680
1689
ScopeSet :: AbsolutePath ( ns) => ( ns, None , true ) ,
@@ -1687,7 +1696,7 @@ impl<'a> Resolver<'a> {
1687
1696
TypeNS | ValueNS => Scope :: Module ( module) ,
1688
1697
MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
1689
1698
} ;
1690
- let mut ident = ident . normalize_to_macros_2_0 ( ) ;
1699
+ let mut ctxt = ctxt . normalize_to_macros_2_0 ( ) ;
1691
1700
let mut use_prelude = !module. no_implicit_prelude ;
1692
1701
1693
1702
loop {
@@ -1723,7 +1732,7 @@ impl<'a> Resolver<'a> {
1723
1732
} ;
1724
1733
1725
1734
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 ) {
1727
1736
return break_result;
1728
1737
}
1729
1738
}
@@ -1753,17 +1762,17 @@ impl<'a> Resolver<'a> {
1753
1762
} ,
1754
1763
Scope :: CrateRoot => match ns {
1755
1764
TypeNS => {
1756
- ident . span . adjust ( ExpnId :: root ( ) ) ;
1765
+ ctxt . adjust ( ExpnId :: root ( ) ) ;
1757
1766
Scope :: ExternPrelude
1758
1767
}
1759
1768
ValueNS | MacroNS => break ,
1760
1769
} ,
1761
1770
Scope :: Module ( module) => {
1762
1771
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 ) {
1764
1773
Some ( parent_module) => Scope :: Module ( parent_module) ,
1765
1774
None => {
1766
- ident . span . adjust ( ExpnId :: root ( ) ) ;
1775
+ ctxt . adjust ( ExpnId :: root ( ) ) ;
1767
1776
match ns {
1768
1777
TypeNS => Scope :: ExternPrelude ,
1769
1778
ValueNS => Scope :: StdLibPrelude ,
@@ -1888,16 +1897,18 @@ impl<'a> Resolver<'a> {
1888
1897
ident = normalized_ident;
1889
1898
let mut poisoned = None ;
1890
1899
loop {
1900
+ let mut span_data = ident. span . data ( ) ;
1891
1901
let opt_module = if let Some ( node_id) = record_used_id {
1892
1902
self . hygienic_lexical_parent_with_compatibility_fallback (
1893
1903
module,
1894
- & mut ident . span ,
1904
+ & mut span_data . ctxt ,
1895
1905
node_id,
1896
1906
& mut poisoned,
1897
1907
)
1898
1908
} else {
1899
- self . hygienic_lexical_parent ( module, & mut ident . span )
1909
+ self . hygienic_lexical_parent ( module, & mut span_data . ctxt )
1900
1910
} ;
1911
+ ident. span = span_data. span ( ) ;
1901
1912
module = unwrap_or ! ( opt_module, break ) ;
1902
1913
let adjusted_parent_scope = & ParentScope { module, ..* parent_scope } ;
1903
1914
let result = self . resolve_ident_in_module_unadjusted (
@@ -1971,10 +1982,10 @@ impl<'a> Resolver<'a> {
1971
1982
fn hygienic_lexical_parent (
1972
1983
& mut self ,
1973
1984
module : Module < ' a > ,
1974
- span : & mut Span ,
1985
+ ctxt : & mut SyntaxContext ,
1975
1986
) -> 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 ( ) ) ) ;
1978
1989
}
1979
1990
1980
1991
if let ModuleKind :: Block ( ..) = module. kind {
@@ -1987,11 +1998,11 @@ impl<'a> Resolver<'a> {
1987
1998
fn hygienic_lexical_parent_with_compatibility_fallback (
1988
1999
& mut self ,
1989
2000
module : Module < ' a > ,
1990
- span : & mut Span ,
2001
+ ctxt : & mut SyntaxContext ,
1991
2002
node_id : NodeId ,
1992
2003
poisoned : & mut Option < NodeId > ,
1993
2004
) -> 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 ) {
1995
2006
return module;
1996
2007
}
1997
2008
@@ -2016,7 +2027,7 @@ impl<'a> Resolver<'a> {
2016
2027
let ext = self . get_macro_by_def_id ( def_id) ;
2017
2028
if ext. builtin_name . is_none ( )
2018
2029
&& ext. macro_kind ( ) == MacroKind :: Derive
2019
- && parent. expansion . outer_expn_is_descendant_of ( span . ctxt ( ) )
2030
+ && parent. expansion . outer_expn_is_descendant_of ( * ctxt)
2020
2031
{
2021
2032
* poisoned = Some ( node_id) ;
2022
2033
return module. parent ;
0 commit comments