@@ -613,7 +613,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
613
613
self . smart_resolve_path ( ty. id , qself. as_ref ( ) , path, PathSource :: Type ) ;
614
614
} else if let TyKind :: ImplicitSelf = ty. node {
615
615
let self_ty = keywords:: SelfType . ident ( ) ;
616
- let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , Some ( ty. span ) )
616
+ let def = self . resolve_ident_in_lexical_scope ( self_ty, TypeNS , true , ty. span )
617
617
. map_or ( Def :: Err , |d| d. def ( ) ) ;
618
618
self . record_def ( ty. id , PathResolution :: new ( def) ) ;
619
619
} else if let TyKind :: Array ( ref element, ref length) = ty. node {
@@ -1267,11 +1267,11 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1267
1267
let namespace = if is_value { ValueNS } else { TypeNS } ;
1268
1268
let hir:: Path { ref segments, span, ref mut def } = * path;
1269
1269
let path: Vec < _ > = segments. iter ( ) . map ( |seg| Ident :: with_empty_ctxt ( seg. name ) ) . collect ( ) ;
1270
- match self . resolve_path ( & path, Some ( namespace) , Some ( span) ) {
1270
+ match self . resolve_path ( & path, Some ( namespace) , true , span) {
1271
1271
PathResult :: Module ( module) => * def = module. def ( ) . unwrap ( ) ,
1272
1272
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1273
1273
* def = path_res. base_def ( ) ,
1274
- PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , Some ( span) ) {
1274
+ PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , true , span) {
1275
1275
PathResult :: Failed ( msg, _) => {
1276
1276
resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
1277
1277
}
@@ -1502,7 +1502,8 @@ impl<'a> Resolver<'a> {
1502
1502
fn resolve_ident_in_lexical_scope ( & mut self ,
1503
1503
mut ident : Ident ,
1504
1504
ns : Namespace ,
1505
- record_used : Option < Span > )
1505
+ record_used : bool ,
1506
+ path_span : Span )
1506
1507
-> Option < LexicalScopeBinding < ' a > > {
1507
1508
if ns == TypeNS {
1508
1509
ident = ident. unhygienize ( ) ;
@@ -1513,12 +1514,13 @@ impl<'a> Resolver<'a> {
1513
1514
if let Some ( def) = self . ribs [ ns] [ i] . bindings . get ( & ident) . cloned ( ) {
1514
1515
// The ident resolves to a type parameter or local variable.
1515
1516
return Some ( LexicalScopeBinding :: Def (
1516
- self . adjust_local_def ( ns, i, def, record_used)
1517
+ self . adjust_local_def ( ns, i, def, record_used, path_span )
1517
1518
) ) ;
1518
1519
}
1519
1520
1520
1521
if let ModuleRibKind ( module) = self . ribs [ ns] [ i] . kind {
1521
- let item = self . resolve_ident_in_module ( module, ident, ns, false , record_used) ;
1522
+ let item = self . resolve_ident_in_module ( module, ident, ns, false ,
1523
+ record_used, path_span) ;
1522
1524
if let Ok ( binding) = item {
1523
1525
// The ident resolves to an item.
1524
1526
return Some ( LexicalScopeBinding :: Item ( binding) ) ;
@@ -1527,7 +1529,8 @@ impl<'a> Resolver<'a> {
1527
1529
if let ModuleKind :: Block ( ..) = module. kind { // We can see through blocks
1528
1530
} else if !module. no_implicit_prelude {
1529
1531
return self . prelude . and_then ( |prelude| {
1530
- self . resolve_ident_in_module ( prelude, ident, ns, false , None ) . ok ( )
1532
+ self . resolve_ident_in_module ( prelude, ident, ns, false ,
1533
+ false , path_span) . ok ( )
1531
1534
} ) . map ( LexicalScopeBinding :: Item )
1532
1535
} else {
1533
1536
return None ;
@@ -2147,7 +2150,8 @@ impl<'a> Resolver<'a> {
2147
2150
PatKind :: Ident ( bmode, ref ident, ref opt_pat) => {
2148
2151
// First try to resolve the identifier as some existing
2149
2152
// entity, then fall back to a fresh binding.
2150
- let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS , None )
2153
+ let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS ,
2154
+ false , pat. span )
2151
2155
. and_then ( LexicalScopeBinding :: item) ;
2152
2156
let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2153
2157
let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
@@ -2253,7 +2257,7 @@ impl<'a> Resolver<'a> {
2253
2257
( format ! ( "" ) , format ! ( "the crate root" ) )
2254
2258
} else {
2255
2259
let mod_path = & path[ ..path. len ( ) - 1 ] ;
2256
- let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2260
+ let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) , false , span ) {
2257
2261
PathResult :: Module ( module) => module. def ( ) ,
2258
2262
_ => None ,
2259
2263
} . map_or ( format ! ( "" ) , |def| format ! ( "{} " , def. kind_name( ) ) ) ;
@@ -2303,9 +2307,9 @@ impl<'a> Resolver<'a> {
2303
2307
}
2304
2308
}
2305
2309
}
2306
- if path. len ( ) == 1 && this. self_type_is_available ( ) {
2310
+ if path. len ( ) == 1 && this. self_type_is_available ( span ) {
2307
2311
if let Some ( candidate) = this. lookup_assoc_candidate ( name, ns, is_expected) {
2308
- let self_is_available = this. self_value_is_available ( path[ 0 ] . ctxt ) ;
2312
+ let self_is_available = this. self_value_is_available ( path[ 0 ] . ctxt , span ) ;
2309
2313
match candidate {
2310
2314
AssocSuggestion :: Field => {
2311
2315
err. span_label ( span, format ! ( "did you mean `self.{}`?" , path_str) ) ;
@@ -2329,7 +2333,7 @@ impl<'a> Resolver<'a> {
2329
2333
let mut levenshtein_worked = false ;
2330
2334
2331
2335
// Try Levenshtein.
2332
- if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected) {
2336
+ if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected, span ) {
2333
2337
err. span_label ( ident_span, format ! ( "did you mean `{}`?" , candidate) ) ;
2334
2338
levenshtein_worked = true ;
2335
2339
}
@@ -2434,14 +2438,15 @@ impl<'a> Resolver<'a> {
2434
2438
resolution
2435
2439
}
2436
2440
2437
- fn self_type_is_available ( & mut self ) -> bool {
2438
- let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) , TypeNS , None ) ;
2441
+ fn self_type_is_available ( & mut self , span : Span ) -> bool {
2442
+ let binding = self . resolve_ident_in_lexical_scope ( keywords:: SelfType . ident ( ) ,
2443
+ TypeNS , false , span) ;
2439
2444
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
2440
2445
}
2441
2446
2442
- fn self_value_is_available ( & mut self , ctxt : SyntaxContext ) -> bool {
2447
+ fn self_value_is_available ( & mut self , ctxt : SyntaxContext , span : Span ) -> bool {
2443
2448
let ident = Ident { name : keywords:: SelfValue . name ( ) , ctxt : ctxt } ;
2444
- let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , None ) ;
2449
+ let binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , false , span ) ;
2445
2450
if let Some ( LexicalScopeBinding :: Def ( def) ) = binding { def != Def :: Err } else { false }
2446
2451
}
2447
2452
@@ -2505,7 +2510,7 @@ impl<'a> Resolver<'a> {
2505
2510
) ) ;
2506
2511
}
2507
2512
2508
- let result = match self . resolve_path ( & path, Some ( ns) , Some ( span) ) {
2513
+ let result = match self . resolve_path ( & path, Some ( ns) , true , span) {
2509
2514
PathResult :: NonModule ( path_res) => path_res,
2510
2515
PathResult :: Module ( module) if !module. is_normal ( ) => {
2511
2516
PathResolution :: new ( module. def ( ) . unwrap ( ) )
@@ -2551,7 +2556,7 @@ impl<'a> Resolver<'a> {
2551
2556
if path. len ( ) > 1 && !global_by_default && result. base_def ( ) != Def :: Err &&
2552
2557
path[ 0 ] . name != keywords:: CrateRoot . name ( ) && path[ 0 ] . name != "$crate" {
2553
2558
let unqualified_result = {
2554
- match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , None ) {
2559
+ match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , false , span ) {
2555
2560
PathResult :: NonModule ( path_res) => path_res. base_def ( ) ,
2556
2561
PathResult :: Module ( module) => module. def ( ) . unwrap ( ) ,
2557
2562
_ => return Some ( result) ,
@@ -2569,7 +2574,8 @@ impl<'a> Resolver<'a> {
2569
2574
fn resolve_path ( & mut self ,
2570
2575
path : & [ Ident ] ,
2571
2576
opt_ns : Option < Namespace > , // `None` indicates a module path
2572
- record_used : Option < Span > )
2577
+ record_used : bool ,
2578
+ path_span : Span )
2573
2579
-> PathResult < ' a > {
2574
2580
let mut module = None ;
2575
2581
let mut allow_super = true ;
@@ -2603,20 +2609,20 @@ impl<'a> Resolver<'a> {
2603
2609
}
2604
2610
2605
2611
let binding = if let Some ( module) = module {
2606
- self . resolve_ident_in_module ( module, ident, ns, false , record_used)
2612
+ self . resolve_ident_in_module ( module, ident, ns, false , record_used, path_span )
2607
2613
} else if opt_ns == Some ( MacroNS ) {
2608
- self . resolve_lexical_macro_path_segment ( ident, ns, record_used)
2614
+ self . resolve_lexical_macro_path_segment ( ident, ns, record_used, path_span )
2609
2615
. map ( MacroBinding :: binding)
2610
2616
} else {
2611
- match self . resolve_ident_in_lexical_scope ( ident, ns, record_used) {
2617
+ match self . resolve_ident_in_lexical_scope ( ident, ns, record_used, path_span ) {
2612
2618
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
2613
2619
Some ( LexicalScopeBinding :: Def ( def) )
2614
2620
if opt_ns == Some ( TypeNS ) || opt_ns == Some ( ValueNS ) => {
2615
2621
return PathResult :: NonModule ( PathResolution :: with_unresolved_segments (
2616
2622
def, path. len ( ) - 1
2617
2623
) ) ;
2618
2624
}
2619
- _ => Err ( if record_used. is_some ( ) { Determined } else { Undetermined } ) ,
2625
+ _ => Err ( if record_used { Determined } else { Undetermined } ) ,
2620
2626
}
2621
2627
} ;
2622
2628
@@ -2673,12 +2679,13 @@ impl<'a> Resolver<'a> {
2673
2679
ns : Namespace ,
2674
2680
rib_index : usize ,
2675
2681
mut def : Def ,
2676
- record_used : Option < Span > ) -> Def {
2682
+ record_used : bool ,
2683
+ span : Span ) -> Def {
2677
2684
let ribs = & self . ribs [ ns] [ rib_index + 1 ..] ;
2678
2685
2679
2686
// An invalid forward use of a type parameter from a previous default.
2680
2687
if let ForwardTyParamBanRibKind = self . ribs [ ns] [ rib_index] . kind {
2681
- if let Some ( span ) = record_used {
2688
+ if record_used {
2682
2689
resolve_error ( self , span,
2683
2690
ResolutionError :: ForwardDeclaredTyParam ) ;
2684
2691
}
@@ -2688,7 +2695,7 @@ impl<'a> Resolver<'a> {
2688
2695
2689
2696
match def {
2690
2697
Def :: Upvar ( ..) => {
2691
- span_bug ! ( record_used . unwrap_or ( DUMMY_SP ) , "unexpected {:?} in bindings" , def)
2698
+ span_bug ! ( span , "unexpected {:?} in bindings" , def)
2692
2699
}
2693
2700
Def :: Local ( def_id) => {
2694
2701
for rib in ribs {
@@ -2714,7 +2721,7 @@ impl<'a> Resolver<'a> {
2714
2721
let depth = vec. len ( ) ;
2715
2722
def = Def :: Upvar ( def_id, depth, function_id) ;
2716
2723
2717
- if let Some ( span ) = record_used {
2724
+ if record_used {
2718
2725
vec. push ( Freevar {
2719
2726
def : prev_def,
2720
2727
span : span,
@@ -2726,15 +2733,15 @@ impl<'a> Resolver<'a> {
2726
2733
// This was an attempt to access an upvar inside a
2727
2734
// named function item. This is not allowed, so we
2728
2735
// report an error.
2729
- if let Some ( span ) = record_used {
2736
+ if record_used {
2730
2737
resolve_error ( self , span,
2731
2738
ResolutionError :: CannotCaptureDynamicEnvironmentInFnItem ) ;
2732
2739
}
2733
2740
return Def :: Err ;
2734
2741
}
2735
2742
ConstantItemRibKind => {
2736
2743
// Still doesn't deal with upvars
2737
- if let Some ( span ) = record_used {
2744
+ if record_used {
2738
2745
resolve_error ( self , span,
2739
2746
ResolutionError :: AttemptToUseNonConstantValueInConstant ) ;
2740
2747
}
@@ -2753,15 +2760,15 @@ impl<'a> Resolver<'a> {
2753
2760
ItemRibKind => {
2754
2761
// This was an attempt to use a type parameter outside
2755
2762
// its scope.
2756
- if let Some ( span ) = record_used {
2763
+ if record_used {
2757
2764
resolve_error ( self , span,
2758
2765
ResolutionError :: TypeParametersFromOuterFunction ) ;
2759
2766
}
2760
2767
return Def :: Err ;
2761
2768
}
2762
2769
ConstantItemRibKind => {
2763
2770
// see #9186
2764
- if let Some ( span ) = record_used {
2771
+ if record_used {
2765
2772
resolve_error ( self , span,
2766
2773
ResolutionError :: OuterTypeParameterContext ) ;
2767
2774
}
@@ -2857,7 +2864,8 @@ impl<'a> Resolver<'a> {
2857
2864
fn lookup_typo_candidate < FilterFn > ( & mut self ,
2858
2865
path : & [ Ident ] ,
2859
2866
ns : Namespace ,
2860
- filter_fn : FilterFn )
2867
+ filter_fn : FilterFn ,
2868
+ span : Span )
2861
2869
-> Option < Symbol >
2862
2870
where FilterFn : Fn ( Def ) -> bool
2863
2871
{
@@ -2909,7 +2917,8 @@ impl<'a> Resolver<'a> {
2909
2917
} else {
2910
2918
// Search in module.
2911
2919
let mod_path = & path[ ..path. len ( ) - 1 ] ;
2912
- if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2920
+ if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) ,
2921
+ false , span) {
2913
2922
add_module_candidates ( module, & mut names) ;
2914
2923
}
2915
2924
}
@@ -3410,7 +3419,10 @@ impl<'a> Resolver<'a> {
3410
3419
continue
3411
3420
}
3412
3421
let ident = attr. path . segments [ 0 ] . identifier ;
3413
- let result = self . resolve_lexical_macro_path_segment ( ident, MacroNS , None ) ;
3422
+ let result = self . resolve_lexical_macro_path_segment ( ident,
3423
+ MacroNS ,
3424
+ false ,
3425
+ attr. path . span ) ;
3414
3426
if let Ok ( binding) = result {
3415
3427
if let SyntaxExtension :: AttrProcMacro ( ..) = * binding. binding ( ) . get_macro ( self ) {
3416
3428
attr:: mark_known ( attr) ;
0 commit comments