Skip to content

Commit 290c638

Browse files
committed
Implement type_of for RPITITs assoc type
1 parent e10034c commit 290c638

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::subst::InternalSubsts;
1010
use rustc_middle::ty::util::IntTypeExt;
1111
use rustc_middle::ty::{
12-
self, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
12+
self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
13+
TypeVisitableExt,
1314
};
1415
use rustc_span::symbol::Ident;
1516
use rustc_span::{Span, DUMMY_SP};
@@ -244,6 +245,24 @@ fn get_path_containing_arg_in_pat<'hir>(
244245
}
245246

246247
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>> {
248+
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
249+
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
250+
// associated type in the impl.
251+
if let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
252+
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
253+
Ok(map) => {
254+
let assoc_item = tcx.associated_item(def_id);
255+
return ty::EarlyBinder(map[&assoc_item.trait_item_def_id.unwrap()]);
256+
}
257+
Err(_) => {
258+
return ty::EarlyBinder(tcx.ty_error_with_message(
259+
DUMMY_SP,
260+
"Could not collect return position impl trait in trait tys",
261+
));
262+
}
263+
}
264+
}
265+
247266
let def_id = def_id.expect_local();
248267
use rustc_hir::*;
249268

0 commit comments

Comments
 (0)