@@ -407,7 +407,7 @@ enum PathSource<'a> {
407
407
// Trait paths in bounds or impls.
408
408
Trait ,
409
409
// Expression paths `path`, with optional parent context.
410
- Expr ( Option < & ' a ExprKind > ) ,
410
+ Expr ( Option < & ' a Expr > ) ,
411
411
// Paths in path patterns `Path`.
412
412
Pat ,
413
413
// Paths in struct expressions and patterns `Path { .. }`.
@@ -464,7 +464,7 @@ impl<'a> PathSource<'a> {
464
464
ValueNS => "method or associated constant" ,
465
465
MacroNS => bug ! ( "associated macro" ) ,
466
466
} ,
467
- PathSource :: Expr ( parent) => match parent {
467
+ PathSource :: Expr ( parent) => match parent. map ( |p| & p . node ) {
468
468
// "function" here means "anything callable" rather than `Def::Fn`,
469
469
// this is not precise but usually more helpful than just "value".
470
470
Some ( & ExprKind :: Call ( ..) ) => "function" ,
@@ -2194,14 +2194,16 @@ impl<'a> Resolver<'a> {
2194
2194
source : PathSource )
2195
2195
-> PathResolution {
2196
2196
let segments = & path. segments . iter ( ) . map ( |seg| seg. identifier ) . collect :: < Vec < _ > > ( ) ;
2197
- self . smart_resolve_path_fragment ( id, qself, segments, path. span , source)
2197
+ let ident_span = path. segments . last ( ) . map_or ( path. span , |seg| seg. span ) ;
2198
+ self . smart_resolve_path_fragment ( id, qself, segments, path. span , ident_span, source)
2198
2199
}
2199
2200
2200
2201
fn smart_resolve_path_fragment ( & mut self ,
2201
2202
id : NodeId ,
2202
2203
qself : Option < & QSelf > ,
2203
2204
path : & [ Ident ] ,
2204
2205
span : Span ,
2206
+ ident_span : Span ,
2205
2207
source : PathSource )
2206
2208
-> PathResolution {
2207
2209
let ns = source. namespace ( ) ;
@@ -2213,9 +2215,9 @@ impl<'a> Resolver<'a> {
2213
2215
let expected = source. descr_expected ( ) ;
2214
2216
let path_str = names_to_string ( path) ;
2215
2217
let code = source. error_code ( def. is_some ( ) ) ;
2216
- let ( base_msg, fallback_label) = if let Some ( def) = def {
2218
+ let ( base_msg, fallback_label, base_span ) = if let Some ( def) = def {
2217
2219
( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2218
- format ! ( "not a {}" , expected) )
2220
+ format ! ( "not a {}" , expected) , span )
2219
2221
} else {
2220
2222
let item_str = path[ path. len ( ) - 1 ] ;
2221
2223
let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
@@ -2231,9 +2233,9 @@ impl<'a> Resolver<'a> {
2231
2233
( mod_prefix, format ! ( "`{}`" , names_to_string( mod_path) ) )
2232
2234
} ;
2233
2235
( format ! ( "cannot find {} `{}` in {}{}" , expected, item_str, mod_prefix, mod_str) ,
2234
- format ! ( "not found in {}" , mod_str) )
2236
+ format ! ( "not found in {}" , mod_str) , ident_span )
2235
2237
} ;
2236
- let mut err = this. session . struct_span_err_with_code ( span , & base_msg, code) ;
2238
+ let mut err = this. session . struct_span_err_with_code ( base_span , & base_msg, code) ;
2237
2239
2238
2240
// Emit special messages for unresolved `Self` and `self`.
2239
2241
if is_self_type ( path, ns) {
@@ -2291,15 +2293,15 @@ impl<'a> Resolver<'a> {
2291
2293
err. span_label ( span, & format ! ( "type aliases cannot be used for traits" ) ) ;
2292
2294
return err;
2293
2295
}
2294
- ( Def :: Mod ( ..) , PathSource :: Expr ( Some ( parent) ) ) => match * parent {
2296
+ ( Def :: Mod ( ..) , PathSource :: Expr ( Some ( parent) ) ) => match parent. node {
2295
2297
ExprKind :: Field ( _, ident) => {
2296
- err. span_label ( span, & format ! ( "did you mean `{}::{}`?" ,
2297
- path_str, ident. node) ) ;
2298
+ err. span_label ( parent . span , & format ! ( "did you mean `{}::{}`?" ,
2299
+ path_str, ident. node) ) ;
2298
2300
return err;
2299
2301
}
2300
2302
ExprKind :: MethodCall ( ident, ..) => {
2301
- err. span_label ( span, & format ! ( "did you mean `{}::{}(...)`?" ,
2302
- path_str, ident. node) ) ;
2303
+ err. span_label ( parent . span , & format ! ( "did you mean `{}::{}(...)`?" ,
2304
+ path_str, ident. node) ) ;
2303
2305
return err;
2304
2306
}
2305
2307
_ => { }
@@ -2324,12 +2326,12 @@ impl<'a> Resolver<'a> {
2324
2326
2325
2327
// Try Levenshtein if nothing else worked.
2326
2328
if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected) {
2327
- err. span_label ( span , & format ! ( "did you mean `{}`?" , candidate) ) ;
2329
+ err. span_label ( ident_span , & format ! ( "did you mean `{}`?" , candidate) ) ;
2328
2330
return err;
2329
2331
}
2330
2332
2331
2333
// Fallback label.
2332
- err. span_label ( span , & fallback_label) ;
2334
+ err. span_label ( base_span , & fallback_label) ;
2333
2335
err
2334
2336
} ;
2335
2337
let report_errors = |this : & mut Self , def : Option < Def > | {
@@ -2449,7 +2451,7 @@ impl<'a> Resolver<'a> {
2449
2451
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
2450
2452
let ns = if qself. position + 1 == path. len ( ) { ns } else { TypeNS } ;
2451
2453
let res = self . smart_resolve_path_fragment ( id, None , & path[ ..qself. position + 1 ] ,
2452
- span, PathSource :: TraitItem ( ns) ) ;
2454
+ span, span , PathSource :: TraitItem ( ns) ) ;
2453
2455
return Some ( PathResolution :: with_unresolved_segments (
2454
2456
res. base_def ( ) , res. unresolved_segments ( ) + path. len ( ) - qself. position - 1
2455
2457
) ) ;
@@ -2807,7 +2809,7 @@ impl<'a> Resolver<'a> {
2807
2809
path : & [ Ident ] ,
2808
2810
ns : Namespace ,
2809
2811
filter_fn : FilterFn )
2810
- -> Option < String >
2812
+ -> Option < Symbol >
2811
2813
where FilterFn : Fn ( Def ) -> bool
2812
2814
{
2813
2815
let add_module_candidates = |module : Module , names : & mut Vec < Name > | {
@@ -2821,7 +2823,7 @@ impl<'a> Resolver<'a> {
2821
2823
} ;
2822
2824
2823
2825
let mut names = Vec :: new ( ) ;
2824
- let prefix_str = if path. len ( ) == 1 {
2826
+ if path. len ( ) == 1 {
2825
2827
// Search in lexical scope.
2826
2828
// Walk backwards up the ribs in scope and collect candidates.
2827
2829
for rib in self . ribs [ ns] . iter ( ) . rev ( ) {
@@ -2855,21 +2857,19 @@ impl<'a> Resolver<'a> {
2855
2857
names. push ( * name) ;
2856
2858
}
2857
2859
}
2858
- String :: new ( )
2859
2860
} else {
2860
2861
// Search in module.
2861
2862
let mod_path = & path[ ..path. len ( ) - 1 ] ;
2862
2863
if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2863
2864
add_module_candidates ( module, & mut names) ;
2864
2865
}
2865
- names_to_string ( mod_path) + "::"
2866
- } ;
2866
+ }
2867
2867
2868
2868
let name = path[ path. len ( ) - 1 ] . name ;
2869
2869
// Make sure error reporting is deterministic.
2870
2870
names. sort_by_key ( |name| name. as_str ( ) ) ;
2871
2871
match find_best_match_for_name ( names. iter ( ) , & name. as_str ( ) , None ) {
2872
- Some ( found) if found != name => Some ( format ! ( "{}{}" , prefix_str , found) ) ,
2872
+ Some ( found) if found != name => Some ( found) ,
2873
2873
_ => None ,
2874
2874
}
2875
2875
}
@@ -2892,7 +2892,7 @@ impl<'a> Resolver<'a> {
2892
2892
self . with_resolved_label ( label, id, |this| this. visit_block ( block) ) ;
2893
2893
}
2894
2894
2895
- fn resolve_expr ( & mut self , expr : & Expr , parent : Option < & ExprKind > ) {
2895
+ fn resolve_expr ( & mut self , expr : & Expr , parent : Option < & Expr > ) {
2896
2896
// First, record candidate traits for this expression if it could
2897
2897
// result in the invocation of a method call.
2898
2898
@@ -2973,11 +2973,11 @@ impl<'a> Resolver<'a> {
2973
2973
2974
2974
// Equivalent to `visit::walk_expr` + passing some context to children.
2975
2975
ExprKind :: Field ( ref subexpression, _) => {
2976
- self . resolve_expr ( subexpression, Some ( & expr. node ) ) ;
2976
+ self . resolve_expr ( subexpression, Some ( expr) ) ;
2977
2977
}
2978
2978
ExprKind :: MethodCall ( _, ref types, ref arguments) => {
2979
2979
let mut arguments = arguments. iter ( ) ;
2980
- self . resolve_expr ( arguments. next ( ) . unwrap ( ) , Some ( & expr. node ) ) ;
2980
+ self . resolve_expr ( arguments. next ( ) . unwrap ( ) , Some ( expr) ) ;
2981
2981
for argument in arguments {
2982
2982
self . resolve_expr ( argument, None ) ;
2983
2983
}
@@ -2993,7 +2993,7 @@ impl<'a> Resolver<'a> {
2993
2993
} ) ;
2994
2994
}
2995
2995
ExprKind :: Call ( ref callee, ref arguments) => {
2996
- self . resolve_expr ( callee, Some ( & expr. node ) ) ;
2996
+ self . resolve_expr ( callee, Some ( expr) ) ;
2997
2997
for argument in arguments {
2998
2998
self . resolve_expr ( argument, None ) ;
2999
2999
}
0 commit comments