@@ -38,7 +38,6 @@ use self::TypeParameters::*;
38
38
use self :: RibKind :: * ;
39
39
use self :: UseLexicalScopeFlag :: * ;
40
40
use self :: ModulePrefixResult :: * ;
41
- use self :: AssocItemResolveResult :: * ;
42
41
use self :: ParentLink :: * ;
43
42
44
43
use rustc:: hir:: map:: Definitions ;
@@ -671,15 +670,6 @@ enum ModulePrefixResult<'a> {
671
670
PrefixFound ( Module < ' a > , usize ) ,
672
671
}
673
672
674
- #[ derive( Copy , Clone ) ]
675
- enum AssocItemResolveResult {
676
- /// Syntax such as `<T>::item`, which can't be resolved until type
677
- /// checking.
678
- TypecheckRequired ,
679
- /// We should have been able to resolve the associated item.
680
- ResolveAttempt ( Option < PathResolution > ) ,
681
- }
682
-
683
673
/// One local scope.
684
674
#[ derive( Debug ) ]
685
675
struct Rib < ' a > {
@@ -2131,24 +2121,12 @@ impl<'a> Resolver<'a> {
2131
2121
fn resolve_type ( & mut self , ty : & Ty ) {
2132
2122
match ty. node {
2133
2123
TyKind :: Path ( ref maybe_qself, ref path) => {
2134
- let resolution = match self . resolve_possibly_assoc_item ( ty. id ,
2135
- maybe_qself. as_ref ( ) ,
2136
- path,
2137
- TypeNS ) {
2138
- // `<T>::a::b::c` is resolved by typeck alone.
2139
- TypecheckRequired => {
2140
- // Resolve embedded types.
2141
- visit:: walk_ty ( self , ty) ;
2142
- return ;
2143
- }
2144
- ResolveAttempt ( resolution) => resolution,
2145
- } ;
2146
-
2147
2124
// This is a path in the type namespace. Walk through scopes
2148
2125
// looking for it.
2149
- if let Some ( def) = resolution {
2126
+ if let Some ( def) = self . resolve_possibly_assoc_item ( ty. id , maybe_qself. as_ref ( ) ,
2127
+ path, TypeNS ) {
2150
2128
match def. base_def {
2151
- Def :: Mod ( ..) => {
2129
+ Def :: Mod ( ..) if def . depth == 0 => {
2152
2130
self . session . span_err ( path. span , "expected type, found module" ) ;
2153
2131
self . record_def ( ty. id , err_path_resolution ( ) ) ;
2154
2132
}
@@ -2281,54 +2259,40 @@ impl<'a> Resolver<'a> {
2281
2259
expected_what : & ' static str )
2282
2260
where ExpectedFn : FnOnce ( Def ) -> bool
2283
2261
{
2284
- let resolution = match self . resolve_possibly_assoc_item ( pat_id, qself, path, namespace) {
2285
- ResolveAttempt ( resolution) => {
2286
- if let Some ( resolution) = resolution {
2287
- if resolution. depth == 0 {
2288
- if expected_fn ( resolution. base_def ) {
2289
- resolution
2290
- } else {
2291
- resolve_error (
2292
- self ,
2293
- path. span ,
2294
- ResolutionError :: PatPathUnexpected ( expected_what,
2295
- resolution. kind_name ( ) , path)
2296
- ) ;
2297
- err_path_resolution ( )
2298
- }
2299
- } else {
2300
- // Not fully resolved associated item `T::A::B::C` or
2301
- // `<T as Tr>::A::B::C`. If `C` should be resolved in value
2302
- // namespace then it needs to be added to the trait map.
2303
- if namespace == ValueNS {
2304
- let item_name = path. segments . last ( ) . unwrap ( ) . identifier . name ;
2305
- let traits = self . get_traits_containing_item ( item_name) ;
2306
- self . trait_map . insert ( pat_id, traits) ;
2307
- }
2308
- resolution
2309
- }
2262
+ let resolution = if let Some ( resolution) = self . resolve_possibly_assoc_item ( pat_id,
2263
+ qself, path, namespace) {
2264
+ if resolution. depth == 0 {
2265
+ if expected_fn ( resolution. base_def ) {
2266
+ resolution
2310
2267
} else {
2311
- if let Err ( false ) = self . resolve_path ( pat_id, path, 0 , namespace) {
2312
- resolve_error (
2313
- self ,
2314
- path. span ,
2315
- ResolutionError :: PatPathUnresolved ( expected_what, path)
2316
- ) ;
2317
- }
2268
+ resolve_error (
2269
+ self ,
2270
+ path. span ,
2271
+ ResolutionError :: PatPathUnexpected ( expected_what,
2272
+ resolution. kind_name ( ) , path)
2273
+ ) ;
2318
2274
err_path_resolution ( )
2319
2275
}
2320
- }
2321
- TypecheckRequired => {
2322
- // `<T>::A::B::C`, resolves exclusively during typechecking.
2323
- // If `C` should be resolved in value namespace then it needs
2324
- // to be added to the trait map.
2276
+ } else {
2277
+ // Not fully resolved associated item `T::A::B` or `<T as Tr>::A::B`
2278
+ // or `<T>::A::B`. If `B` should be resolved in value namespace then
2279
+ // it needs to be added to the trait map.
2325
2280
if namespace == ValueNS {
2326
2281
let item_name = path. segments . last ( ) . unwrap ( ) . identifier . name ;
2327
2282
let traits = self . get_traits_containing_item ( item_name) ;
2328
2283
self . trait_map . insert ( pat_id, traits) ;
2329
2284
}
2330
- return ;
2285
+ resolution
2286
+ }
2287
+ } else {
2288
+ if let Err ( false ) = self . resolve_path ( pat_id, path, 0 , namespace) {
2289
+ resolve_error (
2290
+ self ,
2291
+ path. span ,
2292
+ ResolutionError :: PatPathUnresolved ( expected_what, path)
2293
+ ) ;
2331
2294
}
2295
+ err_path_resolution ( )
2332
2296
} ;
2333
2297
2334
2298
self . record_def ( pat_id, resolution) ;
@@ -2444,13 +2408,17 @@ impl<'a> Resolver<'a> {
2444
2408
maybe_qself : Option < & QSelf > ,
2445
2409
path : & Path ,
2446
2410
namespace : Namespace )
2447
- -> AssocItemResolveResult {
2411
+ -> Option < PathResolution > {
2448
2412
let max_assoc_types;
2449
2413
2450
2414
match maybe_qself {
2451
2415
Some ( qself) => {
2452
2416
if qself. position == 0 {
2453
- return TypecheckRequired ;
2417
+ // FIXME: Create some fake resolution that can't possibly be a type.
2418
+ return Some ( PathResolution {
2419
+ base_def : Def :: Mod ( self . definitions . local_def_id ( ast:: CRATE_NODE_ID ) ) ,
2420
+ depth : path. segments . len ( )
2421
+ } ) ;
2454
2422
}
2455
2423
max_assoc_types = path. segments . len ( ) - qself. position ;
2456
2424
// Make sure the trait is valid.
@@ -2477,7 +2445,7 @@ impl<'a> Resolver<'a> {
2477
2445
}
2478
2446
} ) ;
2479
2447
}
2480
- ResolveAttempt ( resolution)
2448
+ resolution
2481
2449
}
2482
2450
2483
2451
/// Skips `path_depth` trailing segments, which is also reflected in the
@@ -2826,24 +2794,10 @@ impl<'a> Resolver<'a> {
2826
2794
// Next, resolve the node.
2827
2795
match expr. node {
2828
2796
ExprKind :: Path ( ref maybe_qself, ref path) => {
2829
- let resolution = match self . resolve_possibly_assoc_item ( expr. id ,
2830
- maybe_qself. as_ref ( ) ,
2831
- path,
2832
- ValueNS ) {
2833
- // `<T>::a::b::c` is resolved by typeck alone.
2834
- TypecheckRequired => {
2835
- let method_name = path. segments . last ( ) . unwrap ( ) . identifier . name ;
2836
- let traits = self . get_traits_containing_item ( method_name) ;
2837
- self . trait_map . insert ( expr. id , traits) ;
2838
- visit:: walk_expr ( self , expr) ;
2839
- return ;
2840
- }
2841
- ResolveAttempt ( resolution) => resolution,
2842
- } ;
2843
-
2844
2797
// This is a local path in the value namespace. Walk through
2845
2798
// scopes looking for it.
2846
- if let Some ( path_res) = resolution {
2799
+ if let Some ( path_res) = self . resolve_possibly_assoc_item ( expr. id ,
2800
+ maybe_qself. as_ref ( ) , path, ValueNS ) {
2847
2801
// Check if struct variant
2848
2802
let is_struct_variant = if let Def :: Variant ( _, variant_id) = path_res. base_def {
2849
2803
self . structs . contains_key ( & variant_id)
0 commit comments