From 522bc5f817696c113a03a462a5dbec794263dfcb Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Mon, 17 Apr 2023 11:46:01 -0600 Subject: [PATCH] add EarlyBinder to return type of collect_return_position_impl_trait_in_trait_tys query; remove bound_X version --- .../rustc_hir_analysis/src/check/compare_impl_item.rs | 6 +++--- compiler/rustc_hir_analysis/src/collect/type_of.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/src/arena.rs | 6 +++++- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 7 ------- compiler/rustc_query_impl/src/on_disk_cache.rs | 4 +++- compiler/rustc_trait_selection/src/traits/project.rs | 9 ++++----- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 863a9977446..fe87aae8ed1 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -579,7 +579,7 @@ fn compare_asyncness<'tcx>( pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( tcx: TyCtxt<'tcx>, impl_m_def_id: LocalDefId, -) -> Result<&'tcx FxHashMap>, ErrorGuaranteed> { +) -> Result<&'tcx FxHashMap>>, ErrorGuaranteed> { 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 impl_trait_ref = @@ -782,14 +782,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( }) }); debug!(%ty); - collected_tys.insert(def_id, ty); + collected_tys.insert(def_id, ty::EarlyBinder(ty)); } Err(err) => { let reported = tcx.sess.delay_span_bug( return_span, 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))); } } } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index c173bd913a8..f82fad47422 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -251,7 +251,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder { 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(_) => { return ty::EarlyBinder(tcx.ty_error_with_message( diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index dc77a079b07..a6a34765324 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -416,7 +416,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables { macro_definition: Table>, proc_macro: Table, deduced_param_attrs: Table>, - trait_impl_trait_tys: Table>>>, + trait_impl_trait_tys: Table>>>>, doc_link_resolutions: Table>, doc_link_traits_in_scope: Table>, } diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index dd1e254f405..60d7cf59d04 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -114,7 +114,11 @@ macro_rules! arena_types { [] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>, - [decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap>, + [decode] trait_impl_trait_tys: + rustc_data_structures::fx::FxHashMap< + rustc_hir::def_id::DefId, + rustc_middle::ty::EarlyBinder> + >, [] bit_set_u32: rustc_index::bit_set::BitSet, [] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>, [decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 6fc9190b090..7e26e05025f 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -181,7 +181,7 @@ } query collect_return_position_impl_trait_in_trait_tys(key: DefId) - -> Result<&'tcx FxHashMap>, ErrorGuaranteed> + -> Result<&'tcx FxHashMap>>, ErrorGuaranteed> { desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" } cache_on_disk_if { key.is_local() } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index c8a78ec03d9..dab5baae5ee 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -694,13 +694,6 @@ pub fn try_expand_impl_trait_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>, ErrorGuaranteed>> { - ty::EarlyBinder(self.collect_return_position_impl_trait_in_trait_tys(def_id)) - } - pub fn bound_explicit_item_bounds( self, def_id: DefId, diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 30477c7bd44..4ff72fee086 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -806,7 +806,9 @@ fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { } } -impl<'a, 'tcx> Decodable> for &'tcx FxHashMap> { +impl<'a, 'tcx> Decodable> + for &'tcx FxHashMap>> +{ fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self { RefDecodable::decode(d) } diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 826fc63ca06..5e042ffc603 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -2277,11 +2277,10 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( obligation.param_env, cause.clone(), obligation.recursion_depth + 1, - tcx.bound_return_position_impl_trait_in_trait_tys(impl_fn_def_id) - .map_bound(|tys| { - tys.map_or_else(|guar| tcx.ty_error(guar), |tys| tys[&obligation.predicate.def_id]) - }) - .subst(tcx, impl_fn_substs), + tcx.collect_return_position_impl_trait_in_trait_tys(impl_fn_def_id).map_or_else( + |guar| tcx.ty_error(guar), + |tys| tys[&obligation.predicate.def_id].subst(tcx, impl_fn_substs), + ), &mut obligations, );