Skip to content

Commit 3f1900f

Browse files
committed
Implement type_of for RPITITs assoc type
1 parent 3d71fa6 commit 3f1900f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 17 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, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
12+
self, DefIdTree, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeFolder,
13+
TypeSuperFoldable, TypeVisitableExt,
1314
};
1415
use rustc_span::symbol::Ident;
1516
use rustc_span::{Span, DUMMY_SP};
@@ -244,6 +245,21 @@ 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 let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
249+
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
250+
Ok(map) => {
251+
let assoc_item = tcx.associated_item(def_id);
252+
return ty::EarlyBinder(map[&assoc_item.trait_item_def_id.unwrap()]);
253+
}
254+
Err(_) => {
255+
return ty::EarlyBinder(tcx.ty_error_with_message(
256+
DUMMY_SP,
257+
"Could not collect return position impl trait in trait tys",
258+
));
259+
}
260+
}
261+
}
262+
247263
let def_id = def_id.expect_local();
248264
use rustc_hir::*;
249265

0 commit comments

Comments
 (0)