@@ -38,7 +38,7 @@ use rustc_macros::{TypeFoldable, TypeVisitable};
38
38
use rustc_middle:: middle:: stability:: AllowUnstable ;
39
39
use rustc_middle:: mir:: interpret:: LitToConstInput ;
40
40
use rustc_middle:: ty:: print:: PrintPolyTraitRefExt as _;
41
- use rustc_middle:: ty:: typeck_results:: { HasTypeDependentDefs , TypeDependentDef } ;
41
+ use rustc_middle:: ty:: typeck_results:: HasTypeDependentDefs ;
42
42
use rustc_middle:: ty:: {
43
43
self , Const , GenericArgKind , GenericArgsRef , GenericParamDefKind , Ty , TyCtxt , TypeVisitableExt ,
44
44
TypingMode , Upcast , fold_regions,
@@ -204,7 +204,7 @@ pub trait HirTyLowerer<'tcx>: HasTypeDependentDefs {
204
204
fn record_ty ( & self , hir_id : HirId , ty : Ty < ' tcx > , span : Span ) ;
205
205
206
206
/// 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 ) ;
208
208
209
209
/// The inference context of the lowering context if applicable.
210
210
fn infcx ( & self ) -> Option < & InferCtxt < ' tcx > > ;
@@ -1159,28 +1159,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1159
1159
/// Lower a [type-relative](hir::QPath::TypeRelative) path in type position to a type.
1160
1160
///
1161
1161
/// 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 `.
1163
1163
///
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
- //
1184
1164
// NOTE: When this function starts resolving `Trait::AssocTy` successfully
1185
1165
// it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
1186
1166
#[ instrument( level = "debug" , skip_all, ret) ]
@@ -1192,7 +1172,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1192
1172
qpath_hir_id : HirId ,
1193
1173
span : Span ,
1194
1174
permit_variants : PermitVariants ,
1195
- ) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
1175
+ ) -> Result < ( Ty < ' tcx > , DefId ) , ErrorGuaranteed > {
1196
1176
let tcx = self . tcx ( ) ;
1197
1177
match self . lower_type_relative_path (
1198
1178
self_ty,
@@ -1203,15 +1183,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1203
1183
LowerTypeRelativePathMode :: Type ( permit_variants) ,
1204
1184
) ? {
1205
1185
TypeRelativePath :: AssocItem ( def_id, args) => {
1206
- let kind = tcx. def_kind ( def_id) ;
1207
- self . record_res ( qpath_hir_id, Ok ( ( kind, def_id) ) ) ;
1208
1186
let alias_ty = ty:: AliasTy :: new_from_args ( tcx, def_id, args) ;
1209
1187
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) )
1214
1189
}
1190
+ TypeRelativePath :: Variant { adt, variant_did } => Ok ( ( adt, variant_did) ) ,
1215
1191
}
1216
1192
}
1217
1193
@@ -1255,6 +1231,27 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1255
1231
}
1256
1232
1257
1233
/// 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
1258
1255
#[ instrument( level = "debug" , skip_all, ret) ]
1259
1256
fn lower_type_relative_path (
1260
1257
& self ,
@@ -1287,6 +1284,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1287
1284
adt_def,
1288
1285
} ,
1289
1286
) ;
1287
+ self . record_res ( qpath_hir_id, variant_def. def_id ) ;
1290
1288
return Ok ( TypeRelativePath :: Variant {
1291
1289
adt : self_ty,
1292
1290
variant_did : variant_def. def_id ,
@@ -1298,15 +1296,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1298
1296
}
1299
1297
1300
1298
// 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 (
1302
1300
segment,
1303
1301
adt_def. did ( ) ,
1304
1302
self_ty,
1305
1303
qpath_hir_id,
1306
1304
span,
1307
1305
mode. assoc_tag ( ) ,
1308
1306
) ? {
1309
- return Ok ( TypeRelativePath :: AssocItem ( did, args) ) ;
1307
+ self . record_res ( qpath_hir_id, def_id) ;
1308
+ return Ok ( TypeRelativePath :: AssocItem ( def_id, args) ) ;
1310
1309
}
1311
1310
}
1312
1311
@@ -1445,6 +1444,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1445
1444
. probe_assoc_item ( segment. ident , assoc_tag, qpath_hir_id, span, bound. def_id ( ) )
1446
1445
. expect ( "failed to find associated item" ) ;
1447
1446
1447
+ self . record_res ( qpath_hir_id, assoc_item. def_id ) ;
1448
+
1448
1449
Ok ( ( assoc_item. def_id , bound) )
1449
1450
}
1450
1451
@@ -2546,7 +2547,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2546
2547
hir_ty. span ,
2547
2548
PermitVariants :: No ,
2548
2549
)
2549
- . map ( |( ty, _, _ ) | ty)
2550
+ . map ( |( ty, _) | ty)
2550
2551
. unwrap_or_else ( |guar| Ty :: new_error ( tcx, guar) )
2551
2552
}
2552
2553
& hir:: TyKind :: Path ( hir:: QPath :: LangItem ( lang_item, span) ) => {
0 commit comments