@@ -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 ,
@@ -2758,7 +2761,7 @@ impl<'a> Resolver<'a> {
2758
2761
// First try to resolve the identifier as some existing
2759
2762
// entity, then fall back to a fresh binding.
2760
2763
let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS ,
2761
- false , pat. span )
2764
+ None , pat. span )
2762
2765
. and_then ( LexicalScopeBinding :: item) ;
2763
2766
let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2764
2767
let is_syntactic_ambiguity = opt_pat. is_none ( ) &&
@@ -3189,13 +3192,13 @@ impl<'a> Resolver<'a> {
3189
3192
3190
3193
fn self_type_is_available ( & mut self , span : Span ) -> bool {
3191
3194
let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) ,
3192
- TypeNS , false , span) ;
3195
+ TypeNS , None , span) ;
3193
3196
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
3194
3197
}
3195
3198
3196
3199
fn self_value_is_available ( & mut self , self_span : Span , path_span : Span ) -> bool {
3197
3200
let ident = Ident :: new ( keywords:: SelfValue . name ( ) , self_span) ;
3198
- let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , false , path_span) ;
3201
+ let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , None , path_span) ;
3199
3202
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
3200
3203
}
3201
3204
@@ -3472,7 +3475,9 @@ impl<'a> Resolver<'a> {
3472
3475
self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span)
3473
3476
. map ( MacroBinding :: binding)
3474
3477
} else {
3475
- match self . resolve_ident_in_lexical_scope ( ident, ns, record_used, path_span) {
3478
+ let record_used_id =
3479
+ if record_used { crate_lint. node_id ( ) . or ( Some ( CRATE_NODE_ID ) ) } else { None } ;
3480
+ match self . resolve_ident_in_lexical_scope ( ident, ns, record_used_id, path_span) {
3476
3481
// we found a locally-imported or available item/module
3477
3482
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
3478
3483
// we found a local variable or type param
@@ -4692,4 +4697,15 @@ enum CrateLint {
4692
4697
QPathTrait { qpath_id : NodeId , qpath_span : Span } ,
4693
4698
}
4694
4699
4700
+ impl CrateLint {
4701
+ fn node_id ( & self ) -> Option < NodeId > {
4702
+ match * self {
4703
+ CrateLint :: No => None ,
4704
+ CrateLint :: SimplePath ( id) |
4705
+ CrateLint :: UsePath { root_id : id, .. } |
4706
+ CrateLint :: QPathTrait { qpath_id : id, .. } => Some ( id) ,
4707
+ }
4708
+ }
4709
+ }
4710
+
4695
4711
__build_diagnostic_array ! { librustc_resolve, DIAGNOSTICS }
0 commit comments