Skip to content

Commit 9f0b16b

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#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`
2 parents f20da94 + 522bc5f commit 9f0b16b

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn compare_asyncness<'tcx>(
579579
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
580580
tcx: TyCtxt<'tcx>,
581581
impl_m_def_id: LocalDefId,
582-
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
582+
) -> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed> {
583583
let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap();
584584
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
585585
let impl_trait_ref =
@@ -782,14 +782,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
782782
})
783783
});
784784
debug!(%ty);
785-
collected_tys.insert(def_id, ty);
785+
collected_tys.insert(def_id, ty::EarlyBinder(ty));
786786
}
787787
Err(err) => {
788788
let reported = tcx.sess.delay_span_bug(
789789
return_span,
790790
format!("could not fully resolve: {ty} => {err:?}"),
791791
);
792-
collected_tys.insert(def_id, tcx.ty_error(reported));
792+
collected_tys.insert(def_id, ty::EarlyBinder(tcx.ty_error(reported)));
793793
}
794794
}
795795
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
251251
match tcx.collect_return_position_impl_trait_in_trait_tys(fn_def_id) {
252252
Ok(map) => {
253253
let assoc_item = tcx.associated_item(def_id);
254-
return ty::EarlyBinder(map[&assoc_item.trait_item_def_id.unwrap()]);
254+
return map[&assoc_item.trait_item_def_id.unwrap()];
255255
}
256256
Err(_) => {
257257
return ty::EarlyBinder(tcx.ty_error_with_message(

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ define_tables! {
416416
macro_definition: Table<DefIndex, LazyValue<ast::DelimArgs>>,
417417
proc_macro: Table<DefIndex, MacroKind>,
418418
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
419-
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
419+
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, ty::EarlyBinder<Ty<'static>>>>>,
420420
doc_link_resolutions: Table<DefIndex, LazyValue<DocLinkResMap>>,
421421
doc_link_traits_in_scope: Table<DefIndex, LazyArray<DefId>>,
422422
}

compiler/rustc_middle/src/arena.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ macro_rules! arena_types {
114114

115115
[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,
116116

117-
[decode] trait_impl_trait_tys: rustc_data_structures::fx::FxHashMap<rustc_hir::def_id::DefId, rustc_middle::ty::Ty<'tcx>>,
117+
[decode] trait_impl_trait_tys:
118+
rustc_data_structures::fx::FxHashMap<
119+
rustc_hir::def_id::DefId,
120+
rustc_middle::ty::EarlyBinder<rustc_middle::ty::Ty<'tcx>>
121+
>,
118122
[] bit_set_u32: rustc_index::bit_set::BitSet<u32>,
119123
[] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<'tcx>,
120124
[decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ rustc_queries! {
181181
}
182182

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

compiler/rustc_middle/src/ty/util.rs

-7
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,6 @@ impl<'tcx> TyCtxt<'tcx> {
694694
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
695695
}
696696

697-
pub fn bound_return_position_impl_trait_in_trait_tys(
698-
self,
699-
def_id: DefId,
700-
) -> ty::EarlyBinder<Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>> {
701-
ty::EarlyBinder(self.collect_return_position_impl_trait_in_trait_tys(def_id))
702-
}
703-
704697
pub fn bound_explicit_item_bounds(
705698
self,
706699
def_id: DefId,

compiler/rustc_query_impl/src/on_disk_cache.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,9 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx UnordSet<LocalDefId>
807807
}
808808
}
809809

810-
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashMap<DefId, Ty<'tcx>> {
810+
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
811+
for &'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>
812+
{
811813
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
812814
RefDecodable::decode(d)
813815
}

compiler/rustc_trait_selection/src/traits/project.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2277,11 +2277,10 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22772277
obligation.param_env,
22782278
cause.clone(),
22792279
obligation.recursion_depth + 1,
2280-
tcx.bound_return_position_impl_trait_in_trait_tys(impl_fn_def_id)
2281-
.map_bound(|tys| {
2282-
tys.map_or_else(|guar| tcx.ty_error(guar), |tys| tys[&obligation.predicate.def_id])
2283-
})
2284-
.subst(tcx, impl_fn_substs),
2280+
tcx.collect_return_position_impl_trait_in_trait_tys(impl_fn_def_id).map_or_else(
2281+
|guar| tcx.ty_error(guar),
2282+
|tys| tys[&obligation.predicate.def_id].subst(tcx, impl_fn_substs),
2283+
),
22852284
&mut obligations,
22862285
);
22872286

0 commit comments

Comments
 (0)