diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2023-03-03 12:36:44 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2023-03-06 14:49:48 -0300 |
| commit | 290c638b5f8f03704744351fa3aa02fb04b00ffc (patch) | |
| tree | 3054903eba11d736a76059afa92015a66d0d6400 | |
| parent | e10034c6360916c0fdddf092bb3b7db3c98e436f (diff) | |
| download | rust-290c638b5f8f03704744351fa3aa02fb04b00ffc.tar.gz rust-290c638b5f8f03704744351fa3aa02fb04b00ffc.zip | |
Implement type_of for RPITITs assoc type
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/type_of.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index acd9f8a5c8e..045a8a57186 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -9,7 +9,8 @@ use rustc_middle::ty::print::with_forced_trimmed_paths; 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::*; |
