@@ -1195,7 +1195,8 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1195
1195
let path: Vec < _ > = segments. iter ( ) . map ( |seg| Ident :: with_empty_ctxt ( seg. name ) ) . collect ( ) ;
1196
1196
match self . resolve_path ( & path, Some ( namespace) , Some ( span) ) {
1197
1197
PathResult :: Module ( module) => * def = module. def ( ) . unwrap ( ) ,
1198
- PathResult :: NonModule ( path_res) if path_res. depth == 0 => * def = path_res. base_def ,
1198
+ PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1199
+ * def = path_res. base_def ( ) ,
1199
1200
PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , Some ( span) ) {
1200
1201
PathResult :: Failed ( msg, _) => {
1201
1202
resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
@@ -1718,7 +1719,7 @@ impl<'a> Resolver<'a> {
1718
1719
let mut new_id = None ;
1719
1720
if let Some ( trait_ref) = opt_trait_ref {
1720
1721
let def = self . smart_resolve_path ( trait_ref. ref_id , None ,
1721
- & trait_ref. path , PathSource :: Trait ) . base_def ;
1722
+ & trait_ref. path , PathSource :: Trait ) . base_def ( ) ;
1722
1723
if def != Def :: Err {
1723
1724
new_val = Some ( ( def. def_id ( ) , trait_ref. clone ( ) ) ) ;
1724
1725
new_id = Some ( def. def_id ( ) ) ;
@@ -1849,8 +1850,8 @@ impl<'a> Resolver<'a> {
1849
1850
1850
1851
pat. walk ( & mut |pat| {
1851
1852
if let PatKind :: Ident ( binding_mode, ident, ref sub_pat) = pat. node {
1852
- if sub_pat. is_some ( ) || match self . def_map . get ( & pat. id ) {
1853
- Some ( & PathResolution { base_def : Def :: Local ( ..) , .. } ) => true ,
1853
+ if sub_pat. is_some ( ) || match self . def_map . get ( & pat. id ) . map ( |res| res . base_def ( ) ) {
1854
+ Some ( Def :: Local ( ..) ) => true ,
1854
1855
_ => false ,
1855
1856
} {
1856
1857
let binding_info = BindingInfo { span : ident. span , binding_mode : binding_mode } ;
@@ -2248,14 +2249,14 @@ impl<'a> Resolver<'a> {
2248
2249
let resolution = match self . resolve_qpath_anywhere ( id, qself, path, ns, span,
2249
2250
source. defer_to_typeck ( ) ,
2250
2251
source. global_by_default ( ) ) {
2251
- Some ( resolution) if resolution. depth == 0 => {
2252
- if is_expected ( resolution. base_def ) || resolution. base_def == Def :: Err {
2252
+ Some ( resolution) if resolution. unresolved_segments ( ) == 0 => {
2253
+ if is_expected ( resolution. base_def ( ) ) || resolution. base_def ( ) == Def :: Err {
2253
2254
resolution
2254
2255
} else {
2255
2256
// Add a temporary hack to smooth the transition to new struct ctor
2256
2257
// visibility rules. See #38932 for more details.
2257
2258
let mut res = None ;
2258
- if let Def :: Struct ( def_id) = resolution. base_def {
2259
+ if let Def :: Struct ( def_id) = resolution. base_def ( ) {
2259
2260
if let Some ( ( ctor_def, ctor_vis) )
2260
2261
= self . struct_constructors . get ( & def_id) . cloned ( ) {
2261
2262
if is_expected ( ctor_def) && self . is_accessible ( ctor_vis) {
@@ -2268,7 +2269,7 @@ impl<'a> Resolver<'a> {
2268
2269
}
2269
2270
}
2270
2271
2271
- res. unwrap_or_else ( || report_errors ( self , Some ( resolution. base_def ) ) )
2272
+ res. unwrap_or_else ( || report_errors ( self , Some ( resolution. base_def ( ) ) ) )
2272
2273
}
2273
2274
}
2274
2275
Some ( resolution) if source. defer_to_typeck ( ) => {
@@ -2321,7 +2322,8 @@ impl<'a> Resolver<'a> {
2321
2322
match self . resolve_qpath ( id, qself, path, ns, span, global_by_default) {
2322
2323
// If defer_to_typeck, then resolution > no resolution,
2323
2324
// otherwise full resolution > partial resolution > no resolution.
2324
- Some ( res) if res. depth == 0 || defer_to_typeck => return Some ( res) ,
2325
+ Some ( res) if res. unresolved_segments ( ) == 0 || defer_to_typeck =>
2326
+ return Some ( res) ,
2325
2327
res => if fin_res. is_none ( ) { fin_res = res } ,
2326
2328
} ;
2327
2329
}
@@ -2346,19 +2348,17 @@ impl<'a> Resolver<'a> {
2346
2348
if let Some ( qself) = qself {
2347
2349
if qself. position == 0 {
2348
2350
// FIXME: Create some fake resolution that can't possibly be a type.
2349
- return Some ( PathResolution {
2350
- base_def : Def :: Mod ( DefId :: local ( CRATE_DEF_INDEX ) ) ,
2351
- depth : path. len ( ) ,
2352
- } ) ;
2351
+ return Some ( PathResolution :: with_unresolved_segments (
2352
+ Def :: Mod ( DefId :: local ( CRATE_DEF_INDEX ) ) , path. len ( )
2353
+ ) ) ;
2353
2354
}
2354
2355
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
2355
2356
let ns = if qself. position + 1 == path. len ( ) { ns } else { TypeNS } ;
2356
- let mut res = self . smart_resolve_path_fragment ( id, None , & path[ ..qself. position + 1 ] ,
2357
- span, PathSource :: TraitItem ( ns) ) ;
2358
- if res. base_def != Def :: Err {
2359
- res. depth += path. len ( ) - qself. position - 1 ;
2360
- }
2361
- return Some ( res) ;
2357
+ let res = self . smart_resolve_path_fragment ( id, None , & path[ ..qself. position + 1 ] ,
2358
+ span, PathSource :: TraitItem ( ns) ) ;
2359
+ return Some ( PathResolution :: with_unresolved_segments (
2360
+ res. base_def ( ) , res. unresolved_segments ( ) + path. len ( ) - qself. position - 1
2361
+ ) ) ;
2362
2362
}
2363
2363
2364
2364
let result = match self . resolve_path ( & path, Some ( ns) , Some ( span) ) {
@@ -2393,10 +2393,7 @@ impl<'a> Resolver<'a> {
2393
2393
}
2394
2394
_ => { }
2395
2395
}
2396
- PathResolution {
2397
- base_def : Def :: PrimTy ( prim) ,
2398
- depth : path. len ( ) - 1 ,
2399
- }
2396
+ PathResolution :: with_unresolved_segments ( Def :: PrimTy ( prim) , path. len ( ) - 1 )
2400
2397
}
2401
2398
PathResult :: Module ( module) => PathResolution :: new ( module. def ( ) . unwrap ( ) ) ,
2402
2399
PathResult :: Failed ( msg, false ) => {
@@ -2407,16 +2404,16 @@ impl<'a> Resolver<'a> {
2407
2404
PathResult :: Indeterminate => bug ! ( "indetermined path result in resolve_qpath" ) ,
2408
2405
} ;
2409
2406
2410
- if path. len ( ) > 1 && !global_by_default && result. base_def != Def :: Err &&
2407
+ if path. len ( ) > 1 && !global_by_default && result. base_def ( ) != Def :: Err &&
2411
2408
path[ 0 ] . name != keywords:: CrateRoot . name ( ) && path[ 0 ] . name != "$crate" {
2412
2409
let unqualified_result = {
2413
2410
match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , None ) {
2414
- PathResult :: NonModule ( path_res) => path_res. base_def ,
2411
+ PathResult :: NonModule ( path_res) => path_res. base_def ( ) ,
2415
2412
PathResult :: Module ( module) => module. def ( ) . unwrap ( ) ,
2416
2413
_ => return Some ( result) ,
2417
2414
}
2418
2415
} ;
2419
- if result. base_def == unqualified_result {
2416
+ if result. base_def ( ) == unqualified_result {
2420
2417
let lint = lint:: builtin:: UNUSED_QUALIFICATIONS ;
2421
2418
self . session . add_lint ( lint, id, span, "unnecessary qualification" . to_string ( ) ) ;
2422
2419
}
@@ -2470,10 +2467,9 @@ impl<'a> Resolver<'a> {
2470
2467
Some ( LexicalScopeBinding :: Item ( binding) ) => Ok ( binding) ,
2471
2468
Some ( LexicalScopeBinding :: Def ( def) )
2472
2469
if opt_ns == Some ( TypeNS ) || opt_ns == Some ( ValueNS ) => {
2473
- return PathResult :: NonModule ( PathResolution {
2474
- base_def : def,
2475
- depth : path. len ( ) - 1 ,
2476
- } ) ;
2470
+ return PathResult :: NonModule ( PathResolution :: with_unresolved_segments (
2471
+ def, path. len ( ) - 1
2472
+ ) ) ;
2477
2473
}
2478
2474
_ => Err ( if record_used. is_some ( ) { Determined } else { Undetermined } ) ,
2479
2475
}
@@ -2488,10 +2484,9 @@ impl<'a> Resolver<'a> {
2488
2484
} else if def == Def :: Err {
2489
2485
return PathResult :: NonModule ( err_path_resolution ( ) ) ;
2490
2486
} else if opt_ns. is_some ( ) && ( is_last || maybe_assoc) {
2491
- return PathResult :: NonModule ( PathResolution {
2492
- base_def : def,
2493
- depth : path. len ( ) - i - 1 ,
2494
- } ) ;
2487
+ return PathResult :: NonModule ( PathResolution :: with_unresolved_segments (
2488
+ def, path. len ( ) - i - 1
2489
+ ) ) ;
2495
2490
} else {
2496
2491
return PathResult :: Failed ( format ! ( "Not a module `{}`" , ident) , is_last) ;
2497
2492
}
@@ -2500,10 +2495,9 @@ impl<'a> Resolver<'a> {
2500
2495
Err ( Determined ) => {
2501
2496
if let Some ( module) = module {
2502
2497
if opt_ns. is_some ( ) && !module. is_normal ( ) {
2503
- return PathResult :: NonModule ( PathResolution {
2504
- base_def : module. def ( ) . unwrap ( ) ,
2505
- depth : path. len ( ) - i,
2506
- } ) ;
2498
+ return PathResult :: NonModule ( PathResolution :: with_unresolved_segments (
2499
+ module. def ( ) . unwrap ( ) , path. len ( ) - i
2500
+ ) ) ;
2507
2501
}
2508
2502
}
2509
2503
let msg = if module. and_then ( ModuleData :: def) == self . graph_root . def ( ) {
@@ -2672,8 +2666,9 @@ impl<'a> Resolver<'a> {
2672
2666
if let Some ( node_id) = self . current_self_type . as_ref ( ) . and_then ( extract_node_id) {
2673
2667
// Look for a field with the same name in the current self_type.
2674
2668
if let Some ( resolution) = self . def_map . get ( & node_id) {
2675
- match resolution. base_def {
2676
- Def :: Struct ( did) | Def :: Union ( did) if resolution. depth == 0 => {
2669
+ match resolution. base_def ( ) {
2670
+ Def :: Struct ( did) | Def :: Union ( did)
2671
+ if resolution. unresolved_segments ( ) == 0 => {
2677
2672
if let Some ( field_names) = self . field_names . get ( & did) {
2678
2673
if field_names. iter ( ) . any ( |& field_name| name == field_name) {
2679
2674
return Some ( AssocSuggestion :: Field ) ;
@@ -3057,7 +3052,6 @@ impl<'a> Resolver<'a> {
3057
3052
3058
3053
fn record_def ( & mut self , node_id : NodeId , resolution : PathResolution ) {
3059
3054
debug ! ( "(recording def) recording {:?} for {}" , resolution, node_id) ;
3060
- assert ! ( resolution. depth == 0 || resolution. base_def != Def :: Err ) ;
3061
3055
if let Some ( prev_res) = self . def_map . insert ( node_id, resolution) {
3062
3056
panic ! ( "path resolved multiple times ({:?} before, {:?} now)" , prev_res, resolution) ;
3063
3057
}
@@ -3071,7 +3065,8 @@ impl<'a> Resolver<'a> {
3071
3065
ty:: Visibility :: Restricted ( self . current_module . normal_ancestor_id )
3072
3066
}
3073
3067
ast:: Visibility :: Restricted { ref path, id } => {
3074
- let def = self . smart_resolve_path ( id, None , path, PathSource :: Visibility ) . base_def ;
3068
+ let def = self . smart_resolve_path ( id, None , path,
3069
+ PathSource :: Visibility ) . base_def ( ) ;
3075
3070
if def == Def :: Err {
3076
3071
ty:: Visibility :: Public
3077
3072
} else {
0 commit comments