@@ -84,11 +84,11 @@ mod check_unused;
84
84
mod build_reduced_graph;
85
85
mod resolve_imports;
86
86
87
- pub struct ResolvePath < ' a >
88
- {
89
- ident : & ' a [ Ident ] ,
90
- source : Option < NodeId > , // None if this path is speculative
91
- speculative : bool ,
87
+ pub struct ResolvePath < ' a > {
88
+ ident : & ' a [ Ident ] ,
89
+ /// NodeId of the path that we are attempting to resolve. When None, this path is being
90
+ /// speculatively resolved and we should not emit errors or lints about it
91
+ source : Option < NodeId > ,
92
92
}
93
93
94
94
/// A free importable items suggested in case of resolution failure.
@@ -1662,17 +1662,16 @@ impl<'a> Resolver<'a> {
1662
1662
. map ( |seg| Ident :: new ( seg. name , span) )
1663
1663
. collect ( ) ;
1664
1664
1665
- let resolve_path = ResolvePath {
1666
- ident : & path,
1667
- source : None ,
1668
- speculative : true ,
1669
- } ;
1665
+ let path = ResolvePath {
1666
+ ident : & path,
1667
+ source : None ,
1668
+ } ;
1670
1669
// FIXME (Manishearth): Intra doc links won't get warned of epoch changes
1671
- match self . resolve_path ( & resolve_path , Some ( namespace) , true , span) {
1670
+ match self . resolve_path ( & path , Some ( namespace) , true , span) {
1672
1671
PathResult :: Module ( module) => * def = module. def ( ) . unwrap ( ) ,
1673
1672
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1674
1673
* def = path_res. base_def ( ) ,
1675
- PathResult :: NonModule ( ..) => match self . resolve_path ( & resolve_path , None , true , span) {
1674
+ PathResult :: NonModule ( ..) => match self . resolve_path ( & path , None , true , span) {
1676
1675
PathResult :: Failed ( span, msg, _) => {
1677
1676
error_callback ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
1678
1677
}
@@ -2365,10 +2364,9 @@ impl<'a> Resolver<'a> {
2365
2364
. map ( |seg| seg. ident )
2366
2365
. collect ( ) ;
2367
2366
let path = ResolvePath {
2368
- ident : & path,
2369
- source : Some ( trait_ref. ref_id ) ,
2370
- speculative : false ,
2371
- } ;
2367
+ ident : & path,
2368
+ source : Some ( trait_ref. ref_id ) ,
2369
+ } ;
2372
2370
let def = self . smart_resolve_path_fragment (
2373
2371
trait_ref. ref_id ,
2374
2372
None ,
@@ -2805,10 +2803,9 @@ impl<'a> Resolver<'a> {
2805
2803
. map ( |seg| seg. ident )
2806
2804
. collect :: < Vec < _ > > ( ) ;
2807
2805
let resolve_path = ResolvePath {
2808
- ident : & segments,
2809
- source : Some ( id) ,
2810
- speculative : false ,
2811
- } ;
2806
+ ident : & segments,
2807
+ source : Some ( id) ,
2808
+ } ;
2812
2809
self . smart_resolve_path_fragment ( id, qself, & resolve_path, path. span , source)
2813
2810
}
2814
2811
@@ -2844,10 +2841,9 @@ impl<'a> Resolver<'a> {
2844
2841
( format ! ( "" ) , format ! ( "the crate root" ) )
2845
2842
} else {
2846
2843
let mod_path = ResolvePath {
2847
- ident : & path. ident [ ..path. ident . len ( ) - 1 ] ,
2848
- source : Some ( id) ,
2849
- speculative : false ,
2850
- } ;
2844
+ ident : & path. ident [ ..path. ident . len ( ) - 1 ] ,
2845
+ source : Some ( id) ,
2846
+ } ;
2851
2847
let mod_prefix = match this. resolve_path ( & mod_path, Some ( TypeNS ) ,
2852
2848
false , span) {
2853
2849
PathResult :: Module ( module) => module. def ( ) ,
@@ -3172,12 +3168,11 @@ impl<'a> Resolver<'a> {
3172
3168
}
3173
3169
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
3174
3170
let ns = if qself. position + 1 == path. ident . len ( ) { ns } else { TypeNS } ;
3175
- let resolve_path = ResolvePath {
3176
- ident : & path. ident [ ..qself. position + 1 ] ,
3177
- source : Some ( id) ,
3178
- speculative : false ,
3179
- } ;
3180
- let res = self . smart_resolve_path_fragment ( id, None , & resolve_path,
3171
+ let path = ResolvePath {
3172
+ ident : & path. ident [ ..qself. position + 1 ] ,
3173
+ source : Some ( id) ,
3174
+ } ;
3175
+ let res = self . smart_resolve_path_fragment ( id, None , & path,
3181
3176
span, PathSource :: TraitItem ( ns) ) ;
3182
3177
return Some ( PathResolution :: with_unresolved_segments (
3183
3178
res. base_def ( ) , res. unresolved_segments ( ) + path. ident . len ( ) - qself. position - 1
@@ -3221,12 +3216,11 @@ impl<'a> Resolver<'a> {
3221
3216
path. ident [ 0 ] . name != keywords:: CrateRoot . name ( ) &&
3222
3217
path. ident [ 0 ] . name != keywords:: DollarCrate . name ( ) {
3223
3218
let unqualified_result = {
3224
- let resolve_path = ResolvePath {
3225
- ident : & [ * path. ident . last ( ) . unwrap ( ) ] ,
3226
- source : None ,
3227
- speculative : true ,
3228
- } ;
3229
- match self . resolve_path ( & resolve_path, Some ( ns) , false , span) {
3219
+ let path = ResolvePath {
3220
+ ident : & [ * path. ident . last ( ) . unwrap ( ) ] ,
3221
+ source : None ,
3222
+ } ;
3223
+ match self . resolve_path ( & path, Some ( ns) , false , span) {
3230
3224
PathResult :: NonModule ( path_res) => path_res. base_def ( ) ,
3231
3225
PathResult :: Module ( module) => module. def ( ) . unwrap ( ) ,
3232
3226
_ => return Some ( result) ,
@@ -3639,10 +3633,9 @@ impl<'a> Resolver<'a> {
3639
3633
} else {
3640
3634
// Search in module.
3641
3635
let mod_path = ResolvePath {
3642
- ident : & path[ ..path. len ( ) - 1 ] ,
3643
- source : None ,
3644
- speculative : true ,
3645
- } ;
3636
+ ident : & path[ ..path. len ( ) - 1 ] ,
3637
+ source : None ,
3638
+ } ;
3646
3639
if let PathResult :: Module ( module) = self . resolve_path ( & mod_path, Some ( TypeNS ) ,
3647
3640
false , span) {
3648
3641
add_module_candidates ( module, & mut names) ;
@@ -4062,12 +4055,12 @@ impl<'a> Resolver<'a> {
4062
4055
let segments = path. make_root ( ) . iter ( ) . chain ( path. segments . iter ( ) )
4063
4056
. map ( |seg| seg. ident )
4064
4057
. collect :: < Vec < _ > > ( ) ;
4065
- let resolve_path = ResolvePath {
4066
- ident : & segments ,
4067
- source : None ,
4068
- speculative : true ,
4069
- } ;
4070
- let def = self . smart_resolve_path_fragment ( id, None , & resolve_path , path . span ,
4058
+ let span = path . span ;
4059
+ let path = ResolvePath {
4060
+ ident : & segments ,
4061
+ source : None ,
4062
+ } ;
4063
+ let def = self . smart_resolve_path_fragment ( id, None , & path , span,
4071
4064
PathSource :: Visibility ) . base_def ( ) ;
4072
4065
if def == Def :: Err {
4073
4066
ty:: Visibility :: Public
@@ -4076,8 +4069,8 @@ impl<'a> Resolver<'a> {
4076
4069
if self . is_accessible ( vis) {
4077
4070
vis
4078
4071
} else {
4079
- self . session . span_err ( path . span , "visibilities can only be restricted \
4080
- to ancestor modules") ;
4072
+ self . session . span_err ( span, "visibilities can only be restricted \
4073
+ to ancestor modules") ;
4081
4074
ty:: Visibility :: Public
4082
4075
}
4083
4076
}
0 commit comments