1
Fork 0

Rollup merge of #110299 - kylematsuda:earlybinder-impl-subject, r=compiler-errors

Switch to `EarlyBinder` for `impl_subject` query

Part of the work to finish https://github.com/rust-lang/rust/issues/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```
This commit is contained in:
Matthias Krüger 2023-04-14 07:58:42 +02:00 committed by GitHub
commit 610bc68675
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 12 deletions

View file

@ -7,7 +7,7 @@ pub mod nested_filter;
pub mod place; pub mod place;
use crate::ty::query::Providers; use crate::ty::query::Providers;
use crate::ty::{ImplSubject, TyCtxt}; use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
@ -104,11 +104,11 @@ impl<'tcx> TyCtxt<'tcx> {
self.parent_module_from_def_id(id.owner.def_id) self.parent_module_from_def_id(id.owner.def_id)
} }
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> { pub fn impl_subject(self, def_id: DefId) -> EarlyBinder<ImplSubject<'tcx>> {
self.impl_trait_ref(def_id) match self.impl_trait_ref(def_id) {
.map(|t| t.subst_identity()) Some(t) => t.map_bound(ImplSubject::Trait),
.map(ImplSubject::Trait) None => self.type_of(def_id).map_bound(ImplSubject::Inherent),
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id).subst_identity())) }
} }
} }

View file

@ -708,10 +708,6 @@ impl<'tcx> TyCtxt<'tcx> {
ty::EarlyBinder(self.explicit_item_bounds(def_id)) ty::EarlyBinder(self.explicit_item_bounds(def_id))
} }
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
ty::EarlyBinder(self.impl_subject(def_id))
}
/// Returns names of captured upvars for closures and generators. /// Returns names of captured upvars for closures and generators.
/// ///
/// Here are some examples: /// Here are some examples:

View file

@ -306,7 +306,7 @@ fn negative_impl(tcx: TyCtxt<'_>, impl1_def_id: DefId, impl2_def_id: DefId) -> b
&infcx, &infcx,
ObligationCause::dummy(), ObligationCause::dummy(),
impl_env, impl_env,
tcx.impl_subject(impl1_def_id), tcx.impl_subject(impl1_def_id).subst_identity(),
) { ) {
Ok(s) => s, Ok(s) => s,
Err(err) => { Err(err) => {

View file

@ -198,7 +198,7 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
impl_def_id: DefId, impl_def_id: DefId,
impl_substs: SubstsRef<'tcx>, impl_substs: SubstsRef<'tcx>,
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) { ) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
let subject = selcx.tcx().bound_impl_subject(impl_def_id); let subject = selcx.tcx().impl_subject(impl_def_id);
let subject = subject.subst(selcx.tcx(), impl_substs); let subject = subject.subst(selcx.tcx(), impl_substs);
let InferOk { value: subject, obligations: normalization_obligations1 } = let InferOk { value: subject, obligations: normalization_obligations1 } =