@@ -38,7 +38,7 @@ use rustc_macros::{TypeFoldable, TypeVisitable};
3838use rustc_middle:: middle:: stability:: AllowUnstable ;
3939use rustc_middle:: mir:: interpret:: LitToConstInput ;
4040use rustc_middle:: ty:: print:: PrintPolyTraitRefExt as _;
41- use rustc_middle:: ty:: typeck_results:: { HasTypeDependentDefs , TypeDependentDef } ;
41+ use rustc_middle:: ty:: typeck_results:: HasTypeDependentDefs ;
4242use rustc_middle:: ty:: {
4343 self , Const , GenericArgKind , GenericArgsRef , GenericParamDefKind , Ty , TyCtxt , TypeVisitableExt ,
4444 TypingMode , Upcast , fold_regions,
@@ -204,7 +204,7 @@ pub trait HirTyLowerer<'tcx>: HasTypeDependentDefs {
204204 fn record_ty ( & self , hir_id : HirId , ty : Ty < ' tcx > , span : Span ) ;
205205
206206 /// Record the resolution of a HIR node corresponding to a type-dependent definition in this context.
207- fn record_res ( & self , hir_id : hir:: HirId , result : TypeDependentDef ) ;
207+ fn record_res ( & self , hir_id : hir:: HirId , result : DefId ) ;
208208
209209 /// The inference context of the lowering context if applicable.
210210 fn infcx ( & self ) -> Option < & InferCtxt < ' tcx > > ;
@@ -1159,28 +1159,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11591159 /// Lower a [type-relative](hir::QPath::TypeRelative) path in type position to a type.
11601160 ///
11611161 /// If the path refers to an enum variant and `permit_variants` holds,
1162- /// the returned type is simply the provided self type `qself_ty `.
1162+ /// the returned type is simply the provided self type `self_ty `.
11631163 ///
1164- /// A path like `A::B::C::D` is understood as `<A::B::C>::D`. I.e.,
1165- /// `qself_ty` / `qself` is `A::B::C` and `assoc_segment` is `D`.
1166- /// We return the lowered type and the `DefId` for the whole path.
1167- ///
1168- /// We only support associated type paths whose self type is a type parameter or a `Self`
1169- /// type alias (in a trait impl) like `T::Ty` (where `T` is a ty param) or `Self::Ty`.
1170- /// We **don't** support paths whose self type is an arbitrary type like `Struct::Ty` where
1171- /// struct `Struct` impls an in-scope trait that defines an associated type called `Ty`.
1172- /// For the latter case, we report ambiguity.
1173- /// While desirable to support, the implementation would be non-trivial. Tracked in [#22519].
1174- ///
1175- /// At the time of writing, *inherent associated types* are also resolved here. This however
1176- /// is [problematic][iat]. A proper implementation would be as non-trivial as the one
1177- /// described in the previous paragraph and their modeling of projections would likely be
1178- /// very similar in nature.
1179- ///
1180- /// [#22519]: https://github.com/rust-lang/rust/issues/22519
1181- /// [iat]: https://github.com/rust-lang/rust/issues/8995#issuecomment-1569208403
1182- // FIXME(fmease): Update docs
1183- //
11841164 // NOTE: When this function starts resolving `Trait::AssocTy` successfully
11851165 // it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
11861166 #[ instrument( level = "debug" , skip_all, ret) ]
@@ -1192,7 +1172,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11921172 qpath_hir_id : HirId ,
11931173 span : Span ,
11941174 permit_variants : PermitVariants ,
1195- ) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
1175+ ) -> Result < ( Ty < ' tcx > , DefId ) , ErrorGuaranteed > {
11961176 let tcx = self . tcx ( ) ;
11971177 match self . lower_type_relative_path (
11981178 self_ty,
@@ -1203,15 +1183,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12031183 LowerTypeRelativePathMode :: Type ( permit_variants) ,
12041184 ) ? {
12051185 TypeRelativePath :: AssocItem ( def_id, args) => {
1206- let kind = tcx. def_kind ( def_id) ;
1207- self . record_res ( qpath_hir_id, Ok ( ( kind, def_id) ) ) ;
12081186 let alias_ty = ty:: AliasTy :: new_from_args ( tcx, def_id, args) ;
12091187 let ty = Ty :: new_alias ( tcx, alias_ty. kind ( tcx) , alias_ty) ;
1210- Ok ( ( ty, kind, def_id) )
1211- }
1212- TypeRelativePath :: Variant { adt, variant_did } => {
1213- Ok ( ( adt, DefKind :: Variant , variant_did) )
1188+ Ok ( ( ty, def_id) )
12141189 }
1190+ TypeRelativePath :: Variant { adt, variant_did } => Ok ( ( adt, variant_did) ) ,
12151191 }
12161192 }
12171193
@@ -1255,6 +1231,27 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12551231 }
12561232
12571233 /// Lower a [type-relative][hir::QPath::TypeRelative] (and type-level) path.
1234+ ///
1235+ /// A path like `A::B::C::D` is understood as `<A::B::C>::D`. I.e., the self type is `A::B::C`
1236+ /// and the `segment` is `D`.
1237+ ///
1238+ /// <!-- FIXME(fmease): No longer accurate -->
1239+ ///
1240+ /// We only support associated item paths whose self type is a type parameter or a `Self`
1241+ /// type alias (in a trait impl) like `T::Ty` (where `T` is a ty param) or `Self::Ty`.
1242+ /// We **don't** support paths whose self type is an arbitrary type like `Struct::Ty` where
1243+ /// struct `Struct` impls an in-scope trait that defines an associated type called `Ty`.
1244+ /// For the latter case, we report ambiguity.
1245+ /// While desirable to support, the implementation would be non-trivial. Tracked in [#22519].
1246+ ///
1247+ /// <!-- FIXME(fmease): Slightly outdated, too -->
1248+ ///
1249+ /// At the time of writing, *inherent associated types* are also resolved here. This however
1250+ /// is problematic. A proper implementation would be as non-trivial as the one
1251+ /// described in the previous paragraph and their modeling of projections would likely be
1252+ /// very similar in nature.
1253+ ///
1254+ /// [#22519]: https://github.com/rust-lang/rust/issues/22519
12581255 #[ instrument( level = "debug" , skip_all, ret) ]
12591256 fn lower_type_relative_path (
12601257 & self ,
@@ -1287,6 +1284,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12871284 adt_def,
12881285 } ,
12891286 ) ;
1287+ self . record_res ( qpath_hir_id, variant_def. def_id ) ;
12901288 return Ok ( TypeRelativePath :: Variant {
12911289 adt : self_ty,
12921290 variant_did : variant_def. def_id ,
@@ -1298,15 +1296,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12981296 }
12991297
13001298 // FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
1301- if let Some ( ( did , args) ) = self . probe_inherent_assoc_item (
1299+ if let Some ( ( def_id , args) ) = self . probe_inherent_assoc_item (
13021300 segment,
13031301 adt_def. did ( ) ,
13041302 self_ty,
13051303 qpath_hir_id,
13061304 span,
13071305 mode. assoc_tag ( ) ,
13081306 ) ? {
1309- return Ok ( TypeRelativePath :: AssocItem ( did, args) ) ;
1307+ self . record_res ( qpath_hir_id, def_id) ;
1308+ return Ok ( TypeRelativePath :: AssocItem ( def_id, args) ) ;
13101309 }
13111310 }
13121311
@@ -1445,6 +1444,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14451444 . probe_assoc_item ( segment. ident , assoc_tag, qpath_hir_id, span, bound. def_id ( ) )
14461445 . expect ( "failed to find associated item" ) ;
14471446
1447+ self . record_res ( qpath_hir_id, assoc_item. def_id ) ;
1448+
14481449 Ok ( ( assoc_item. def_id , bound) )
14491450 }
14501451
@@ -2546,7 +2547,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25462547 hir_ty. span ,
25472548 PermitVariants :: No ,
25482549 )
2549- . map ( |( ty, _, _ ) | ty)
2550+ . map ( |( ty, _) | ty)
25502551 . unwrap_or_else ( |guar| Ty :: new_error ( tcx, guar) )
25512552 }
25522553 & hir:: TyKind :: Path ( hir:: QPath :: LangItem ( lang_item, span) ) => {
0 commit comments