move Constness into TraitPredicate
This commit is contained in:
parent
04c9901a08
commit
32390a0df6
49 changed files with 157 additions and 124 deletions
|
@ -285,6 +285,7 @@ impl AutoTraitFinder<'tcx> {
|
|||
def_id: trait_did,
|
||||
substs: infcx.tcx.mk_substs_trait(ty, &[]),
|
||||
},
|
||||
constness: hir::Constness::NotConst,
|
||||
}));
|
||||
|
||||
let computed_preds = param_env.caller_bounds().iter();
|
||||
|
@ -344,10 +345,7 @@ impl AutoTraitFinder<'tcx> {
|
|||
Err(SelectionError::Unimplemented) => {
|
||||
if self.is_param_no_infer(pred.skip_binder().trait_ref.substs) {
|
||||
already_visited.remove(&pred);
|
||||
self.add_user_pred(
|
||||
&mut user_computed_preds,
|
||||
pred.without_const().to_predicate(self.tcx),
|
||||
);
|
||||
self.add_user_pred(&mut user_computed_preds, pred.to_predicate(self.tcx));
|
||||
predicates.push_back(pred);
|
||||
} else {
|
||||
debug!(
|
||||
|
@ -414,10 +412,8 @@ impl AutoTraitFinder<'tcx> {
|
|||
) {
|
||||
let mut should_add_new = true;
|
||||
user_computed_preds.retain(|&old_pred| {
|
||||
if let (
|
||||
ty::PredicateKind::Trait(new_trait, _),
|
||||
ty::PredicateKind::Trait(old_trait, _),
|
||||
) = (new_pred.kind().skip_binder(), old_pred.kind().skip_binder())
|
||||
if let (ty::PredicateKind::Trait(new_trait), ty::PredicateKind::Trait(old_trait)) =
|
||||
(new_pred.kind().skip_binder(), old_pred.kind().skip_binder())
|
||||
{
|
||||
if new_trait.def_id() == old_trait.def_id() {
|
||||
let new_substs = new_trait.trait_ref.substs;
|
||||
|
@ -638,7 +634,7 @@ impl AutoTraitFinder<'tcx> {
|
|||
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(p, _) => {
|
||||
ty::PredicateKind::Trait(p) => {
|
||||
// Add this to `predicates` so that we end up calling `select`
|
||||
// with it. If this predicate ends up being unimplemented,
|
||||
// then `evaluate_predicates` will handle adding it the `ParamEnv`
|
||||
|
|
|
@ -277,7 +277,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_predicate, _) => {
|
||||
ty::PredicateKind::Trait(trait_predicate) => {
|
||||
let trait_predicate = bound_predicate.rebind(trait_predicate);
|
||||
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
|
||||
|
||||
|
@ -518,8 +518,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
);
|
||||
trait_pred
|
||||
});
|
||||
let unit_obligation =
|
||||
obligation.with(predicate.without_const().to_predicate(tcx));
|
||||
let unit_obligation = obligation.with(predicate.to_predicate(tcx));
|
||||
if self.predicate_may_hold(&unit_obligation) {
|
||||
err.note("this trait is implemented for `()`.");
|
||||
err.note(
|
||||
|
@ -1148,7 +1147,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
|
||||
let bound_error = error.kind();
|
||||
let (cond, error) = match (cond.kind().skip_binder(), bound_error.skip_binder()) {
|
||||
(ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => {
|
||||
(ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error)) => {
|
||||
(cond, bound_error.rebind(error))
|
||||
}
|
||||
_ => {
|
||||
|
@ -1159,7 +1158,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
if let ty::PredicateKind::Trait(implication, _) = bound_predicate.skip_binder() {
|
||||
if let ty::PredicateKind::Trait(implication) = bound_predicate.skip_binder() {
|
||||
let error = error.to_poly_trait_ref();
|
||||
let implication = bound_predicate.rebind(implication.trait_ref);
|
||||
// FIXME: I'm just not taking associated types at all here.
|
||||
|
@ -1536,7 +1535,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
let bound_predicate = predicate.kind();
|
||||
let mut err = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(data, _) => {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
let trait_ref = bound_predicate.rebind(data.trait_ref);
|
||||
debug!("trait_ref {:?}", trait_ref);
|
||||
|
||||
|
@ -1803,7 +1802,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
match (obligation.predicate.kind().skip_binder(), obligation.cause.code.peel_derives())
|
||||
{
|
||||
(
|
||||
ty::PredicateKind::Trait(pred, _),
|
||||
ty::PredicateKind::Trait(pred),
|
||||
&ObligationCauseCode::BindingObligation(item_def_id, span),
|
||||
) => (pred, item_def_id, span),
|
||||
_ => return,
|
||||
|
|
|
@ -1386,7 +1386,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
// bound was introduced. At least one generator should be present for this diagnostic to be
|
||||
// modified.
|
||||
let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
|
||||
ty::PredicateKind::Trait(p) => (Some(p.trait_ref), Some(p.self_ty())),
|
||||
_ => (None, None),
|
||||
};
|
||||
let mut generator = None;
|
||||
|
|
|
@ -352,7 +352,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
// Evaluation will discard candidates using the leak check.
|
||||
// This means we need to pass it the bound version of our
|
||||
// predicate.
|
||||
ty::PredicateKind::Trait(trait_ref, _constness) => {
|
||||
ty::PredicateKind::Trait(trait_ref) => {
|
||||
let trait_obligation = obligation.with(binder.rebind(trait_ref));
|
||||
|
||||
self.process_trait_obligation(
|
||||
|
@ -388,7 +388,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
}
|
||||
},
|
||||
Some(pred) => match pred {
|
||||
ty::PredicateKind::Trait(data, _) => {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
let trait_obligation = obligation.with(Binder::dummy(data));
|
||||
|
||||
self.process_trait_obligation(
|
||||
|
|
|
@ -280,7 +280,7 @@ fn predicate_references_self(
|
|||
let self_ty = tcx.types.self_param;
|
||||
let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into());
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
ty::PredicateKind::Trait(ref data) => {
|
||||
// In the case of a trait predicate, we can skip the "self" type.
|
||||
if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
|||
let predicates = predicates.instantiate_identity(tcx).predicates;
|
||||
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
|
||||
match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ref trait_pred, _) => {
|
||||
ty::PredicateKind::Trait(ref trait_pred) => {
|
||||
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
|
||||
}
|
||||
ty::PredicateKind::Projection(..)
|
||||
|
|
|
@ -15,7 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
|
|||
// `&T`, accounts for about 60% percentage of the predicates
|
||||
// we have to prove. No need to canonicalize and all that for
|
||||
// such cases.
|
||||
if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Trait(trait_ref) = key.value.predicate.kind().skip_binder() {
|
||||
if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
|
||||
if trait_ref.def_id() == sized_def_id {
|
||||
if trait_ref.self_ty().is_trivially_sized(tcx) {
|
||||
|
|
|
@ -42,7 +42,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
|
|||
use rustc_middle::ty::relate::TypeRelation;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
|
||||
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
|
||||
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, WithConstness};
|
||||
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
@ -454,7 +454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let result = ensure_sufficient_stack(|| {
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(t, _) => {
|
||||
ty::PredicateKind::Trait(t) => {
|
||||
let t = bound_predicate.rebind(t);
|
||||
debug_assert!(!t.has_escaping_bound_vars());
|
||||
let obligation = obligation.with(t);
|
||||
|
@ -762,8 +762,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// if the regions match exactly.
|
||||
let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
|
||||
let tcx = self.tcx();
|
||||
let cycle =
|
||||
cycle.map(|stack| stack.obligation.predicate.without_const().to_predicate(tcx));
|
||||
let cycle = cycle.map(|stack| stack.obligation.predicate.to_predicate(tcx));
|
||||
if self.coinductive_match(cycle) {
|
||||
debug!("evaluate_stack --> recursive, coinductive");
|
||||
Some(EvaluatedToOk)
|
||||
|
@ -873,7 +872,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
|
||||
let result = match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
|
||||
ty::PredicateKind::Trait(ref data) => self.tcx().trait_is_auto(data.def_id()),
|
||||
_ => false,
|
||||
};
|
||||
debug!(?predicate, ?result, "coinductive_predicate");
|
||||
|
@ -1213,7 +1212,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
.enumerate()
|
||||
.filter_map(|(idx, bound)| {
|
||||
let bound_predicate = bound.kind();
|
||||
if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() {
|
||||
if let ty::PredicateKind::Trait(pred) = bound_predicate.skip_binder() {
|
||||
let bound = bound_predicate.rebind(pred.trait_ref);
|
||||
if self.infcx.probe(|_| {
|
||||
match self.match_normalize_trait_ref(
|
||||
|
|
|
@ -108,7 +108,7 @@ pub fn predicate_obligations<'a, 'tcx>(
|
|||
|
||||
// It's ok to skip the binder here because wf code is prepared for it
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(t, _) => {
|
||||
ty::PredicateKind::Trait(t) => {
|
||||
wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(..) => {}
|
||||
|
@ -226,7 +226,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Trait(pred, _) => {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
// An associated item obligation born out of the `trait` failed to be met. An example
|
||||
// can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
|
||||
debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue