Skip to content

Commit 610bc68

Browse files
authored
Rollup merge of #110299 - kylematsuda:earlybinder-impl-subject, r=compiler-errors
Switch to `EarlyBinder` for `impl_subject` query Part of the work to finish #105779. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `impl_subject` query and removes `bound_impl_subject`. r? ```@lcnr```
2 parents a7889d1 + 8d5ee1a commit 610bc68

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

Diff for: compiler/rustc_middle/src/hir/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod nested_filter;
77
pub mod place;
88

99
use crate::ty::query::Providers;
10-
use crate::ty::{ImplSubject, TyCtxt};
10+
use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
1313
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -104,11 +104,11 @@ impl<'tcx> TyCtxt<'tcx> {
104104
self.parent_module_from_def_id(id.owner.def_id)
105105
}
106106

107-
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> {
108-
self.impl_trait_ref(def_id)
109-
.map(|t| t.subst_identity())
110-
.map(ImplSubject::Trait)
111-
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id).subst_identity()))
107+
pub fn impl_subject(self, def_id: DefId) -> EarlyBinder<ImplSubject<'tcx>> {
108+
match self.impl_trait_ref(def_id) {
109+
Some(t) => t.map_bound(ImplSubject::Trait),
110+
None => self.type_of(def_id).map_bound(ImplSubject::Inherent),
111+
}
112112
}
113113
}
114114

Diff for: compiler/rustc_middle/src/ty/util.rs

-4
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,6 @@ impl<'tcx> TyCtxt<'tcx> {
708708
ty::EarlyBinder(self.explicit_item_bounds(def_id))
709709
}
710710

711-
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
712-
ty::EarlyBinder(self.impl_subject(def_id))
713-
}
714-
715711
/// Returns names of captured upvars for closures and generators.
716712
///
717713
/// Here are some examples:

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn negative_impl(tcx: TyCtxt<'_>, impl1_def_id: DefId, impl2_def_id: DefId) -> b
306306
&infcx,
307307
ObligationCause::dummy(),
308308
impl_env,
309-
tcx.impl_subject(impl1_def_id),
309+
tcx.impl_subject(impl1_def_id).subst_identity(),
310310
) {
311311
Ok(s) => s,
312312
Err(err) => {

Diff for: compiler/rustc_trait_selection/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
198198
impl_def_id: DefId,
199199
impl_substs: SubstsRef<'tcx>,
200200
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
201-
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
201+
let subject = selcx.tcx().impl_subject(impl_def_id);
202202
let subject = subject.subst(selcx.tcx(), impl_substs);
203203

204204
let InferOk { value: subject, obligations: normalization_obligations1 } =

0 commit comments

Comments
 (0)