@@ -106,9 +106,12 @@ pub trait AstConv<'tcx> {
106106 poly_trait_ref : ty:: PolyTraitRef < ' tcx > ,
107107 ) -> Ty < ' tcx > ;
108108
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 > > ;
112115
113116 /// Invoked when we encounter an error from some prior pass
114117 /// (e.g., resolve) that is translated into a ty-error. This is
@@ -1805,7 +1808,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18051808
18061809 // Check if we have an enum variant.
18071810 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) {
18091812 if adt_def. is_enum ( ) {
18101813 let variant_def = adt_def
18111814 . variants ( )
@@ -1907,6 +1910,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19071910 let Some ( assoc_ty_did) = self . lookup_assoc_ty ( assoc_ident, hir_ref_id, span, impl_) else {
19081911 continue ;
19091912 } ;
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+ } ;
19101917 let item_substs = self . create_substs_for_associated_item (
19111918 span,
19121919 assoc_ty_did,
@@ -2262,6 +2269,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22622269 self_ty : Option < Ty < ' tcx > > ,
22632270 kind : DefKind ,
22642271 def_id : DefId ,
2272+ span : Span ,
22652273 ) -> Vec < PathSeg > {
22662274 // We need to extract the type parameters supplied by the user in
22672275 // 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 {
23292337
23302338 // Case 2. Reference to a variant constructor.
23312339 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 ( ) ;
23342342 debug_assert ! ( adt_def. is_enum( ) ) ;
23352343 ( adt_def. did ( ) , last)
23362344 } else if last >= 1 && segments[ last - 1 ] . args . is_some ( ) {
@@ -2426,7 +2434,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24262434 assert_eq ! ( opt_self_ty, None ) ;
24272435
24282436 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 ) ;
24302438 let generic_segs: FxHashSet < _ > =
24312439 path_segs. iter ( ) . map ( |PathSeg ( _, index) | index) . collect ( ) ;
24322440 self . prohibit_generics (
0 commit comments