Rollup merge of #110498 - kylematsuda:earlybinder-rpitit-tys, r=compiler-errors

Switch to `EarlyBinder` for `collect_return_position_impl_trait_in_trait_tys`

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `collect_return_position_impl_trait_in_trait_tys` query and removes `bound_return_position_impl_trait_in_trait_tys`.

r? `@lcnr`
This commit is contained in:
Matthias Krüger 2023-04-19 06:35:35 +02:00 committed by GitHub
commit 9f0b16b2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 20 deletions

View File

@ -579,7 +579,7 @@ fn compare_asyncness<'tcx>(
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
impl_m_def_id: LocalDefId, impl_m_def_id: LocalDefId,
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> { ) -> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed> {
let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap(); let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap();
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap(); let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
let impl_trait_ref = let impl_trait_ref =
@ -782,14 +782,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
}) })
}); });
debug!(%ty); debug!(%ty);
collected_tys.insert(def_id, ty); collected_tys.insert(def_id, ty::EarlyBinder(ty));
} }
Err(err) => { Err(err) => {
let reported = tcx.sess.delay_span_bug( let reported = tcx.sess.delay_span_bug(
return_span, return_span,
format!("could not fully resolve: {ty} => {err:?}"), format!("could not fully resolve: {ty} => {err:?}"),
); );
collected_tys.insert(def_id, tcx.ty_error(reported)); collected_tys.insert(def_id, ty::EarlyBinder(tcx.ty_error(reported)));
} }
} }
} }

View File

@ -251,7 +251,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) { match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
Ok(map) => { Ok(map) => {
let assoc_item = tcx.associated_item(def_id); let assoc_item = tcx.associated_item(def_id);
return ty::EarlyBinder(map[&assoc_item.trait_item_def_id.unwrap()]); return map[&assoc_item.trait_item_def_id.unwrap()];
} }
Err(_) => { Err(_) => {
return ty::EarlyBinder(tcx.ty_error_with_message( return ty::EarlyBinder(tcx.ty_error_with_message(

View File

@ -416,7 +416,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>, macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>,
proc_macro: Table<DefIndex, MacroKind>, proc_macro: Table<DefIndex, MacroKind>,
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>, deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>, trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, ty::EarlyBinder<Ty<'static>>>>>,
doc_link_resolutions: Table<DefIndex, LazyValue<DocLinkResMap>>, doc_link_resolutions: Table<DefIndex, LazyValue<DocLinkResMap>>,
doc_link_traits_in_scope: Table<DefIndex, LazyArray<DefId>>, doc_link_traits_in_scope: Table<DefIndex, LazyArray<DefId>>,
} }

View File

@ -114,7 +114,11 @@ macro_rules! arena_types {
[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>, [] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,
[decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>, [decode] trait_impl_trait_tys:
rustc_data_structures::fx::FxHashMap<
rustc_hir::def_id::DefId,
rustc_middle::ty::EarlyBinder<rustc_middle::ty::Ty<'tcx>>
>,
[] bit_set_u32: rustc_index::bit_set::BitSet<u32>, [] bit_set_u32: rustc_index::bit_set::BitSet<u32>,
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>, [] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>,
[decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap, [decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,

View File

@ -181,7 +181,7 @@
} }
query collect_return_position_impl_trait_in_trait_tys(key: DefId) query collect_return_position_impl_trait_in_trait_tys(key: DefId)
-> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> -> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed>
{ {
desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" } desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }

View File

@ -694,13 +694,6 @@ pub fn try_expand_impl_trait_type(
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) } if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
} }
pub fn bound_return_position_impl_trait_in_trait_tys(
self,
def_id: DefId,
) -> ty::EarlyBinder<Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>> {
ty::EarlyBinder(self.collect_return_position_impl_trait_in_trait_tys(def_id))
}
pub fn bound_explicit_item_bounds( pub fn bound_explicit_item_bounds(
self, self,
def_id: DefId, def_id: DefId,

View File

@ -807,7 +807,9 @@ fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
} }
} }
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashMap<DefId, Ty<'tcx>> { impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
for &'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>
{
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
RefDecodable::decode(d) RefDecodable::decode(d)
} }

View File

@ -2277,11 +2277,10 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
obligation.param_env, obligation.param_env,
cause.clone(), cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
tcx.bound_return_position_impl_trait_in_trait_tys(impl_fn_def_id) tcx.collect_return_position_impl_trait_in_trait_tys(impl_fn_def_id).map_or_else(
.map_bound(|tys| { |guar| tcx.ty_error(guar),
tys.map_or_else(|guar| tcx.ty_error(guar), |tys| tys[&obligation.predicate.def_id]) |tys| tys[&obligation.predicate.def_id].subst(tcx, impl_fn_substs),
}) ),
.subst(tcx, impl_fn_substs),
&mut obligations, &mut obligations,
); );