Better names?
This commit is contained in:
parent
868aa42f4b
commit
84d254ead0
@ -102,8 +102,8 @@ fn check_def_id(&mut self, impl_def_id: LocalDefId, self_ty: Ty<'tcx>, ty_def_id
|
||||
if let Some(simp) = simplify_type(
|
||||
self.tcx,
|
||||
self_ty,
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id);
|
||||
} else {
|
||||
@ -164,9 +164,12 @@ fn check_primitive_impl(&mut self, impl_def_id: LocalDefId, ty: Ty<'tcx>) {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(simp) =
|
||||
simplify_type(self.tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate)
|
||||
{
|
||||
if let Some(simp) = simplify_type(
|
||||
self.tcx,
|
||||
ty,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id);
|
||||
} else {
|
||||
bug!("unexpected primitive type: {:?}", ty);
|
||||
|
@ -700,7 +700,7 @@ fn assemble_probe(&mut self, self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'t
|
||||
}
|
||||
|
||||
fn assemble_inherent_candidates_for_incoherent_ty(&mut self, self_ty: Ty<'tcx>) {
|
||||
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate) else {
|
||||
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey) else {
|
||||
bug!("unexpected incoherent type: {:?}", self_ty)
|
||||
};
|
||||
for &impl_def_id in self.tcx.incoherent_impls(simp) {
|
||||
|
@ -1258,7 +1258,7 @@ fn suggest_associated_call_syntax(
|
||||
let target_ty = self
|
||||
.autoderef(sugg_span, rcvr_ty)
|
||||
.find(|(rcvr_ty, _)| {
|
||||
DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }
|
||||
DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey }
|
||||
.types_may_unify(*rcvr_ty, impl_ty)
|
||||
})
|
||||
.map_or(impl_ty, |(ty, _)| ty)
|
||||
@ -1517,7 +1517,7 @@ fn suggest_constraining_numerical_ty(
|
||||
.into_iter()
|
||||
.any(|info| self.associated_value(info.def_id, item_name).is_some());
|
||||
let found_assoc = |ty: Ty<'tcx>| {
|
||||
simplify_type(tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate)
|
||||
simplify_type(tcx, ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey)
|
||||
.and_then(|simp| {
|
||||
tcx.incoherent_impls(simp)
|
||||
.iter()
|
||||
@ -2649,8 +2649,8 @@ enum Introducer {
|
||||
} else if let Some(simp_rcvr_ty) = simplify_type(
|
||||
self.tcx,
|
||||
rcvr_ty,
|
||||
TreatParams::AsPlaceholder,
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatParams::ForLookup,
|
||||
TreatProjections::ForLookup,
|
||||
) {
|
||||
let mut potential_candidates = Vec::new();
|
||||
let mut explicitly_negative = Vec::new();
|
||||
@ -2667,8 +2667,8 @@ enum Introducer {
|
||||
let imp_simp = simplify_type(
|
||||
self.tcx,
|
||||
imp.self_ty(),
|
||||
TreatParams::AsPlaceholder,
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatParams::ForLookup,
|
||||
TreatProjections::ForLookup,
|
||||
);
|
||||
imp_simp.map_or(false, |s| s == simp_rcvr_ty)
|
||||
})
|
||||
|
@ -1858,8 +1858,8 @@ fn encode_impls(&mut self) -> LazyArray<TraitImpls> {
|
||||
let simplified_self_ty = fast_reject::simplify_type(
|
||||
self.tcx,
|
||||
trait_ref.self_ty(),
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
);
|
||||
|
||||
fx_hash_map
|
||||
|
@ -51,9 +51,12 @@ pub enum SimplifiedType {
|
||||
/// generic parameters as if they were inference variables in that case.
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
pub enum TreatParams {
|
||||
/// Treat parameters as placeholders in the given environment.
|
||||
AsPlaceholder,
|
||||
AsInfer,
|
||||
/// Treat parameters as infer vars. This is the correct mode for caching
|
||||
/// an impl's type for lookup.
|
||||
AsCandidateKey,
|
||||
/// Treat parameters as placeholders in the given environment. This is the
|
||||
/// correct mode for *lookup*, as during candidate selection.
|
||||
ForLookup,
|
||||
}
|
||||
|
||||
/// During fast-rejection, we have the choice of treating projection types
|
||||
@ -67,13 +70,13 @@ pub enum TreatProjections {
|
||||
/// We must assume that the `impl<T> Trait<T> for <T as Id>::This`
|
||||
/// can apply to all self types so we don't return a simplified type
|
||||
/// for `<T as Id>::This`.
|
||||
DefaultCandidate,
|
||||
AsCandidateKey,
|
||||
/// In the old solver we don't try to normalize projections
|
||||
/// when looking up impls and only access them by using the
|
||||
/// current self type. This means that if the self type is
|
||||
/// a projection which could later be normalized, we must not
|
||||
/// treat it as rigid.
|
||||
DefaultLookup,
|
||||
ForLookup,
|
||||
/// We can treat projections in the self type as opaque as
|
||||
/// we separately look up impls for the normalized self type.
|
||||
NextSolverLookup,
|
||||
@ -133,13 +136,13 @@ pub fn simplify_type<'tcx>(
|
||||
ty::FnPtr(f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
|
||||
ty::Placeholder(..) => Some(PlaceholderSimplifiedType),
|
||||
ty::Param(_) => match treat_params {
|
||||
TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType),
|
||||
TreatParams::AsInfer => None,
|
||||
TreatParams::ForLookup => Some(PlaceholderSimplifiedType),
|
||||
TreatParams::AsCandidateKey => None,
|
||||
},
|
||||
ty::Alias(..) => match treat_projections {
|
||||
TreatProjections::DefaultLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType),
|
||||
TreatProjections::ForLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType),
|
||||
TreatProjections::NextSolverLookup => Some(PlaceholderSimplifiedType),
|
||||
TreatProjections::DefaultCandidate | TreatProjections::DefaultLookup => None,
|
||||
TreatProjections::AsCandidateKey | TreatProjections::ForLookup => None,
|
||||
},
|
||||
ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
|
||||
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
|
||||
@ -307,8 +310,8 @@ pub fn types_may_unify<'tcx>(self, obligation_ty: Ty<'tcx>, impl_ty: Ty<'tcx>) -
|
||||
// Depending on the value of `treat_obligation_params`, we either
|
||||
// treat generic parameters like placeholders or like inference variables.
|
||||
ty::Param(_) => match self.treat_obligation_params {
|
||||
TreatParams::AsPlaceholder => false,
|
||||
TreatParams::AsInfer => true,
|
||||
TreatParams::ForLookup => false,
|
||||
TreatParams::AsCandidateKey => true,
|
||||
},
|
||||
|
||||
ty::Infer(_) => true,
|
||||
@ -345,8 +348,8 @@ pub fn consts_may_unify(self, obligation_ct: ty::Const<'_>, impl_ct: ty::Const<'
|
||||
let k = impl_ct.kind();
|
||||
match obligation_ct.kind() {
|
||||
ty::ConstKind::Param(_) => match self.treat_obligation_params {
|
||||
TreatParams::AsPlaceholder => false,
|
||||
TreatParams::AsInfer => true,
|
||||
TreatParams::ForLookup => false,
|
||||
TreatParams::AsCandidateKey => true,
|
||||
},
|
||||
|
||||
// As we don't necessarily eagerly evaluate constants,
|
||||
|
@ -127,7 +127,7 @@ pub fn for_each_relevant_impl(
|
||||
self.for_each_relevant_impl_treating_projections(
|
||||
trait_def_id,
|
||||
self_ty,
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatProjections::ForLookup,
|
||||
f,
|
||||
)
|
||||
}
|
||||
@ -156,8 +156,8 @@ pub fn non_blanket_impls_for_ty(
|
||||
if let Some(simp) = fast_reject::simplify_type(
|
||||
self,
|
||||
self_ty,
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||
return impls.iter().copied();
|
||||
@ -196,7 +196,7 @@ pub fn find_map_relevant_impl<T>(
|
||||
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
|
||||
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
|
||||
if let Some(simp) =
|
||||
fast_reject::simplify_type(self, self_ty, TreatParams::AsPlaceholder, treat_projections)
|
||||
fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup, treat_projections)
|
||||
{
|
||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||
for &impl_def_id in impls {
|
||||
@ -261,8 +261,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
|
||||
if let Some(simplified_self_ty) = fast_reject::simplify_type(
|
||||
tcx,
|
||||
impl_self_ty,
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id);
|
||||
} else {
|
||||
|
@ -368,7 +368,7 @@ pub fn calculate_dtor(
|
||||
drop_trait,
|
||||
ty,
|
||||
// FIXME: This could also be some other mode, like "unexpected"
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatProjections::ForLookup,
|
||||
|impl_did| {
|
||||
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
|
||||
if validate(self, impl_did).is_ok() {
|
||||
|
@ -2215,7 +2215,7 @@ fn check_proc_macro(&self, hir_id: HirId, target: Target, kind: ProcMacroKind) {
|
||||
// `fn(TokenStream) -> TokenStream` after some substitution of generic arguments.
|
||||
//
|
||||
// Properly checking this means pulling in additional `rustc` crates, so we don't.
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey };
|
||||
|
||||
if sig.abi != Abi::Rust {
|
||||
tcx.sess.emit_err(errors::ProcMacroInvalidAbi {
|
||||
|
@ -184,7 +184,7 @@ fn consider_impl_candidate(
|
||||
|
||||
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
|
||||
if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
||||
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ fn consider_impl_candidate(
|
||||
let tcx = ecx.tcx();
|
||||
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
|
||||
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
||||
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ pub fn overlapping_impls(
|
||||
// Before doing expensive operations like entering an inference context, do
|
||||
// a quick check via fast_reject to tell if the impl headers could possibly
|
||||
// unify.
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey };
|
||||
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
|
||||
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
|
||||
let may_overlap = match (impl1_ref, impl2_ref) {
|
||||
|
@ -1803,7 +1803,7 @@ fn report_projection_error(
|
||||
self.tcx.find_map_relevant_impl(
|
||||
id,
|
||||
proj.projection_ty.self_ty(),
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatProjections::ForLookup,
|
||||
|did| {
|
||||
self.tcx
|
||||
.associated_items(did)
|
||||
@ -2185,7 +2185,7 @@ fn note_version_mismatch(
|
||||
self.tcx.find_map_relevant_impl(
|
||||
trait_def_id,
|
||||
trait_ref.skip_binder().self_ty(),
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatProjections::ForLookup,
|
||||
Some,
|
||||
)
|
||||
};
|
||||
|
@ -784,7 +784,7 @@ fn assemble_const_destruct_candidates(
|
||||
let relevant_impl = self.tcx().find_map_relevant_impl(
|
||||
self.tcx().require_lang_item(LangItem::Drop, None),
|
||||
obligation.predicate.skip_binder().trait_ref.self_ty(),
|
||||
TreatProjections::DefaultLookup,
|
||||
TreatProjections::ForLookup,
|
||||
Some,
|
||||
);
|
||||
|
||||
|
@ -2558,7 +2558,7 @@ fn fast_reject_trait_refs(
|
||||
// We can avoid creating type variables and doing the full
|
||||
// substitution if we find that any of the input types, when
|
||||
// simplified, do not match.
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
|
||||
iter::zip(obligation.predicate.skip_binder().trait_ref.substs, impl_trait_ref.substs)
|
||||
.any(|(obl, imp)| !drcx.generic_args_may_unify(obl, imp))
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
||||
if let Some(st) = fast_reject::simplify_type(
|
||||
tcx,
|
||||
trait_ref.self_ty(),
|
||||
TreatParams::AsInfer,
|
||||
fast_reject::TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
|
||||
self.non_blanket_impls.entry(st).or_default().push(impl_def_id)
|
||||
@ -72,8 +72,8 @@ fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
||||
if let Some(st) = fast_reject::simplify_type(
|
||||
tcx,
|
||||
trait_ref.self_ty(),
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
) {
|
||||
debug!("remove_existing: impl_def_id={:?} st={:?}", impl_def_id, st);
|
||||
vec = self.non_blanket_impls.get_mut(&st).unwrap();
|
||||
@ -313,8 +313,8 @@ fn insert(
|
||||
let simplified = fast_reject::simplify_type(
|
||||
tcx,
|
||||
trait_ref.self_ty(),
|
||||
TreatParams::AsInfer,
|
||||
TreatProjections::DefaultCandidate,
|
||||
TreatParams::AsCandidateKey,
|
||||
TreatProjections::AsCandidateKey,
|
||||
);
|
||||
|
||||
// Descend the specialization tree, where `parent` is the current parent node.
|
||||
|
@ -735,7 +735,7 @@ fn trait_impls_for<'a>(
|
||||
trace!("considering explicit impl for trait {:?}", trait_);
|
||||
|
||||
// Look at each trait implementation to see if it's an impl for `did`
|
||||
tcx.find_map_relevant_impl(trait_, ty, TreatProjections::DefaultLookup, |impl_| {
|
||||
tcx.find_map_relevant_impl(trait_, ty, TreatProjections::ForLookup, |impl_| {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
|
||||
// Check if these are the same type.
|
||||
let impl_type = trait_ref.skip_binder().self_ty();
|
||||
|
Loading…
Reference in New Issue
Block a user