@@ -106,9 +106,12 @@ pub trait AstConv<'tcx> {
106
106
poly_trait_ref : ty:: PolyTraitRef < ' tcx > ,
107
107
) -> Ty < ' tcx > ;
108
108
109
- fn normalize_ty_2 ( & self , _span : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
110
- ty
111
- }
109
+ /// Returns `AdtDef` if `ty` is an ADT.
110
+ /// Note that `ty` might be a projection type that needs normalization.
111
+ /// This used to get the enum variants in scope of the type.
112
+ /// For example, `Self::A` could refer to an associated type
113
+ /// or to an enum variant depending on the result of this function.
114
+ fn probe_adt ( & self , span : Span , ty : Ty < ' tcx > ) -> Option < ty:: AdtDef < ' tcx > > ;
112
115
113
116
/// Invoked when we encounter an error from some prior pass
114
117
/// (e.g., resolve) that is translated into a ty-error. This is
@@ -1805,7 +1808,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1805
1808
1806
1809
// Check if we have an enum variant.
1807
1810
let mut variant_resolution = None ;
1808
- if let ty :: Adt ( adt_def, adt_substs ) = self . normalize_ty_2 ( span, qself_ty) . kind ( ) {
1811
+ if let Some ( adt_def) = self . probe_adt ( span, qself_ty) {
1809
1812
if adt_def. is_enum ( ) {
1810
1813
let variant_def = adt_def
1811
1814
. variants ( )
@@ -1907,6 +1910,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1907
1910
let Some ( assoc_ty_did) = self . lookup_assoc_ty ( assoc_ident, hir_ref_id, span, impl_) else {
1908
1911
continue ;
1909
1912
} ;
1913
+ let ty:: Adt ( _, adt_substs) = qself_ty. kind ( ) else {
1914
+ // FIXME(inherent_associated_types)
1915
+ bug ! ( "unimplemented: non-adt self of inherent assoc ty" ) ;
1916
+ } ;
1910
1917
let item_substs = self . create_substs_for_associated_item (
1911
1918
span,
1912
1919
assoc_ty_did,
@@ -2262,6 +2269,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2262
2269
self_ty : Option < Ty < ' tcx > > ,
2263
2270
kind : DefKind ,
2264
2271
def_id : DefId ,
2272
+ span : Span ,
2265
2273
) -> Vec < PathSeg > {
2266
2274
// We need to extract the type parameters supplied by the user in
2267
2275
// the path `path`. Due to the current setup, this is a bit of a
@@ -2329,8 +2337,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2329
2337
2330
2338
// Case 2. Reference to a variant constructor.
2331
2339
DefKind :: Ctor ( CtorOf :: Variant , ..) | DefKind :: Variant => {
2332
- let adt_def = self_ty . map ( |t| t . ty_adt_def ( ) . unwrap ( ) ) ;
2333
- let ( generics_def_id , index ) = if let Some ( adt_def) = adt_def {
2340
+ let ( generics_def_id , index ) = if let Some ( self_ty ) = self_ty {
2341
+ let adt_def = self . probe_adt ( span , self_ty ) . unwrap ( ) ;
2334
2342
debug_assert ! ( adt_def. is_enum( ) ) ;
2335
2343
( adt_def. did ( ) , last)
2336
2344
} else if last >= 1 && segments[ last - 1 ] . args . is_some ( ) {
@@ -2426,7 +2434,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2426
2434
assert_eq ! ( opt_self_ty, None ) ;
2427
2435
2428
2436
let path_segs =
2429
- self . def_ids_for_value_path_segments ( path. segments , None , kind, def_id) ;
2437
+ self . def_ids_for_value_path_segments ( path. segments , None , kind, def_id, span ) ;
2430
2438
let generic_segs: FxHashSet < _ > =
2431
2439
path_segs. iter ( ) . map ( |PathSeg ( _, index) | index) . collect ( ) ;
2432
2440
self . prohibit_generics (
0 commit comments