@@ -39,6 +39,7 @@ use rustc_infer::traits::ObligationCause;
39
39
use rustc_middle:: middle:: stability:: AllowUnstable ;
40
40
use rustc_middle:: mir:: interpret:: { LitToConstError , LitToConstInput } ;
41
41
use rustc_middle:: ty:: print:: PrintPolyTraitRefExt as _;
42
+ use rustc_middle:: ty:: typeck_results:: { HasTypeDependentDefs , TypeDependentDef } ;
42
43
use rustc_middle:: ty:: {
43
44
self , Const , GenericArgKind , GenericArgsRef , GenericParamDefKind , ParamEnv , Ty , TyCtxt ,
44
45
TypeVisitableExt ,
@@ -98,7 +99,7 @@ pub enum RegionInferReason<'a> {
98
99
/// the [`rustc_middle::ty`] representation.
99
100
///
100
101
/// This trait used to be called `AstConv`.
101
- pub trait HirTyLowerer < ' tcx > {
102
+ pub trait HirTyLowerer < ' tcx > : HasTypeDependentDefs {
102
103
fn tcx ( & self ) -> TyCtxt < ' tcx > ;
103
104
104
105
/// Returns the [`LocalDefId`] of the overarching item whose constituents get lowered.
@@ -173,6 +174,8 @@ pub trait HirTyLowerer<'tcx> {
173
174
/// Record the lowered type of a HIR node in this context.
174
175
fn record_ty ( & self , hir_id : HirId , ty : Ty < ' tcx > , span : Span ) ;
175
176
177
+ fn record_res ( & self , hir_id : hir:: HirId , result : TypeDependentDef ) ;
178
+
176
179
/// The inference context of the lowering context if applicable.
177
180
fn infcx ( & self ) -> Option < & InferCtxt < ' tcx > > ;
178
181
@@ -192,6 +195,8 @@ pub trait HirTyLowerer<'tcx> {
192
195
{
193
196
self
194
197
}
198
+
199
+ fn upcast ( & self ) -> & dyn HasTypeDependentDefs ;
195
200
}
196
201
197
202
/// New-typed boolean indicating whether explicit late-bound lifetimes
@@ -992,6 +997,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
992
997
/// [type-relative]: hir::QPath::TypeRelative
993
998
/// [#22519]: https://github.com/rust-lang/rust/issues/22519
994
999
/// [iat]: https://github.com/rust-lang/rust/issues/8995#issuecomment-1569208403
1000
+ // FIXME(fmease): Update docs
995
1001
//
996
1002
// NOTE: When this function starts resolving `Trait::AssocTy` successfully
997
1003
// it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
@@ -1006,13 +1012,33 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1006
1012
permit_variants : bool ,
1007
1013
) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
1008
1014
debug ! ( %qself_ty, ?assoc_segment. ident) ;
1015
+ let result = self . lower_assoc_path_inner (
1016
+ hir_ref_id,
1017
+ span,
1018
+ qself_ty,
1019
+ qself,
1020
+ assoc_segment,
1021
+ permit_variants,
1022
+ ) ;
1023
+ self . record_res ( hir_ref_id, result. map ( |( _, def_kind, def_id) | ( def_kind, def_id) ) ) ;
1024
+ result
1025
+ }
1026
+
1027
+ fn lower_assoc_path_inner (
1028
+ & self ,
1029
+ hir_ref_id : HirId ,
1030
+ span : Span ,
1031
+ qself_ty : Ty < ' tcx > ,
1032
+ qself : & ' tcx hir:: Ty < ' tcx > ,
1033
+ assoc_segment : & ' tcx hir:: PathSegment < ' tcx > ,
1034
+ permit_variants : bool ,
1035
+ ) -> Result < ( Ty < ' tcx > , DefKind , DefId ) , ErrorGuaranteed > {
1009
1036
let tcx = self . tcx ( ) ;
1010
1037
1011
1038
let assoc_ident = assoc_segment. ident ;
1012
- let qself_res = if let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = & qself. kind {
1013
- path. res
1014
- } else {
1015
- Res :: Err
1039
+ let qself_res = match & qself. kind {
1040
+ hir:: TyKind :: Path ( qpath) => self . upcast ( ) . qpath_res ( qpath, qself. hir_id ) ,
1041
+ _ => Res :: Err ,
1016
1042
} ;
1017
1043
1018
1044
// Check if we have an enum variant or an inherent associated type.
@@ -1038,15 +1064,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1038
1064
}
1039
1065
1040
1066
// FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
1041
- if let Some ( ( ty, did ) ) = self . probe_inherent_assoc_ty (
1067
+ if let Some ( ( ty, def_id ) ) = self . probe_inherent_assoc_ty (
1042
1068
assoc_ident,
1043
1069
assoc_segment,
1044
1070
adt_def. did ( ) ,
1045
1071
qself_ty,
1046
1072
hir_ref_id,
1047
1073
span,
1048
1074
) ? {
1049
- return Ok ( ( ty, DefKind :: AssocTy , did ) ) ;
1075
+ return Ok ( ( ty, DefKind :: AssocTy , def_id ) ) ;
1050
1076
}
1051
1077
}
1052
1078
@@ -1085,14 +1111,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1085
1111
assoc_ident,
1086
1112
span,
1087
1113
) ?,
1088
- // FIXME(fmease):
1089
- // Require the pre-lowered projectee (the HIR QSelf) to have `DefKind::AssocTy`. Rephrased,
1090
- // `T::Assoc::Assoc` typeck'ing shouldn't imply `Identity<T::Assoc>::Assoc` typeck'ing where
1091
- // `Identity` is an eager (i.e., non-lazy) type alias. We should do this
1092
- // * for consistency with lazy type aliases (`ty::Weak`)
1093
- // * for consistency with the fact that `T::Assoc` typeck'ing doesn't imply `Identity<T>::Assoc`
1094
- // typeck'ing
1095
- ( ty:: Alias ( ty:: Projection , alias_ty) , _ /* Res::Def(DefKind::AssocTy, _) */ ) => {
1114
+ ( ty:: Alias ( ty:: Projection , alias_ty) , Res :: Def ( DefKind :: AssocTy , _) ) => {
1096
1115
// FIXME: Utilizing `item_bounds` for this is cycle-prone.
1097
1116
let predicates = tcx. item_bounds ( alias_ty. def_id ) . instantiate ( tcx, alias_ty. args ) ;
1098
1117
0 commit comments