@@ -717,7 +717,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
717
717
}
718
718
TyKind :: ImplicitSelf => {
719
719
let self_ty = keywords:: SelfType . ident ( ) ;
720
- let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , true , ty. span )
720
+ let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , Some ( ty . id ) , ty. span )
721
721
. map_or ( Def :: Err , |d| d. def ( ) ) ;
722
722
self . record_def ( ty. id , PathResolution :: new ( def) ) ;
723
723
}
@@ -1839,9 +1839,10 @@ impl<'a> Resolver<'a> {
1839
1839
fn resolve_ident_in_lexical_scope ( & mut self ,
1840
1840
mut ident : Ident ,
1841
1841
ns : Namespace ,
1842
- record_used : bool ,
1842
+ record_used_id : Option < NodeId > ,
1843
1843
path_span : Span )
1844
1844
-> Option < LexicalScopeBinding < ' a > > {
1845
+ let record_used = record_used_id. is_some ( ) ;
1845
1846
if ns == TypeNS {
1846
1847
ident. span = if ident. name == keywords:: SelfType . name ( ) {
1847
1848
// FIXME(jseyfried) improve `Self` hygiene
@@ -1890,10 +1891,11 @@ impl<'a> Resolver<'a> {
1890
1891
1891
1892
ident. span = ident. span . modern ( ) ;
1892
1893
loop {
1893
- let ( opt_module, poisoned) = if record_used {
1894
- self . hygienic_lexical_parent_with_compatibility_fallback ( module, & mut ident. span )
1894
+ let ( opt_module, poisoned) = if let Some ( node_id) = record_used_id {
1895
+ self . hygienic_lexical_parent_with_compatibility_fallback ( module, & mut ident. span ,
1896
+ node_id)
1895
1897
} else {
1896
- ( self . hygienic_lexical_parent ( module, & mut ident. span ) , false )
1898
+ ( self . hygienic_lexical_parent ( module, & mut ident. span ) , None )
1897
1899
} ;
1898
1900
module = unwrap_or ! ( opt_module, break ) ;
1899
1901
let orig_current_module = self . current_module ;
@@ -1905,18 +1907,18 @@ impl<'a> Resolver<'a> {
1905
1907
1906
1908
match result {
1907
1909
Ok ( binding) => {
1908
- if poisoned {
1910
+ if let Some ( node_id ) = poisoned {
1909
1911
self . session . buffer_lint_with_diagnostic (
1910
1912
lint:: builtin:: PROC_MACRO_DERIVE_RESOLUTION_FALLBACK ,
1911
- CRATE_NODE_ID , ident. span ,
1913
+ node_id , ident. span ,
1912
1914
& format ! ( "cannot find {} `{}` in this scope" , ns. descr( ) , ident) ,
1913
1915
lint:: builtin:: BuiltinLintDiagnostics ::
1914
1916
ProcMacroDeriveResolutionFallback ( ident. span ) ,
1915
1917
) ;
1916
1918
}
1917
1919
return Some ( LexicalScopeBinding :: Item ( binding) )
1918
1920
}
1919
- _ if poisoned => break ,
1921
+ _ if poisoned. is_some ( ) => break ,
1920
1922
Err ( Undetermined ) => return None ,
1921
1923
Err ( Determined ) => { }
1922
1924
}
@@ -1965,10 +1967,11 @@ impl<'a> Resolver<'a> {
1965
1967
}
1966
1968
1967
1969
fn hygienic_lexical_parent_with_compatibility_fallback (
1968
- & mut self , module : Module < ' a > , span : & mut Span ) -> ( Option < Module < ' a > > , /* poisoned */ bool
1969
- ) {
1970
+ & mut self , module : Module < ' a > , span : & mut Span , node_id : NodeId
1971
+ ) -> ( Option < Module < ' a > > , /* poisoned */ Option < NodeId > )
1972
+ {
1970
1973
if let module @ Some ( ..) = self . hygienic_lexical_parent ( module, span) {
1971
- return ( module, false ) ;
1974
+ return ( module, None ) ;
1972
1975
}
1973
1976
1974
1977
// We need to support the next case under a deprecation warning
@@ -1989,13 +1992,13 @@ impl<'a> Resolver<'a> {
1989
1992
// The macro is a proc macro derive
1990
1993
if module. expansion . looks_like_proc_macro_derive ( ) {
1991
1994
if parent. expansion . is_descendant_of ( span. ctxt ( ) . outer ( ) ) {
1992
- return ( module. parent , true ) ;
1995
+ return ( module. parent , Some ( node_id ) ) ;
1993
1996
}
1994
1997
}
1995
1998
}
1996
1999
}
1997
2000
1998
- ( None , false )
2001
+ ( None , None )
1999
2002
}
2000
2003
2001
2004
fn resolve_ident_in_module ( & mut self ,
@@ -2760,7 +2763,7 @@ impl<'a> Resolver<'a> {
2760
2763
// First try to resolve the identifier as some existing
2761
2764
// entity, then fall back to a fresh binding.
2762
2765
let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS ,
2763
- false , pat. span )
2766
+ None , pat. span )
2764
2767
. and_then ( LexicalScopeBinding :: item) ;
2765
2768
let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2766
2769
let is_syntactic_ambiguity = opt_pat. is_none ( ) &&
@@ -3191,13 +3194,13 @@ impl<'a> Resolver<'a> {
3191
3194
3192
3195
fn self_type_is_available ( & mut self , span : Span ) -> bool {
3193
3196
let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) ,
3194
- TypeNS , false , span) ;
3197
+ TypeNS , None , span) ;
3195
3198
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
3196
3199
}
3197
3200
3198
3201
fn self_value_is_available ( & mut self , self_span : Span , path_span : Span ) -> bool {
3199
3202
let ident = Ident :: new ( keywords:: SelfValue . name ( ) , self_span) ;
3200
- let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , false , path_span) ;
3203
+ let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , None , path_span) ;
3201
3204
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
3202
3205
}
3203
3206
@@ -3474,7 +3477,9 @@ impl<'a> Resolver<'a> {
3474
3477
self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span)
3475
3478
. map ( MacroBinding :: binding)
3476
3479
} else {
3477
- match self . resolve_ident_in_lexical_scope ( ident, ns, record_used, path_span) {
3480
+ let record_used_id =
3481
+ if record_used { crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) ) } else { None } ;
3482
+ match self . resolve_ident_in_lexical_scope ( ident, ns, record_used_id, path_span) {
3478
3483
// we found a locally-imported or available item/module
3479
3484
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
3480
3485
// we found a local variable or type param
@@ -4694,4 +4699,15 @@ enum CrateLint {
4694
4699
QPathTrait { qpath_id : NodeId , qpath_span : Span } ,
4695
4700
}
4696
4701
4702
+ impl CrateLint {
4703
+ fn node_id ( & self ) -> Option < NodeId > {
4704
+ match * self {
4705
+ CrateLint :: No => None ,
4706
+ CrateLint :: SimplePath ( id) |
4707
+ CrateLint :: UsePath { root_id : id, .. } |
4708
+ CrateLint :: QPathTrait { qpath_id : id, .. } => Some ( id) ,
4709
+ }
4710
+ }
4711
+ }
4712
+
4697
4713
__build_diagnostic_array ! { librustc_resolve, DIAGNOSTICS }
0 commit comments