@@ -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" ,
@@ -2200,14 +2200,16 @@ impl<'a> Resolver<'a> {
2200
2200
source : PathSource )
2201
2201
-> PathResolution {
2202
2202
let segments = & path. segments . iter ( ) . map ( |seg| seg. identifier ) . collect :: < Vec < _ > > ( ) ;
2203
- self . smart_resolve_path_fragment ( id, qself, segments, path. span , source)
2203
+ let ident_span = path. segments . last ( ) . map_or ( path. span , |seg| seg. span ) ;
2204
+ self . smart_resolve_path_fragment ( id, qself, segments, path. span , ident_span, source)
2204
2205
}
2205
2206
2206
2207
fn smart_resolve_path_fragment ( & mut self ,
2207
2208
id : NodeId ,
2208
2209
qself : Option < & QSelf > ,
2209
2210
path : & [ Ident ] ,
2210
2211
span : Span ,
2212
+ ident_span : Span ,
2211
2213
source : PathSource )
2212
2214
-> PathResolution {
2213
2215
let ns = source. namespace ( ) ;
@@ -2219,9 +2221,9 @@ impl<'a> Resolver<'a> {
2219
2221
let expected = source. descr_expected ( ) ;
2220
2222
let path_str = names_to_string ( path) ;
2221
2223
let code = source. error_code ( def. is_some ( ) ) ;
2222
- let ( base_msg, fallback_label) = if let Some ( def) = def {
2224
+ let ( base_msg, fallback_label, base_span ) = if let Some ( def) = def {
2223
2225
( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2224
- format ! ( "not a {}" , expected) )
2226
+ format ! ( "not a {}" , expected) , span )
2225
2227
} else {
2226
2228
let item_str = path[ path. len ( ) - 1 ] ;
2227
2229
let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
@@ -2237,9 +2239,9 @@ impl<'a> Resolver<'a> {
2237
2239
( mod_prefix, format ! ( "`{}`" , names_to_string( mod_path) ) )
2238
2240
} ;
2239
2241
( format ! ( "cannot find {} `{}` in {}{}" , expected, item_str, mod_prefix, mod_str) ,
2240
- format ! ( "not found in {}" , mod_str) )
2242
+ format ! ( "not found in {}" , mod_str) , ident_span )
2241
2243
} ;
2242
- let mut err = this. session . struct_span_err_with_code ( span , & base_msg, code) ;
2244
+ let mut err = this. session . struct_span_err_with_code ( base_span , & base_msg, code) ;
2243
2245
2244
2246
// Emit special messages for unresolved `Self` and `self`.
2245
2247
if is_self_type ( path, ns) {
@@ -2297,15 +2299,15 @@ impl<'a> Resolver<'a> {
2297
2299
err. span_label ( span, & format ! ( "type aliases cannot be used for traits" ) ) ;
2298
2300
return err;
2299
2301
}
2300
- ( Def :: Mod ( ..) , PathSource :: Expr ( Some ( parent) ) ) => match * parent {
2302
+ ( Def :: Mod ( ..) , PathSource :: Expr ( Some ( parent) ) ) => match parent. node {
2301
2303
ExprKind :: Field ( _, ident) => {
2302
- err. span_label ( span, & format ! ( "did you mean `{}::{}`?" ,
2303
- path_str, ident. node) ) ;
2304
+ err. span_label ( parent . span , & format ! ( "did you mean `{}::{}`?" ,
2305
+ path_str, ident. node) ) ;
2304
2306
return err;
2305
2307
}
2306
2308
ExprKind :: MethodCall ( ident, ..) => {
2307
- err. span_label ( span, & format ! ( "did you mean `{}::{}(...)`?" ,
2308
- path_str, ident. node) ) ;
2309
+ err. span_label ( parent . span , & format ! ( "did you mean `{}::{}(...)`?" ,
2310
+ path_str, ident. node) ) ;
2309
2311
return err;
2310
2312
}
2311
2313
_ => { }
@@ -2330,12 +2332,12 @@ impl<'a> Resolver<'a> {
2330
2332
2331
2333
// Try Levenshtein if nothing else worked.
2332
2334
if let Some ( candidate) = this. lookup_typo_candidate ( path, ns, is_expected) {
2333
- err. span_label ( span , & format ! ( "did you mean `{}`?" , candidate) ) ;
2335
+ err. span_label ( ident_span , & format ! ( "did you mean `{}`?" , candidate) ) ;
2334
2336
return err;
2335
2337
}
2336
2338
2337
2339
// Fallback label.
2338
- err. span_label ( span , & fallback_label) ;
2340
+ err. span_label ( base_span , & fallback_label) ;
2339
2341
err
2340
2342
} ;
2341
2343
let report_errors = |this : & mut Self , def : Option < Def > | {
@@ -2455,7 +2457,7 @@ impl<'a> Resolver<'a> {
2455
2457
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
2456
2458
let ns = if qself. position + 1 == path. len ( ) { ns } else { TypeNS } ;
2457
2459
let res = self . smart_resolve_path_fragment ( id, None , & path[ ..qself. position + 1 ] ,
2458
- span, PathSource :: TraitItem ( ns) ) ;
2460
+ span, span , PathSource :: TraitItem ( ns) ) ;
2459
2461
return Some ( PathResolution :: with_unresolved_segments (
2460
2462
res. base_def ( ) , res. unresolved_segments ( ) + path. len ( ) - qself. position - 1
2461
2463
) ) ;
@@ -2813,7 +2815,7 @@ impl<'a> Resolver<'a> {
2813
2815
path : & [ Ident ] ,
2814
2816
ns : Namespace ,
2815
2817
filter_fn : FilterFn )
2816
- -> Option < String >
2818
+ -> Option < Symbol >
2817
2819
where FilterFn : Fn ( Def ) -> bool
2818
2820
{
2819
2821
let add_module_candidates = |module : Module , names : & mut Vec < Name > | {
@@ -2827,7 +2829,7 @@ impl<'a> Resolver<'a> {
2827
2829
} ;
2828
2830
2829
2831
let mut names = Vec :: new ( ) ;
2830
- let prefix_str = if path. len ( ) == 1 {
2832
+ if path. len ( ) == 1 {
2831
2833
// Search in lexical scope.
2832
2834
// Walk backwards up the ribs in scope and collect candidates.
2833
2835
for rib in self . ribs [ ns] . iter ( ) . rev ( ) {
@@ -2861,21 +2863,19 @@ impl<'a> Resolver<'a> {
2861
2863
names. push ( * name) ;
2862
2864
}
2863
2865
}
2864
- String :: new ( )
2865
2866
} else {
2866
2867
// Search in module.
2867
2868
let mod_path = & path[ ..path. len ( ) - 1 ] ;
2868
2869
if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2869
2870
add_module_candidates ( module, & mut names) ;
2870
2871
}
2871
- names_to_string ( mod_path) + "::"
2872
- } ;
2872
+ }
2873
2873
2874
2874
let name = path[ path. len ( ) - 1 ] . name ;
2875
2875
// Make sure error reporting is deterministic.
2876
2876
names. sort_by_key ( |name| name. as_str ( ) ) ;
2877
2877
match find_best_match_for_name ( names. iter ( ) , & name. as_str ( ) , None ) {
2878
- Some ( found) if found != name => Some ( format ! ( "{}{}" , prefix_str , found) ) ,
2878
+ Some ( found) if found != name => Some ( found) ,
2879
2879
_ => None ,
2880
2880
}
2881
2881
}
@@ -2898,7 +2898,7 @@ impl<'a> Resolver<'a> {
2898
2898
self . with_resolved_label ( label, id, |this| this. visit_block ( block) ) ;
2899
2899
}
2900
2900
2901
- fn resolve_expr ( & mut self , expr : & Expr , parent : Option < & ExprKind > ) {
2901
+ fn resolve_expr ( & mut self , expr : & Expr , parent : Option < & Expr > ) {
2902
2902
// First, record candidate traits for this expression if it could
2903
2903
// result in the invocation of a method call.
2904
2904
@@ -2979,11 +2979,11 @@ impl<'a> Resolver<'a> {
2979
2979
2980
2980
// Equivalent to `visit::walk_expr` + passing some context to children.
2981
2981
ExprKind :: Field ( ref subexpression, _) => {
2982
- self . resolve_expr ( subexpression, Some ( & expr. node ) ) ;
2982
+ self . resolve_expr ( subexpression, Some ( expr) ) ;
2983
2983
}
2984
2984
ExprKind :: MethodCall ( _, ref types, ref arguments) => {
2985
2985
let mut arguments = arguments. iter ( ) ;
2986
- self . resolve_expr ( arguments. next ( ) . unwrap ( ) , Some ( & expr. node ) ) ;
2986
+ self . resolve_expr ( arguments. next ( ) . unwrap ( ) , Some ( expr) ) ;
2987
2987
for argument in arguments {
2988
2988
self . resolve_expr ( argument, None ) ;
2989
2989
}
@@ -2999,7 +2999,7 @@ impl<'a> Resolver<'a> {
2999
2999
} ) ;
3000
3000
}
3001
3001
ExprKind :: Call ( ref callee, ref arguments) => {
3002
- self . resolve_expr ( callee, Some ( & expr. node ) ) ;
3002
+ self . resolve_expr ( callee, Some ( expr) ) ;
3003
3003
for argument in arguments {
3004
3004
self . resolve_expr ( argument, None ) ;
3005
3005
}
@@ -3130,11 +3130,10 @@ impl<'a> Resolver<'a> {
3130
3130
if ident. name == lookup_name && ns == namespace {
3131
3131
if filter_fn ( name_binding. def ( ) ) {
3132
3132
// create the path
3133
- let span = name_binding. span ;
3134
3133
let mut segms = path_segments. clone ( ) ;
3135
- segms. push ( ident. into ( ) ) ;
3134
+ segms. push ( ast :: PathSegment :: from_ident ( ident, name_binding . span ) ) ;
3136
3135
let path = Path {
3137
- span : span,
3136
+ span : name_binding . span ,
3138
3137
segments : segms,
3139
3138
} ;
3140
3139
// the entity is accessible in the following cases:
@@ -3154,7 +3153,7 @@ impl<'a> Resolver<'a> {
3154
3153
if let Some ( module) = name_binding. module ( ) {
3155
3154
// form the path
3156
3155
let mut path_segments = path_segments. clone ( ) ;
3157
- path_segments. push ( ident. into ( ) ) ;
3156
+ path_segments. push ( ast :: PathSegment :: from_ident ( ident, name_binding . span ) ) ;
3158
3157
3159
3158
if !in_module_is_extern || name_binding. vis == ty:: Visibility :: Public {
3160
3159
// add the module to the lookup
0 commit comments