Implement type_of for RPITITs assoc type
This commit is contained in:
parent
e10034c636
commit
290c638b5f
@ -9,7 +9,8 @@
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_middle::ty::{
|
||||
self, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
|
||||
self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
|
||||
TypeVisitableExt,
|
||||
};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
@ -244,6 +245,24 @@ fn get_path_containing_arg_in_pat<'hir>(
|
||||
}
|
||||
|
||||
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>> {
|
||||
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
|
||||
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
|
||||
// associated type in the impl.
|
||||
if let Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
|
||||
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
|
||||
Ok(map) => {
|
||||
let assoc_item = tcx.associated_item(def_id);
|
||||
return ty::EarlyBinder(map[&assoc_item.trait_item_def_id.unwrap()]);
|
||||
}
|
||||
Err(_) => {
|
||||
return ty::EarlyBinder(tcx.ty_error_with_message(
|
||||
DUMMY_SP,
|
||||
"Could not collect return position impl trait in trait tys",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let def_id = def_id.expect_local();
|
||||
use rustc_hir::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user