mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #104846 - spastorino:santa-clauses-make-goals-early-christmas-🎄, r=oli-obk
Branch Clause from Predicate r? `@oli-obk` This is part of what's proposed in https://github.com/rust-lang/compiler-team/issues/531
This commit is contained in:
commit
051cab2b84
@ -666,15 +666,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
// Find out if the predicates show that the type is a Fn or FnMut
|
||||
let find_fn_kind_from_did =
|
||||
|predicates: ty::EarlyBinder<&[(ty::Predicate<'tcx>, Span)]>, substs| {
|
||||
predicates.0.iter().find_map(|(pred, _)| {
|
||||
let find_fn_kind_from_did = |predicates: ty::EarlyBinder<
|
||||
&[(ty::Predicate<'tcx>, Span)],
|
||||
>,
|
||||
substs| {
|
||||
predicates.0.iter().find_map(|(pred, _)| {
|
||||
let pred = if let Some(substs) = substs {
|
||||
predicates.rebind(*pred).subst(tcx, substs).kind().skip_binder()
|
||||
} else {
|
||||
pred.kind().skip_binder()
|
||||
};
|
||||
if let ty::PredicateKind::Trait(pred) = pred && pred.self_ty() == ty {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred && pred.self_ty() == ty {
|
||||
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
|
||||
return Some(hir::Mutability::Not);
|
||||
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
|
||||
@ -683,7 +685,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
None
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
|
||||
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
|
||||
@ -784,13 +786,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let predicates: Result<Vec<_>, _> = errors
|
||||
.into_iter()
|
||||
.map(|err| match err.obligation.predicate.kind().skip_binder() {
|
||||
PredicateKind::Trait(predicate) => match predicate.self_ty().kind() {
|
||||
ty::Param(param_ty) => Ok((
|
||||
generics.type_param(param_ty, tcx),
|
||||
predicate.trait_ref.print_only_trait_path().to_string(),
|
||||
)),
|
||||
_ => Err(()),
|
||||
},
|
||||
PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
|
||||
match predicate.self_ty().kind() {
|
||||
ty::Param(param_ty) => Ok((
|
||||
generics.type_param(param_ty, tcx),
|
||||
predicate.trait_ref.print_only_trait_path().to_string(),
|
||||
)),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
_ => Err(()),
|
||||
})
|
||||
.collect();
|
||||
|
@ -959,8 +959,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
{
|
||||
predicates.iter().any(|pred| {
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(data) if data.self_ty() == ty => {}
|
||||
ty::PredicateKind::Projection(data) if data.projection_ty.self_ty() == ty => {}
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) if data.self_ty() == ty => {}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data)) if data.projection_ty.self_ty() == ty => {}
|
||||
_ => return false,
|
||||
}
|
||||
tcx.any_free_region_meets(pred, |r| {
|
||||
|
@ -88,11 +88,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
category: ConstraintCategory<'tcx>,
|
||||
) {
|
||||
self.prove_predicate(
|
||||
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
})),
|
||||
}))),
|
||||
locations,
|
||||
category,
|
||||
);
|
||||
|
@ -2013,8 +2013,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
);
|
||||
|
||||
let outlives_predicate =
|
||||
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::TypeOutlives(
|
||||
ty::OutlivesPredicate(self_ty, *region),
|
||||
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::Clause::TypeOutlives(ty::OutlivesPredicate(self_ty, *region)),
|
||||
)));
|
||||
self.prove_predicate(
|
||||
outlives_predicate,
|
||||
|
@ -10,7 +10,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
|
||||
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef, TypeVisitable};
|
||||
use rustc_middle::ty::{Binder, TraitRef, TypeVisitable};
|
||||
use rustc_mir_dataflow::{self, Analysis};
|
||||
use rustc_span::{sym, Span, Symbol};
|
||||
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
|
||||
@ -735,11 +735,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||
}
|
||||
|
||||
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
|
||||
let poly_trait_pred = Binder::dummy(TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
});
|
||||
let poly_trait_pred =
|
||||
Binder::dummy(trait_ref).with_constness(ty::BoundConstness::ConstIfConst);
|
||||
let obligation =
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
|
||||
|
||||
@ -828,9 +825,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||
tcx,
|
||||
ObligationCause::dummy_with_span(*fn_span),
|
||||
param_env,
|
||||
tcx.mk_predicate(
|
||||
poly_trait_pred.map_bound(ty::PredicateKind::Trait),
|
||||
),
|
||||
poly_trait_pred,
|
||||
);
|
||||
|
||||
// improve diagnostics by showing what failed. Our requirements are stricter this time
|
||||
|
@ -13,10 +13,9 @@ use rustc_middle::mir;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{
|
||||
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, TraitPredicate,
|
||||
Ty,
|
||||
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty,
|
||||
};
|
||||
use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef};
|
||||
use rustc_middle::ty::{Binder, TraitRef};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{BytePos, Pos, Span, Symbol};
|
||||
@ -150,11 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||
tcx,
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
Binder::dummy(TraitPredicate {
|
||||
trait_ref,
|
||||
constness: BoundConstness::NotConst,
|
||||
polarity: ImplPolarity::Positive,
|
||||
}),
|
||||
Binder::dummy(trait_ref),
|
||||
);
|
||||
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
|
@ -157,11 +157,8 @@ impl Qualif for NeedsNonConstDrop {
|
||||
cx.tcx,
|
||||
ObligationCause::dummy_with_span(cx.body.span),
|
||||
cx.param_env,
|
||||
ty::Binder::dummy(ty::TraitPredicate {
|
||||
trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]),
|
||||
constness: ty::BoundConstness::ConstIfConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
}),
|
||||
ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]))
|
||||
.with_constness(ty::BoundConstness::ConstIfConst),
|
||||
);
|
||||
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
|
@ -1378,7 +1378,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
let pred = bound_predicate.rebind(pred);
|
||||
associated_types.entry(span).or_default().extend(
|
||||
tcx.associated_items(pred.def_id())
|
||||
@ -1387,7 +1387,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
.map(|item| item.def_id),
|
||||
);
|
||||
}
|
||||
ty::PredicateKind::Projection(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
|
||||
let pred = bound_predicate.rebind(pred);
|
||||
// A `Self` within the original bound will be substituted with a
|
||||
// `trait_object_dummy_self`, so check for that.
|
||||
|
@ -183,19 +183,27 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
||||
let predicate = predicate.kind();
|
||||
let p = p.kind();
|
||||
match (predicate.skip_binder(), p.skip_binder()) {
|
||||
(ty::PredicateKind::Trait(a), ty::PredicateKind::Trait(b)) => {
|
||||
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
|
||||
}
|
||||
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
|
||||
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
|
||||
}
|
||||
(
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(a)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(b)),
|
||||
) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(),
|
||||
(
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(a)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(b)),
|
||||
) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(),
|
||||
(
|
||||
ty::PredicateKind::ConstEvaluatable(a),
|
||||
ty::PredicateKind::ConstEvaluatable(b),
|
||||
) => relator.relate(predicate.rebind(a), predicate.rebind(b)).is_ok(),
|
||||
(
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, lt_a)),
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_b, lt_b)),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty_a,
|
||||
lt_a,
|
||||
))),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty_b,
|
||||
lt_b,
|
||||
))),
|
||||
) => {
|
||||
relator.relate(predicate.rebind(ty_a), p.rebind(ty_b)).is_ok()
|
||||
&& relator.relate(predicate.rebind(lt_a), p.rebind(lt_b)).is_ok()
|
||||
|
@ -309,7 +309,7 @@ fn bounds_from_generic_predicates<'tcx>(
|
||||
debug!("predicate {:?}", predicate);
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
|
||||
let entry = types.entry(trait_predicate.self_ty()).or_default();
|
||||
let def_id = trait_predicate.def_id();
|
||||
if Some(def_id) != tcx.lang_items().sized_trait() {
|
||||
@ -318,7 +318,7 @@ fn bounds_from_generic_predicates<'tcx>(
|
||||
entry.push(trait_predicate.def_id());
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Projection(projection_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(projection_pred)) => {
|
||||
projections.push(bound_predicate.rebind(projection_pred));
|
||||
}
|
||||
_ => {}
|
||||
|
@ -462,12 +462,16 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
||||
let mut unsatisfied_bounds: Vec<_> = required_bounds
|
||||
.into_iter()
|
||||
.filter(|clause| match clause.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => {
|
||||
!region_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
!ty_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => !ty_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b),
|
||||
_ => bug!("Unexpected PredicateKind"),
|
||||
})
|
||||
.map(|clause| clause.to_string())
|
||||
@ -599,8 +603,9 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
||||
}));
|
||||
// The predicate we expect to see. (In our example,
|
||||
// `Self: 'me`.)
|
||||
let clause =
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param));
|
||||
let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty_param, region_param),
|
||||
));
|
||||
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
|
||||
bounds.insert(clause);
|
||||
}
|
||||
@ -636,9 +641,8 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
||||
name: region_b_param.name,
|
||||
}));
|
||||
// The predicate we expect to see.
|
||||
let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
region_a_param,
|
||||
region_b_param,
|
||||
let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(region_a_param, region_b_param),
|
||||
));
|
||||
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
|
||||
bounds.insert(clause);
|
||||
@ -1784,7 +1788,7 @@ fn receiver_is_implemented<'tcx>(
|
||||
let tcx = wfcx.tcx();
|
||||
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
|
||||
|
||||
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
|
||||
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref);
|
||||
|
||||
if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
|
||||
true
|
||||
|
@ -128,11 +128,11 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
||||
.or_default()
|
||||
.push(error.obligation.cause.span);
|
||||
}
|
||||
if let ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
..
|
||||
}) = error_predicate.kind().skip_binder()
|
||||
})) = error_predicate.kind().skip_binder()
|
||||
{
|
||||
let ty = trait_ref.self_ty();
|
||||
if let ty::Param(_) = ty.kind() {
|
||||
|
@ -35,9 +35,11 @@ fn associated_type_bounds<'tcx>(
|
||||
|
||||
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(tr) => tr.self_ty() == item_ty,
|
||||
ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
|
||||
ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(tr)) => tr.self_ty() == item_ty,
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => {
|
||||
proj.projection_ty.self_ty() == item_ty
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(outlives)) => outlives.0 == item_ty,
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
|
@ -1558,7 +1558,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
|
||||
let bound_predicate = pred.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
|
||||
// The order here needs to match what we would get from `subst_supertrait`
|
||||
let pred_bound_vars = bound_predicate.bound_vars();
|
||||
let mut all_bound_vars = bound_vars.clone();
|
||||
|
@ -233,8 +233,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||
}
|
||||
_ => bug!(),
|
||||
};
|
||||
let pred = ty::Binder::dummy(ty::PredicateKind::RegionOutlives(
|
||||
ty::OutlivesPredicate(r1, r2),
|
||||
let pred = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
|
||||
))
|
||||
.to_predicate(icx.tcx);
|
||||
|
||||
@ -299,17 +299,15 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||
name: duplicate.name.ident().name,
|
||||
}));
|
||||
predicates.push((
|
||||
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
orig_region,
|
||||
dup_region,
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(orig_region, dup_region),
|
||||
)))
|
||||
.to_predicate(icx.tcx),
|
||||
duplicate.span,
|
||||
));
|
||||
predicates.push((
|
||||
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
dup_region,
|
||||
orig_region,
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(dup_region, orig_region),
|
||||
)))
|
||||
.to_predicate(icx.tcx),
|
||||
duplicate.span,
|
||||
@ -426,11 +424,13 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
|
||||
ty::PredicateKind::Projection(proj) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(tr)) => !is_assoc_item_ty(tr.self_ty()),
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => {
|
||||
!is_assoc_item_ty(proj.projection_ty.self_ty())
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(outlives)) => {
|
||||
!is_assoc_item_ty(outlives.0)
|
||||
}
|
||||
_ => true,
|
||||
})
|
||||
.collect();
|
||||
@ -566,7 +566,9 @@ pub(super) fn super_predicates_that_define_assoc_type(
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
for &(pred, span) in superbounds {
|
||||
debug!("superbound: {:?}", pred);
|
||||
if let ty::PredicateKind::Trait(bound) = pred.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) =
|
||||
pred.kind().skip_binder()
|
||||
{
|
||||
tcx.at(span).super_predicates_of(bound.def_id());
|
||||
}
|
||||
}
|
||||
@ -666,7 +668,7 @@ pub(super) fn type_param_predicates(
|
||||
)
|
||||
.into_iter()
|
||||
.filter(|(predicate, _)| match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(data) => data.self_ty().is_param(index),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => data.self_ty().is_param(index),
|
||||
_ => false,
|
||||
}),
|
||||
);
|
||||
|
@ -187,7 +187,8 @@ pub fn setup_constraining_predicates<'tcx>(
|
||||
for j in i..predicates.len() {
|
||||
// Note that we don't have to care about binders here,
|
||||
// as the impl trait ref never contains any late-bound regions.
|
||||
if let ty::PredicateKind::Projection(projection) = predicates[j].0.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(projection)) =
|
||||
predicates[j].0.kind().skip_binder()
|
||||
{
|
||||
// Special case: watch out for some kind of sneaky attempt
|
||||
// to project out an associated type defined by this very
|
||||
|
@ -214,7 +214,9 @@ fn unconstrained_parent_impl_substs<'tcx>(
|
||||
// the functions in `cgp` add the constrained parameters to a list of
|
||||
// unconstrained parameters.
|
||||
for (predicate, _) in impl_generic_predicates.predicates.iter() {
|
||||
if let ty::PredicateKind::Projection(proj) = predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) =
|
||||
predicate.kind().skip_binder()
|
||||
{
|
||||
let projection_ty = proj.projection_ty;
|
||||
let projected_ty = proj.term;
|
||||
|
||||
@ -429,7 +431,10 @@ fn trait_predicates_eq<'tcx>(
|
||||
let pred1_kind = predicate1.kind().skip_binder();
|
||||
let pred2_kind = predicate2.kind().skip_binder();
|
||||
let (trait_pred1, trait_pred2) = match (pred1_kind, pred2_kind) {
|
||||
(ty::PredicateKind::Trait(pred1), ty::PredicateKind::Trait(pred2)) => (pred1, pred2),
|
||||
(
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred1)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred2)),
|
||||
) => (pred1, pred2),
|
||||
// Just use plain syntactic equivalence if either of the predicates aren't
|
||||
// trait predicates or have bound vars.
|
||||
_ => return predicate1 == predicate2,
|
||||
@ -467,7 +472,11 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
||||
_ if predicate.is_global() => (),
|
||||
// We allow specializing on explicitly marked traits with no associated
|
||||
// items.
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, constness: _, polarity: _ }) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
})) => {
|
||||
if !matches!(
|
||||
trait_predicate_kind(tcx, predicate),
|
||||
Some(TraitSpecializationKind::Marker)
|
||||
@ -483,7 +492,10 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
||||
projection_ty,
|
||||
term,
|
||||
})) => {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
@ -504,12 +516,14 @@ fn trait_predicate_kind<'tcx>(
|
||||
predicate: ty::Predicate<'tcx>,
|
||||
) -> Option<TraitSpecializationKind> {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, constness: _, polarity: _ }) => {
|
||||
Some(tcx.trait_def(trait_ref.def_id).specialization_kind)
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(_)
|
||||
| ty::PredicateKind::TypeOutlives(_)
|
||||
| ty::PredicateKind::Projection(_)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
})) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind),
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::Subtype(_)
|
||||
| ty::PredicateKind::Coerce(_)
|
||||
|
@ -30,28 +30,30 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
|
||||
// process predicates and convert to `RequiredPredicates` entry, see below
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::TypeOutlives(OutlivesPredicate(ty, reg)) => {
|
||||
insert_outlives_predicate(
|
||||
tcx,
|
||||
ty.into(),
|
||||
reg,
|
||||
span,
|
||||
&mut required_predicates,
|
||||
)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(OutlivesPredicate(
|
||||
ty,
|
||||
reg,
|
||||
))) => insert_outlives_predicate(
|
||||
tcx,
|
||||
ty.into(),
|
||||
reg,
|
||||
span,
|
||||
&mut required_predicates,
|
||||
),
|
||||
|
||||
ty::PredicateKind::RegionOutlives(OutlivesPredicate(reg1, reg2)) => {
|
||||
insert_outlives_predicate(
|
||||
tcx,
|
||||
reg1.into(),
|
||||
reg2,
|
||||
span,
|
||||
&mut required_predicates,
|
||||
)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(OutlivesPredicate(
|
||||
reg1,
|
||||
reg2,
|
||||
))) => insert_outlives_predicate(
|
||||
tcx,
|
||||
reg1.into(),
|
||||
reg2,
|
||||
span,
|
||||
&mut required_predicates,
|
||||
),
|
||||
|
||||
ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
|
@ -51,8 +51,10 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
|
||||
let mut pred: Vec<String> = predicates
|
||||
.iter()
|
||||
.map(|(out_pred, _)| match out_pred.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(p) => p.to_string(),
|
||||
ty::PredicateKind::TypeOutlives(p) => p.to_string(),
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(p)) => {
|
||||
p.to_string()
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(p)) => p.to_string(),
|
||||
err => bug!("unexpected predicate {:?}", err),
|
||||
})
|
||||
.collect();
|
||||
@ -101,15 +103,17 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||
match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty1, *region2),
|
||||
))
|
||||
)))
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(
|
||||
ty::OutlivesPredicate(region1, *region2),
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
region1, *region2,
|
||||
)),
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
|
@ -123,25 +123,28 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||
// which thus mentions `'a` and should thus accept hidden types that borrow 'a
|
||||
// instead of requiring an additional `+ 'a`.
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef { def_id: _, substs },
|
||||
constness: _,
|
||||
polarity: _,
|
||||
}) => {
|
||||
})) => {
|
||||
for subst in &substs[1..] {
|
||||
subst.visit_with(&mut collector);
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
||||
projection_ty: ty::ProjectionTy { substs, item_def_id: _ },
|
||||
term,
|
||||
}) => {
|
||||
})) => {
|
||||
for subst in &substs[1..] {
|
||||
subst.visit_with(&mut collector);
|
||||
}
|
||||
term.visit_with(&mut collector);
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, region)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
_,
|
||||
region,
|
||||
))) => {
|
||||
region.visit_with(&mut collector);
|
||||
}
|
||||
_ => {
|
||||
|
@ -539,17 +539,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.subst_iter_copied(self.tcx, substs)
|
||||
{
|
||||
let pred = pred.kind().rebind(match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
|
||||
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
|
||||
ty::PredicateKind::Trait(trait_pred.with_self_type(self.tcx, ty))
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
trait_pred.with_self_type(self.tcx, ty),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Projection(mut proj_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
|
||||
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
|
||||
proj_pred.projection_ty.substs = self.tcx.mk_substs_trait(
|
||||
ty,
|
||||
proj_pred.projection_ty.substs.iter().skip(1),
|
||||
);
|
||||
ty::PredicateKind::Projection(proj_pred)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
|
||||
}
|
||||
_ => continue,
|
||||
});
|
||||
|
@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// Given a Projection predicate, we can potentially infer
|
||||
// the complete signature.
|
||||
if expected_sig.is_none()
|
||||
&& let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder()
|
||||
&& let ty::PredicateKind::Clause(ty::Clause::Projection(proj_predicate)) = bound_predicate.skip_binder()
|
||||
{
|
||||
expected_sig = self.normalize_associated_types_in(
|
||||
obligation.cause.span,
|
||||
@ -228,10 +228,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// like `F : Fn<A>`. Note that due to subtyping we could encounter
|
||||
// many viable options, so pick the most restrictive.
|
||||
let trait_def_id = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Projection(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
|
||||
Some(data.projection_ty.trait_def_id(self.tcx))
|
||||
}
|
||||
ty::PredicateKind::Trait(data) => Some(data.def_id()),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => Some(data.def_id()),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(closure_kind) =
|
||||
@ -658,7 +658,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// where R is the return type we are expecting. This type `T`
|
||||
// will be our output.
|
||||
let bound_predicate = predicate.kind();
|
||||
if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj_predicate)) =
|
||||
bound_predicate.skip_binder()
|
||||
{
|
||||
self.deduce_future_output_from_projection(
|
||||
span,
|
||||
bound_predicate.rebind(proj_predicate),
|
||||
|
@ -644,7 +644,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
debug!("coerce_unsized resolve step: {:?}", obligation);
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
let trait_pred = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_pred) if traits.contains(&trait_pred.def_id()) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
|
||||
if traits.contains(&trait_pred.def_id()) =>
|
||||
{
|
||||
if unsize_did == trait_pred.def_id() {
|
||||
let self_ty = trait_pred.self_ty();
|
||||
let unsize_ty = trait_pred.trait_ref.substs[1].expect_ty();
|
||||
@ -778,8 +780,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
self.tcx,
|
||||
self.cause.clone(),
|
||||
self.param_env,
|
||||
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
a, b_region,
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(a, b_region),
|
||||
))),
|
||||
),
|
||||
])
|
||||
@ -792,8 +794,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
self.param_env,
|
||||
ty::Binder::dummy(
|
||||
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
|
||||
)
|
||||
.to_poly_trait_predicate(),
|
||||
),
|
||||
));
|
||||
|
||||
Ok(InferOk {
|
||||
|
@ -2824,7 +2824,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
) {
|
||||
for error in errors {
|
||||
match error.obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(predicate)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(predicate))
|
||||
if self.tcx.is_diagnostic_item(sym::SliceIndex, predicate.trait_ref.def_id) => {
|
||||
}
|
||||
_ => continue,
|
||||
|
@ -669,7 +669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
self.fulfillment_cx.borrow().pending_obligations().into_iter().filter_map(
|
||||
move |obligation| match &obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Projection(data)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data))
|
||||
if self.self_type_matches_expected_vid(
|
||||
data.projection_ty.self_ty(),
|
||||
ty_var_root,
|
||||
@ -677,18 +677,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
{
|
||||
Some(obligation)
|
||||
}
|
||||
ty::PredicateKind::Trait(data)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data))
|
||||
if self.self_type_matches_expected_vid(data.self_ty(), ty_var_root) =>
|
||||
{
|
||||
Some(obligation)
|
||||
}
|
||||
|
||||
ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
@ -712,7 +712,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let sized_did = self.tcx.lang_items().sized_trait();
|
||||
self.obligations_for_self_ty(self_ty).any(|obligation| {
|
||||
match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(data) => Some(data.def_id()) == sized_did,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
|
||||
Some(data.def_id()) == sized_did
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
|
@ -1740,8 +1740,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
let generics = self.tcx.generics_of(def_id);
|
||||
let predicate_substs = match unsubstituted_pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => pred.trait_ref.substs,
|
||||
ty::PredicateKind::Projection(pred) => pred.projection_ty.substs,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => pred.trait_ref.substs,
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => pred.projection_ty.substs,
|
||||
_ => ty::List::empty(),
|
||||
};
|
||||
|
||||
@ -2113,7 +2113,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
for (predicate, span) in
|
||||
std::iter::zip(instantiated.predicates, instantiated.spans)
|
||||
{
|
||||
if let ty::PredicateKind::Trait(pred) = predicate.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = predicate.kind().skip_binder()
|
||||
&& pred.self_ty().peel_refs() == callee_ty
|
||||
&& ty::ClosureKind::from_def_id(self.tcx, pred.def_id()).is_some()
|
||||
{
|
||||
@ -2149,11 +2149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.tcx,
|
||||
traits::ObligationCause::dummy(),
|
||||
self.param_env,
|
||||
ty::Binder::dummy(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
}),
|
||||
ty::Binder::dummy(trait_ref),
|
||||
);
|
||||
match SelectionContext::new(&self).select(&obligation) {
|
||||
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
|
||||
|
@ -201,7 +201,9 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||
predicates: tcx.arena.alloc_from_iter(
|
||||
self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(data) if data.self_ty().is_param(index) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data))
|
||||
if data.self_ty().is_param(index) =>
|
||||
{
|
||||
// HACK(eddyb) should get the original `Span`.
|
||||
let span = tcx.def_span(def_id);
|
||||
Some((predicate, span))
|
||||
|
@ -173,7 +173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
ty::Opaque(def_id, substs) => {
|
||||
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
||||
if let ty::PredicateKind::Projection(proj) = pred.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output()
|
||||
// args tuple will always be substs[1]
|
||||
&& let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind()
|
||||
@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty::Param(param) => {
|
||||
let def_id = self.tcx.generics_of(self.body_id.owner).type_param(¶m, self.tcx).def_id;
|
||||
self.tcx.predicates_of(self.body_id.owner).predicates.iter().find_map(|(pred, _)| {
|
||||
if let ty::PredicateKind::Projection(proj) = pred.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output()
|
||||
&& proj.projection_ty.self_ty() == found
|
||||
// args tuple will always be substs[1]
|
||||
@ -1096,8 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty::Binder::dummy(self.tcx.mk_trait_ref(
|
||||
into_def_id,
|
||||
[expr_ty, expected_ty]
|
||||
))
|
||||
.to_poly_trait_predicate(),
|
||||
)),
|
||||
))
|
||||
{
|
||||
let sugg = if expr.precedence().order() >= PREC_POSTFIX {
|
||||
|
@ -566,7 +566,7 @@ fn check_must_not_suspend_ty<'tcx>(
|
||||
let mut has_emitted = false;
|
||||
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate) =
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(ref poly_trait_predicate)) =
|
||||
predicate.kind().skip_binder()
|
||||
{
|
||||
let def_id = poly_trait_predicate.trait_ref.def_id;
|
||||
|
@ -531,7 +531,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
|
||||
// We don't care about regions here.
|
||||
.filter_map(|obligation| match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
|
||||
if trait_pred.def_id() == sized_def_id =>
|
||||
{
|
||||
let span = iter::zip(&predicates.predicates, &predicates.spans)
|
||||
.find_map(
|
||||
|(p, span)| {
|
||||
|
@ -348,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
},
|
||||
),
|
||||
self.param_env,
|
||||
poly_trait_ref.without_const(),
|
||||
poly_trait_ref,
|
||||
),
|
||||
substs,
|
||||
)
|
||||
|
@ -785,7 +785,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
|
||||
match *trait_predicate.trait_ref.self_ty().kind() {
|
||||
ty::Param(p) if p == param_ty => {
|
||||
Some(bound_predicate.rebind(trait_predicate.trait_ref))
|
||||
@ -795,12 +795,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
}
|
||||
ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Ambiguous
|
||||
@ -1430,7 +1430,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
|
||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate();
|
||||
let predicate = ty::Binder::dummy(trait_ref);
|
||||
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
|
||||
traits::SelectionContext::new(self).select(&obligation)
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut unimplemented_traits = FxHashMap::default();
|
||||
let mut unimplemented_traits_only = true;
|
||||
for (predicate, _parent_pred, cause) in &unsatisfied_predicates {
|
||||
if let (ty::PredicateKind::Trait(p), Some(cause)) =
|
||||
if let (ty::PredicateKind::Clause(ty::Clause::Trait(p)), Some(cause)) =
|
||||
(predicate.kind().skip_binder(), cause.as_ref())
|
||||
{
|
||||
if p.trait_ref.self_ty() != rcvr_ty {
|
||||
@ -469,7 +469,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// because of some non-Clone item being iterated over.
|
||||
for (predicate, _parent_pred, _cause) in &unsatisfied_predicates {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(p)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(p))
|
||||
if unimplemented_traits.contains_key(&p.trait_ref.def_id) => {}
|
||||
_ => {
|
||||
unimplemented_traits_only = false;
|
||||
@ -481,7 +481,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut collect_type_param_suggestions =
|
||||
|self_ty: Ty<'tcx>, parent_pred: ty::Predicate<'tcx>, obligation: &str| {
|
||||
// We don't care about regions here, so it's fine to skip the binder here.
|
||||
if let (ty::Param(_), ty::PredicateKind::Trait(p)) =
|
||||
if let (ty::Param(_), ty::PredicateKind::Clause(ty::Clause::Trait(p))) =
|
||||
(self_ty.kind(), parent_pred.kind().skip_binder())
|
||||
{
|
||||
let hir = self.tcx.hir();
|
||||
@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut format_pred = |pred: ty::Predicate<'tcx>| {
|
||||
let bound_predicate = pred.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Projection(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
|
||||
let pred = bound_predicate.rebind(pred);
|
||||
// `<Foo as Iterator>::Item = String`.
|
||||
let projection_ty = pred.skip_binder().projection_ty;
|
||||
@ -567,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
|
||||
Some((obligation, projection_ty.self_ty()))
|
||||
}
|
||||
ty::PredicateKind::Trait(poly_trait_ref) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(poly_trait_ref)) => {
|
||||
let p = poly_trait_ref.trait_ref;
|
||||
let self_ty = p.self_ty();
|
||||
let path = p.print_only_trait_path();
|
||||
@ -637,7 +637,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let sized_pred =
|
||||
unsatisfied_predicates.iter().any(|(pred, _, _)| {
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
Some(pred.def_id())
|
||||
== self.tcx.lang_items().sized_trait()
|
||||
&& pred.polarity == ty::ImplPolarity::Positive
|
||||
@ -1722,7 +1722,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
) {
|
||||
let all_local_types_needing_impls =
|
||||
errors.iter().all(|e| match e.obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => match pred.self_ty().kind() {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => match pred.self_ty().kind() {
|
||||
ty::Adt(def, _) => def.did().is_local(),
|
||||
_ => false,
|
||||
},
|
||||
@ -1731,7 +1731,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut preds: Vec<_> = errors
|
||||
.iter()
|
||||
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => Some(pred),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => Some(pred),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
@ -1802,7 +1802,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut derives = Vec::<(String, Span, Symbol)>::new();
|
||||
let mut traits = Vec::<Span>::new();
|
||||
for (pred, _, _) in unsatisfied_predicates {
|
||||
let ty::PredicateKind::Trait(trait_pred) = pred.kind().skip_binder() else { continue };
|
||||
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = pred.kind().skip_binder() else { continue };
|
||||
let adt = match trait_pred.self_ty().ty_adt_def() {
|
||||
Some(adt) if adt.did().is_local() => adt,
|
||||
_ => continue,
|
||||
@ -2212,8 +2212,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
match p.kind().skip_binder() {
|
||||
// Hide traits if they are present in predicates as they can be fixed without
|
||||
// having to implement them.
|
||||
ty::PredicateKind::Trait(t) => t.def_id() == info.def_id,
|
||||
ty::PredicateKind::Projection(p) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(t)) => {
|
||||
t.def_id() == info.def_id
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(p)) => {
|
||||
p.projection_ty.item_def_id == info.def_id
|
||||
}
|
||||
_ => false,
|
||||
|
@ -569,10 +569,10 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
|
||||
let atom = match k1.unpack() {
|
||||
GenericArgKind::Lifetime(r1) => {
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(r1, r2)))
|
||||
}
|
||||
GenericArgKind::Type(t1) => {
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(t1, r2)))
|
||||
}
|
||||
GenericArgKind::Const(..) => {
|
||||
// Consts cannot outlive one another, so we don't expect to
|
||||
@ -720,8 +720,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
||||
self.obligations.push(Obligation {
|
||||
cause: self.cause.clone(),
|
||||
param_env: self.param_env,
|
||||
predicate: ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
sup, sub,
|
||||
predicate: ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(sup, sub),
|
||||
)))
|
||||
.to_predicate(self.infcx.tcx),
|
||||
recursion_depth: 0,
|
||||
|
@ -351,7 +351,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
let output = predicate
|
||||
.kind()
|
||||
.map_bound(|kind| match kind {
|
||||
ty::PredicateKind::Projection(projection_predicate)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate))
|
||||
if projection_predicate.projection_ty.item_def_id == item_def_id =>
|
||||
{
|
||||
projection_predicate.term.ty()
|
||||
|
@ -595,7 +595,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
ct_op: |ct| ct,
|
||||
});
|
||||
|
||||
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(projection)) =
|
||||
predicate.kind().skip_binder()
|
||||
{
|
||||
if projection.term.references_error() {
|
||||
// No point on adding these obligations since there's a type error involved.
|
||||
return Ok(InferOk { value: (), obligations: vec![] });
|
||||
|
@ -19,20 +19,21 @@ pub fn explicit_outlives_bounds<'tcx>(
|
||||
.map(ty::Predicate::kind)
|
||||
.filter_map(ty::Binder::no_bound_vars)
|
||||
.filter_map(move |kind| match kind {
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Ambiguous
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
|
||||
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
r_a,
|
||||
r_b,
|
||||
))) => Some(OutlivesBound::RegionSubRegion(r_b, r_a)),
|
||||
})
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ impl<'tcx> PredicateObligation<'tcx> {
|
||||
|
||||
pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> {
|
||||
self.param_env = self.param_env.without_const();
|
||||
if let ty::PredicateKind::Trait(trait_pred) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() {
|
||||
self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Trait(trait_pred.without_const())));
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() {
|
||||
self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred.without_const()))));
|
||||
}
|
||||
self
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
|
||||
// Get predicates declared on the trait.
|
||||
let predicates = tcx.super_predicates_of(data.def_id());
|
||||
|
||||
@ -184,7 +184,7 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
// Currently, we do not "elaborate" predicates like `X -> Y`,
|
||||
// though conceivably we might.
|
||||
}
|
||||
ty::PredicateKind::Projection(..) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..)) => {
|
||||
// Nothing to elaborate in a projection predicate.
|
||||
}
|
||||
ty::PredicateKind::ClosureKind(..) => {
|
||||
@ -198,10 +198,13 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
// Currently, we do not elaborate const-equate
|
||||
// predicates.
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(..) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => {
|
||||
// Nothing to elaborate from `'a: 'b`.
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty_max,
|
||||
r_min,
|
||||
))) => {
|
||||
// We know that `T: 'a` for some type `T`. We can
|
||||
// often elaborate this. For example, if we know that
|
||||
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
|
||||
@ -231,16 +234,16 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
if r.is_late_bound() {
|
||||
None
|
||||
} else {
|
||||
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
r, r_min,
|
||||
Some(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(r, r_min),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
Component::Param(p) => {
|
||||
let ty = tcx.mk_ty_param(p.index, p.name);
|
||||
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty, r_min,
|
||||
Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty, r_min),
|
||||
)))
|
||||
}
|
||||
|
||||
@ -248,8 +251,8 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
|
||||
Component::Opaque(def_id, substs) => {
|
||||
let ty = tcx.mk_opaque(def_id, substs);
|
||||
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty, r_min,
|
||||
Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty, r_min),
|
||||
)))
|
||||
}
|
||||
|
||||
@ -258,8 +261,8 @@ impl<'tcx> Elaborator<'tcx> {
|
||||
// With this, we can deduce that `<Bar as Baz>::Assoc: 'a`.
|
||||
let ty =
|
||||
tcx.mk_projection(projection.item_def_id, projection.substs);
|
||||
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty, r_min,
|
||||
Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty, r_min),
|
||||
)))
|
||||
}
|
||||
|
||||
|
@ -1638,19 +1638,20 @@ declare_lint_pass!(
|
||||
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::Clause;
|
||||
use rustc_middle::ty::PredicateKind::*;
|
||||
|
||||
if cx.tcx.features().trivial_bounds {
|
||||
let predicates = cx.tcx.predicates_of(item.owner_id);
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
let predicate_kind_name = match predicate.kind().skip_binder() {
|
||||
Trait(..) => "trait",
|
||||
TypeOutlives(..) |
|
||||
RegionOutlives(..) => "lifetime",
|
||||
Clause(Clause::Trait(..)) => "trait",
|
||||
Clause(Clause::TypeOutlives(..)) |
|
||||
Clause(Clause::RegionOutlives(..)) => "lifetime",
|
||||
|
||||
// Ignore projections, as they can only be global
|
||||
// if the trait bound is global
|
||||
Projection(..) |
|
||||
Clause(Clause::Projection(..)) |
|
||||
// Ignore bounds that a user can't type
|
||||
WellFormed(..) |
|
||||
ObjectSafe(..) |
|
||||
@ -2051,7 +2052,10 @@ impl ExplicitOutlivesRequirements {
|
||||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => match *a {
|
||||
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
|
||||
_ => None,
|
||||
},
|
||||
@ -2067,9 +2071,10 @@ impl ExplicitOutlivesRequirements {
|
||||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
a.is_param(index).then_some(b)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => a.is_param(index).then_some(b),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
|
@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||
// Liberate bound regions in the predicate since we
|
||||
// don't actually care about lifetimes in this check.
|
||||
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
||||
let ty::PredicateKind::Projection(proj) = predicate else {
|
||||
let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = predicate else {
|
||||
continue;
|
||||
};
|
||||
// Only check types, since those are the only things that may
|
||||
@ -116,12 +116,13 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||
// If it's a trait bound and an opaque that doesn't satisfy it,
|
||||
// then we can emit a suggestion to add the bound.
|
||||
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
||||
(ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => {
|
||||
Some(AddBound {
|
||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||
trait_ref: trait_pred.print_modifiers_and_trait_path(),
|
||||
})
|
||||
}
|
||||
(
|
||||
ty::Opaque(def_id, _),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
|
||||
) => Some(AddBound {
|
||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||
trait_ref: trait_pred.print_modifiers_and_trait_path(),
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
cx.emit_spanned_lint(
|
||||
|
@ -87,11 +87,12 @@ declare_lint_pass!(
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
use rustc_middle::ty::Clause;
|
||||
use rustc_middle::ty::PredicateKind::*;
|
||||
|
||||
let predicates = cx.tcx.explicit_predicates_of(item.owner_id);
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
let Trait(trait_predicate) = predicate.kind().skip_binder() else {
|
||||
let Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
||||
continue
|
||||
};
|
||||
let def_id = trait_predicate.trait_ref.def_id;
|
||||
|
@ -258,8 +258,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||
)
|
||||
.filter_map(|obligation| {
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate) =
|
||||
obligation.predicate.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
ref poly_trait_predicate,
|
||||
)) = obligation.predicate.kind().skip_binder()
|
||||
{
|
||||
let def_id = poly_trait_predicate.trait_ref.def_id;
|
||||
|
||||
|
@ -2296,7 +2296,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||
|
||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
||||
let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
|
||||
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
||||
return false;
|
||||
};
|
||||
trait_predicate.trait_ref.def_id == future_trait
|
||||
@ -2319,7 +2319,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
let generic_predicates = self.super_predicates_of(trait_did);
|
||||
|
||||
for (predicate, _) in generic_predicates.predicates {
|
||||
if let ty::PredicateKind::Trait(data) = predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(data)) =
|
||||
predicate.kind().skip_binder()
|
||||
{
|
||||
if set.insert(data.def_id()) {
|
||||
stack.push(data.def_id());
|
||||
}
|
||||
|
@ -216,14 +216,17 @@ impl FlagComputation {
|
||||
|
||||
fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) {
|
||||
match atom {
|
||||
ty::PredicateKind::Trait(trait_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
|
||||
self.add_substs(trait_pred.trait_ref.substs);
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(a, b))) => {
|
||||
self.add_region(a);
|
||||
self.add_region(b);
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty,
|
||||
region,
|
||||
))) => {
|
||||
self.add_ty(ty);
|
||||
self.add_region(region);
|
||||
}
|
||||
@ -235,7 +238,10 @@ impl FlagComputation {
|
||||
self.add_ty(a);
|
||||
self.add_ty(b);
|
||||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
||||
projection_ty,
|
||||
term,
|
||||
})) => {
|
||||
self.add_projection_ty(projection_ty);
|
||||
match term.unpack() {
|
||||
ty::TermKind::Ty(ty) => self.add_ty(ty),
|
||||
|
@ -574,13 +574,15 @@ impl<'tcx> Predicate<'tcx> {
|
||||
let kind = self
|
||||
.kind()
|
||||
.map_bound(|kind| match kind {
|
||||
PredicateKind::Trait(TraitPredicate { trait_ref, constness, polarity }) => {
|
||||
Some(PredicateKind::Trait(TraitPredicate {
|
||||
trait_ref,
|
||||
constness,
|
||||
polarity: polarity.flip()?,
|
||||
}))
|
||||
}
|
||||
PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref,
|
||||
constness,
|
||||
polarity,
|
||||
})) => Some(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref,
|
||||
constness,
|
||||
polarity: polarity.flip()?,
|
||||
}))),
|
||||
|
||||
_ => None,
|
||||
})
|
||||
@ -590,14 +592,14 @@ impl<'tcx> Predicate<'tcx> {
|
||||
}
|
||||
|
||||
pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> Self {
|
||||
if let PredicateKind::Trait(TraitPredicate { trait_ref, constness, polarity }) = self.kind().skip_binder()
|
||||
if let PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref, constness, polarity })) = self.kind().skip_binder()
|
||||
&& constness != BoundConstness::NotConst
|
||||
{
|
||||
self = tcx.mk_predicate(self.kind().rebind(PredicateKind::Trait(TraitPredicate {
|
||||
self = tcx.mk_predicate(self.kind().rebind(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref,
|
||||
constness: BoundConstness::NotConst,
|
||||
polarity,
|
||||
})));
|
||||
}))));
|
||||
}
|
||||
self
|
||||
}
|
||||
@ -611,10 +613,10 @@ impl<'tcx> Predicate<'tcx> {
|
||||
pub fn allow_normalization(self) -> bool {
|
||||
match self.kind().skip_binder() {
|
||||
PredicateKind::WellFormed(_) => false,
|
||||
PredicateKind::Trait(_)
|
||||
| PredicateKind::RegionOutlives(_)
|
||||
| PredicateKind::TypeOutlives(_)
|
||||
| PredicateKind::Projection(_)
|
||||
PredicateKind::Clause(Clause::Trait(_))
|
||||
| PredicateKind::Clause(Clause::RegionOutlives(_))
|
||||
| PredicateKind::Clause(Clause::TypeOutlives(_))
|
||||
| PredicateKind::Clause(Clause::Projection(_))
|
||||
| PredicateKind::ObjectSafe(_)
|
||||
| PredicateKind::ClosureKind(_, _, _)
|
||||
| PredicateKind::Subtype(_)
|
||||
@ -650,7 +652,9 @@ impl rustc_errors::IntoDiagnosticArg for Predicate<'_> {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
|
||||
pub enum PredicateKind<'tcx> {
|
||||
/// A clause is something that can appear in where bounds or be inferred
|
||||
/// by implied bounds.
|
||||
pub enum Clause<'tcx> {
|
||||
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
|
||||
/// the `Self` type of the trait reference and `A`, `B`, and `C`
|
||||
/// would be the type parameters.
|
||||
@ -665,6 +669,13 @@ pub enum PredicateKind<'tcx> {
|
||||
/// `where <T as TraitRef>::Name == X`, approximately.
|
||||
/// See the `ProjectionPredicate` struct for details.
|
||||
Projection(ProjectionPredicate<'tcx>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
|
||||
pub enum PredicateKind<'tcx> {
|
||||
/// Prove a clause
|
||||
Clause(Clause<'tcx>),
|
||||
|
||||
/// No syntax: `T` well-formed.
|
||||
WellFormed(GenericArg<'tcx>),
|
||||
@ -1153,27 +1164,46 @@ impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tc
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
|
||||
pred.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
self.map_bound(|trait_ref| TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(PredicateKind::Trait).to_predicate(tcx)
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::Trait(p))).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyRegionOutlivesPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(PredicateKind::RegionOutlives).to_predicate(tcx)
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::RegionOutlives(p))).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTypeOutlivesPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(PredicateKind::TypeOutlives).to_predicate(tcx)
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::TypeOutlives(p))).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyProjectionPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(PredicateKind::Projection).to_predicate(tcx)
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::Projection(p))).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1181,15 +1211,15 @@ impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Trait(t) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Projection(..)
|
||||
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Clause(Clause::Projection(..))
|
||||
| PredicateKind::Subtype(..)
|
||||
| PredicateKind::Coerce(..)
|
||||
| PredicateKind::RegionOutlives(..)
|
||||
| PredicateKind::Clause(Clause::RegionOutlives(..))
|
||||
| PredicateKind::WellFormed(..)
|
||||
| PredicateKind::ObjectSafe(..)
|
||||
| PredicateKind::ClosureKind(..)
|
||||
| PredicateKind::TypeOutlives(..)
|
||||
| PredicateKind::Clause(Clause::TypeOutlives(..))
|
||||
| PredicateKind::ConstEvaluatable(..)
|
||||
| PredicateKind::ConstEquate(..)
|
||||
| PredicateKind::Ambiguous
|
||||
@ -1200,15 +1230,15 @@ impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_projection_pred(self) -> Option<PolyProjectionPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Projection(t) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Trait(..)
|
||||
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Clause(Clause::Trait(..))
|
||||
| PredicateKind::Subtype(..)
|
||||
| PredicateKind::Coerce(..)
|
||||
| PredicateKind::RegionOutlives(..)
|
||||
| PredicateKind::Clause(Clause::RegionOutlives(..))
|
||||
| PredicateKind::WellFormed(..)
|
||||
| PredicateKind::ObjectSafe(..)
|
||||
| PredicateKind::ClosureKind(..)
|
||||
| PredicateKind::TypeOutlives(..)
|
||||
| PredicateKind::Clause(Clause::TypeOutlives(..))
|
||||
| PredicateKind::ConstEvaluatable(..)
|
||||
| PredicateKind::ConstEquate(..)
|
||||
| PredicateKind::Ambiguous
|
||||
@ -1219,12 +1249,12 @@ impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::TypeOutlives(data) => Some(predicate.rebind(data)),
|
||||
PredicateKind::Trait(..)
|
||||
| PredicateKind::Projection(..)
|
||||
PredicateKind::Clause(Clause::TypeOutlives(data)) => Some(predicate.rebind(data)),
|
||||
PredicateKind::Clause(Clause::Trait(..))
|
||||
| PredicateKind::Clause(Clause::Projection(..))
|
||||
| PredicateKind::Subtype(..)
|
||||
| PredicateKind::Coerce(..)
|
||||
| PredicateKind::RegionOutlives(..)
|
||||
| PredicateKind::Clause(Clause::RegionOutlives(..))
|
||||
| PredicateKind::WellFormed(..)
|
||||
| PredicateKind::ObjectSafe(..)
|
||||
| PredicateKind::ClosureKind(..)
|
||||
|
@ -814,7 +814,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
let bound_predicate = predicate.kind();
|
||||
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
let trait_ref = bound_predicate.rebind(pred.trait_ref);
|
||||
|
||||
// Don't print + Sized, but rather + ?Sized if absent.
|
||||
@ -825,7 +825,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
|
||||
self.insert_trait_and_projection(trait_ref, None, &mut traits, &mut fn_traits);
|
||||
}
|
||||
ty::PredicateKind::Projection(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
|
||||
let proj_ref = bound_predicate.rebind(pred);
|
||||
let trait_ref = proj_ref.required_poly_trait_ref(tcx);
|
||||
|
||||
@ -839,7 +839,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
&mut fn_traits,
|
||||
);
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(outlives) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(outlives)) => {
|
||||
lifetimes.push(outlives.1);
|
||||
}
|
||||
_ => {}
|
||||
@ -2689,14 +2689,14 @@ define_print_and_forward_display! {
|
||||
|
||||
ty::PredicateKind<'tcx> {
|
||||
match *self {
|
||||
ty::PredicateKind::Trait(ref data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ref data)) => {
|
||||
p!(print(data))
|
||||
}
|
||||
ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
|
||||
ty::PredicateKind::Coerce(predicate) => p!(print(predicate)),
|
||||
ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
|
||||
ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
|
||||
ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"),
|
||||
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
||||
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
|
||||
|
@ -150,15 +150,23 @@ impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::Clause<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::Clause::Trait(ref a) => a.fmt(f),
|
||||
ty::Clause::RegionOutlives(ref pair) => pair.fmt(f),
|
||||
ty::Clause::TypeOutlives(ref pair) => pair.fmt(f),
|
||||
ty::Clause::Projection(ref pair) => pair.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::PredicateKind::Trait(ref a) => a.fmt(f),
|
||||
ty::PredicateKind::Clause(ref a) => a.fmt(f),
|
||||
ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
|
||||
ty::PredicateKind::Coerce(ref pair) => pair.fmt(f),
|
||||
ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
|
||||
ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
|
||||
ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
|
||||
ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
|
||||
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
||||
write!(f, "ObjectSafe({:?})", trait_def_id)
|
||||
|
@ -853,23 +853,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
|
||||
pub fn def_id(&self) -> DefId {
|
||||
self.skip_binder().def_id
|
||||
}
|
||||
|
||||
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
|
||||
self.map_bound(|trait_ref| ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
})
|
||||
}
|
||||
|
||||
/// Same as [`PolyTraitRef::to_poly_trait_predicate`] but sets a negative polarity instead.
|
||||
pub fn to_poly_trait_predicate_negative_polarity(&self) -> ty::PolyTraitPredicate<'tcx> {
|
||||
self.map_bound(|trait_ref| ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: ty::ImplPolarity::Negative,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {
|
||||
|
@ -110,7 +110,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
|
||||
|
||||
/// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type.
|
||||
fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option<Ty<'tcx>> {
|
||||
if let ty::PredicateKind::Trait(predicate) = bound {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) = bound {
|
||||
if self.tcx.is_diagnostic_item(sym::Pointer, predicate.def_id()) {
|
||||
Some(predicate.trait_ref.self_ty())
|
||||
} else {
|
||||
|
@ -146,19 +146,23 @@ where
|
||||
|
||||
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
}) => self.visit_trait(trait_ref),
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
|
||||
})) => self.visit_trait(trait_ref),
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
||||
projection_ty,
|
||||
term,
|
||||
})) => {
|
||||
term.visit_with(self)?;
|
||||
self.visit_projection_ty(projection_ty)
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
|
||||
ty.visit_with(self)
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE,
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty,
|
||||
_region,
|
||||
))) => ty.visit_with(self),
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => ControlFlow::CONTINUE,
|
||||
ty::PredicateKind::ConstEvaluatable(ct) => ct.visit_with(self),
|
||||
ty::PredicateKind::WellFormed(arg) => arg.visit_with(self),
|
||||
_ => bug!("unexpected predicate: {:?}", predicate),
|
||||
|
@ -131,7 +131,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
||||
tcx,
|
||||
cause.clone(),
|
||||
self.param_env,
|
||||
ty::Binder::dummy(trait_ref).without_const(),
|
||||
ty::Binder::dummy(trait_ref),
|
||||
);
|
||||
if !self.infcx.predicate_may_hold(&obligation) {
|
||||
debug!("overloaded_deref_ty: cannot match obligation");
|
||||
|
@ -10,7 +10,7 @@ use crate::traits::project::ProjectAndUnifyResult;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::{PolyTraitRef, Region, RegionVid};
|
||||
use rustc_middle::ty::{ImplPolarity, Region, RegionVid};
|
||||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
||||
|
||||
@ -88,19 +88,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
||||
|
||||
let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);
|
||||
|
||||
let trait_pred = ty::Binder::dummy(trait_ref);
|
||||
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
let mut selcx = SelectionContext::new(&infcx);
|
||||
for f in [
|
||||
PolyTraitRef::to_poly_trait_predicate,
|
||||
PolyTraitRef::to_poly_trait_predicate_negative_polarity,
|
||||
] {
|
||||
for polarity in [true, false] {
|
||||
let result = selcx.select(&Obligation::new(
|
||||
tcx,
|
||||
ObligationCause::dummy(),
|
||||
orig_env,
|
||||
f(&trait_pred),
|
||||
ty::Binder::dummy(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: ty::BoundConstness::NotConst,
|
||||
polarity: if polarity {
|
||||
ImplPolarity::Positive
|
||||
} else {
|
||||
ImplPolarity::Negative
|
||||
},
|
||||
}),
|
||||
));
|
||||
if let Ok(Some(ImplSource::UserDefined(_))) = result {
|
||||
debug!(
|
||||
@ -400,8 +403,10 @@ impl<'tcx> 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::Clause(ty::Clause::Trait(new_trait)),
|
||||
ty::PredicateKind::Clause(ty::Clause::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;
|
||||
@ -621,14 +626,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
||||
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(p) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::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`
|
||||
// if possible.
|
||||
predicates.push_back(bound_predicate.rebind(p));
|
||||
}
|
||||
ty::PredicateKind::Projection(p) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(p)) => {
|
||||
let p = bound_predicate.rebind(p);
|
||||
debug!(
|
||||
"evaluate_nested_obligations: examining projection predicate {:?}",
|
||||
@ -761,11 +766,11 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(binder) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(binder)) => {
|
||||
let binder = bound_predicate.rebind(binder);
|
||||
select.infcx().region_outlives_predicate(&dummy_cause, binder)
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(binder) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(binder)) => {
|
||||
let binder = bound_predicate.rebind(binder);
|
||||
match (
|
||||
binder.no_bound_vars(),
|
||||
|
@ -39,8 +39,7 @@ pub fn codegen_select_candidate<'tcx>(
|
||||
let mut selcx = SelectionContext::new(&infcx);
|
||||
|
||||
let obligation_cause = ObligationCause::dummy();
|
||||
let obligation =
|
||||
Obligation::new(tcx, obligation_cause, param_env, trait_ref.to_poly_trait_predicate());
|
||||
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);
|
||||
|
||||
let selection = match selcx.select(&obligation) {
|
||||
Ok(Some(selection)) => selection,
|
||||
|
@ -587,7 +587,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
|
||||
let trait_predicate = bound_predicate.rebind(trait_predicate);
|
||||
let mut trait_predicate = self.resolve_vars_if_possible(trait_predicate);
|
||||
|
||||
@ -1051,9 +1051,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
span_bug!(span, "coerce requirement gave wrong error: `{:?}`", predicate)
|
||||
}
|
||||
|
||||
ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::TypeOutlives(..) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) => {
|
||||
let predicate = self.resolve_vars_if_possible(obligation.predicate);
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
@ -1473,9 +1473,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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)) => {
|
||||
(cond, bound_error.rebind(error))
|
||||
}
|
||||
(
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(error)),
|
||||
) => (cond, bound_error.rebind(error)),
|
||||
_ => {
|
||||
// FIXME: make this work in other cases too.
|
||||
return false;
|
||||
@ -1484,7 +1485,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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::Clause(ty::Clause::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.
|
||||
@ -1581,7 +1584,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
// this can fail if the problem was higher-ranked, in which
|
||||
// cause I have no idea for a good error message.
|
||||
let bound_predicate = predicate.kind();
|
||||
if let ty::PredicateKind::Projection(data) = bound_predicate.skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
|
||||
bound_predicate.skip_binder()
|
||||
{
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
let data = self.replace_bound_vars_with_fresh_vars(
|
||||
obligation.cause.span,
|
||||
@ -1629,7 +1634,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
let mut diag = struct_span_err!(self.tcx.sess, obligation.cause.span, E0271, "{msg}");
|
||||
|
||||
let secondary_span = match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Projection(proj) => self
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => self
|
||||
.tcx
|
||||
.opt_associated_item(proj.projection_ty.item_def_id)
|
||||
.and_then(|trait_assoc_item| {
|
||||
@ -2047,7 +2052,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
let bound_predicate = predicate.kind();
|
||||
let mut err = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
|
||||
let trait_ref = bound_predicate.rebind(data.trait_ref);
|
||||
debug!(?trait_ref);
|
||||
|
||||
@ -2111,7 +2116,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
)
|
||||
};
|
||||
|
||||
let obligation = obligation.with(self.tcx, trait_ref.to_poly_trait_predicate());
|
||||
let obligation = obligation.with(self.tcx, trait_ref);
|
||||
let mut selcx = SelectionContext::new(&self);
|
||||
match selcx.select_from_obligation(&obligation) {
|
||||
Ok(None) => {
|
||||
@ -2324,7 +2329,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
assert!(a.is_ty_var() && b.is_ty_var());
|
||||
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true)
|
||||
}
|
||||
ty::PredicateKind::Projection(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
|
||||
if predicate.references_error() || self.tainted_by_errors().is_some() {
|
||||
return;
|
||||
}
|
||||
@ -2570,7 +2575,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
err: &mut Diagnostic,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) {
|
||||
let ty::PredicateKind::Trait(pred) = obligation.predicate.kind().skip_binder() else { return; };
|
||||
let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = obligation.predicate.kind().skip_binder() else { return; };
|
||||
let (ObligationCauseCode::BindingObligation(item_def_id, span)
|
||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..))
|
||||
= *obligation.cause.code().peel_derives() else { return; };
|
||||
|
@ -810,7 +810,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
err: &mut Diagnostic,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
if let ty::PredicateKind::Trait(trait_pred) = obligation.predicate.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = obligation.predicate.kind().skip_binder()
|
||||
&& Some(trait_pred.def_id()) == self.tcx.lang_items().sized_trait()
|
||||
{
|
||||
// Don't suggest calling to turn an unsized type into a sized type
|
||||
@ -839,7 +839,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
ty::Opaque(def_id, substs) => {
|
||||
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
||||
if let ty::PredicateKind::Projection(proj) = pred.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output()
|
||||
// args tuple will always be substs[1]
|
||||
&& let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind()
|
||||
@ -873,7 +873,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
ty::Param(_) => {
|
||||
obligation.param_env.caller_bounds().iter().find_map(|pred| {
|
||||
if let ty::PredicateKind::Projection(proj) = pred.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||
&& Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output()
|
||||
&& proj.projection_ty.self_ty() == found
|
||||
// args tuple will always be substs[1]
|
||||
@ -1256,7 +1256,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
);
|
||||
// FIXME: account for associated `async fn`s.
|
||||
if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
|
||||
if let ty::PredicateKind::Trait(pred) =
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) =
|
||||
obligation.predicate.kind().skip_binder()
|
||||
{
|
||||
err.span_label(
|
||||
@ -1755,7 +1755,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
if let ObligationCauseCode::ExprBindingObligation(def_id, _, _, idx) = cause
|
||||
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
|
||||
&& let Some(pred) = predicates.predicates.get(*idx)
|
||||
&& let ty::PredicateKind::Trait(trait_pred) = pred.kind().skip_binder()
|
||||
&& let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = pred.kind().skip_binder()
|
||||
&& ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id()).is_some()
|
||||
{
|
||||
let expected_self =
|
||||
@ -1769,7 +1769,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
let other_pred = std::iter::zip(&predicates.predicates, &predicates.spans)
|
||||
.enumerate()
|
||||
.find(|(other_idx, (pred, _))| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(trait_pred)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
|
||||
if ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id())
|
||||
.is_some()
|
||||
&& other_idx != idx
|
||||
@ -1896,7 +1896,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, '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), Some(p.self_ty())),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(p)) => (Some(p), Some(p.self_ty())),
|
||||
_ => (None, None),
|
||||
};
|
||||
let mut generator = None;
|
||||
|
@ -269,7 +269,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, '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) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_ref)) => {
|
||||
let trait_obligation = obligation.with(infcx.tcx, binder.rebind(trait_ref));
|
||||
|
||||
self.process_trait_obligation(
|
||||
@ -278,7 +278,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||
&mut pending_obligation.stalled_on,
|
||||
)
|
||||
}
|
||||
ty::PredicateKind::Projection(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
|
||||
let project_obligation = obligation.with(infcx.tcx, binder.rebind(data));
|
||||
|
||||
self.process_projection_obligation(
|
||||
@ -287,8 +287,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||
&mut pending_obligation.stalled_on,
|
||||
)
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(_)
|
||||
| ty::PredicateKind::TypeOutlives(_)
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::ObjectSafe(_)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
@ -306,7 +306,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||
}
|
||||
},
|
||||
Some(pred) => match pred {
|
||||
ty::PredicateKind::Trait(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
|
||||
let trait_obligation = obligation.with(infcx.tcx, Binder::dummy(data));
|
||||
|
||||
self.process_trait_obligation(
|
||||
@ -316,7 +316,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
ty::PredicateKind::RegionOutlives(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(data)) => {
|
||||
if infcx.considering_regions {
|
||||
infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data));
|
||||
}
|
||||
@ -324,14 +324,17 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||
ProcessResult::Changed(vec![])
|
||||
}
|
||||
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
t_a,
|
||||
r_b,
|
||||
))) => {
|
||||
if infcx.considering_regions {
|
||||
infcx.register_region_obligation_with_cause(t_a, r_b, &obligation.cause);
|
||||
}
|
||||
ProcessResult::Changed(vec![])
|
||||
}
|
||||
|
||||
ty::PredicateKind::Projection(ref data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ref data)) => {
|
||||
let project_obligation = obligation.with(infcx.tcx, Binder::dummy(*data));
|
||||
|
||||
self.process_projection_obligation(
|
||||
|
@ -317,7 +317,10 @@ pub fn normalize_param_env_or_error<'tcx>(
|
||||
// TypeOutlives predicates - these are normally used by regionck.
|
||||
let outlives_predicates: Vec<_> = predicates
|
||||
.drain_filter(|predicate| {
|
||||
matches!(predicate.kind().skip_binder(), ty::PredicateKind::TypeOutlives(..))
|
||||
matches!(
|
||||
predicate.kind().skip_binder(),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@ -477,7 +480,7 @@ fn subst_and_check_impossible_predicates<'tcx>(
|
||||
// associated items.
|
||||
if let Some(trait_def_id) = tcx.trait_of_item(key.0) {
|
||||
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
|
||||
predicates.push(ty::Binder::dummy(trait_ref).to_poly_trait_predicate().to_predicate(tcx));
|
||||
predicates.push(ty::Binder::dummy(trait_ref).to_predicate(tcx));
|
||||
}
|
||||
|
||||
predicates.retain(|predicate| !predicate.needs_subst());
|
||||
|
@ -288,11 +288,11 @@ fn predicate_references_self<'tcx>(
|
||||
let self_ty = tcx.types.self_param;
|
||||
let has_self_ty = |arg: &GenericArg<'tcx>| arg.walk().any(|arg| arg == self_ty.into());
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ref data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::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 }
|
||||
}
|
||||
ty::PredicateKind::Projection(ref data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(ref data)) => {
|
||||
// And similarly for projections. This should be redundant with
|
||||
// the previous check because any projection should have a
|
||||
// matching `Trait` predicate with the same inputs, but we do
|
||||
@ -312,8 +312,8 @@ fn predicate_references_self<'tcx>(
|
||||
}
|
||||
ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
@ -338,17 +338,17 @@ 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::Clause(ty::Clause::Trait(ref trait_pred)) => {
|
||||
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
|
||||
}
|
||||
ty::PredicateKind::Projection(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Ambiguous
|
||||
@ -723,8 +723,7 @@ fn receiver_is_dispatchable<'tcx>(
|
||||
let obligation = {
|
||||
let predicate = ty::Binder::dummy(
|
||||
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
|
||||
)
|
||||
.without_const();
|
||||
);
|
||||
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||
};
|
||||
|
@ -1328,8 +1328,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
|
||||
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
|
||||
// FIXME(named-returns): Binders
|
||||
let trait_predicate =
|
||||
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
|
||||
.to_poly_trait_predicate();
|
||||
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });
|
||||
|
||||
let _ = selcx.infcx().commit_if_ok(|_| {
|
||||
match selcx.select(&obligation.with(tcx, trait_predicate)) {
|
||||
@ -1477,7 +1476,9 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
|
||||
let infcx = selcx.infcx();
|
||||
for predicate in env_predicates {
|
||||
let bound_predicate = predicate.kind();
|
||||
if let ty::PredicateKind::Projection(data) = predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(data)) =
|
||||
predicate.kind().skip_binder()
|
||||
{
|
||||
let data = bound_predicate.rebind(data);
|
||||
if data.projection_def_id() != obligation.predicate.item_def_id {
|
||||
continue;
|
||||
@ -1527,7 +1528,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
||||
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
|
||||
// start out by selecting the predicate `T as TraitRef<...>`:
|
||||
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
|
||||
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
|
||||
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref);
|
||||
let _ = selcx.infcx().commit_if_ok(|_| {
|
||||
let impl_source = match selcx.select(&trait_obligation) {
|
||||
Ok(Some(impl_source)) => impl_source,
|
||||
|
@ -66,7 +66,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||
let mut _orig_values = OriginalQueryValues::default();
|
||||
|
||||
let param_env = match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
// we ignore the value set to it.
|
||||
let mut _constness = pred.constness;
|
||||
obligation
|
||||
|
@ -15,7 +15,9 @@ 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::Clause(ty::Clause::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) {
|
||||
@ -33,7 +35,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
|
||||
mut canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
|
||||
) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
|
||||
match canonicalized.value.value.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
canonicalized.value.param_env.remap_constness_with(pred.constness);
|
||||
}
|
||||
_ => canonicalized.value.param_env = canonicalized.value.param_env.without_const(),
|
||||
|
@ -12,7 +12,7 @@ pub(crate) fn update<'tcx, T>(
|
||||
T: TraitEngine<'tcx>,
|
||||
{
|
||||
// (*) binder skipped
|
||||
if let ty::PredicateKind::Trait(tpred) = obligation.predicate.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(tpred)) = obligation.predicate.kind().skip_binder()
|
||||
&& let Some(ty) = infcx.shallow_resolve(tpred.self_ty()).ty_vid().map(|t| infcx.root_var(t))
|
||||
&& infcx.tcx.lang_items().sized_trait().map_or(false, |st| st != tpred.trait_ref.def_id)
|
||||
{
|
||||
@ -26,7 +26,7 @@ pub(crate) fn update<'tcx, T>(
|
||||
.kind()
|
||||
.rebind(
|
||||
// (*) binder moved here
|
||||
ty::PredicateKind::Trait(tpred.with_self_type(infcx.tcx, new_self_ty))
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_type(infcx.tcx, new_self_ty)))
|
||||
),
|
||||
);
|
||||
// Don't report overflow errors. Otherwise equivalent to may_hold.
|
||||
@ -35,7 +35,9 @@ pub(crate) fn update<'tcx, T>(
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::PredicateKind::Projection(predicate) = obligation.predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) =
|
||||
obligation.predicate.kind().skip_binder()
|
||||
{
|
||||
// If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
|
||||
// we need to make it into one.
|
||||
if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
|
||||
|
@ -731,12 +731,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// <ty as Deref>
|
||||
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
|
||||
|
||||
let obligation = traits::Obligation::new(
|
||||
tcx,
|
||||
cause.clone(),
|
||||
param_env,
|
||||
ty::Binder::dummy(trait_ref).without_const(),
|
||||
);
|
||||
let obligation =
|
||||
traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref));
|
||||
if !self.infcx.predicate_may_hold(&obligation) {
|
||||
return None;
|
||||
}
|
||||
|
@ -634,12 +634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
);
|
||||
let tr =
|
||||
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
|
||||
nested.push(Obligation::new(
|
||||
self.infcx.tcx,
|
||||
cause,
|
||||
obligation.param_env,
|
||||
tr.to_poly_trait_predicate(),
|
||||
));
|
||||
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
|
||||
|
||||
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
ensure_sufficient_stack(|| {
|
||||
let bound_predicate = obligation.predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(t) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(t)) => {
|
||||
let t = bound_predicate.rebind(t);
|
||||
debug_assert!(!t.has_escaping_bound_vars());
|
||||
let obligation = obligation.with(self.tcx(), t);
|
||||
@ -546,7 +546,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::PredicateKind::TypeOutlives(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(pred)) => {
|
||||
// A global type with no late-bound regions can only
|
||||
// contain the "'static" lifetime (any other lifetime
|
||||
// would either be late-bound or local), so it is guaranteed
|
||||
@ -558,7 +558,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::PredicateKind::RegionOutlives(..) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => {
|
||||
// We do not consider region relationships when evaluating trait matches.
|
||||
Ok(EvaluatedToOkModuloRegions)
|
||||
}
|
||||
@ -571,7 +571,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::PredicateKind::Projection(data) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
|
||||
let data = bound_predicate.rebind(data);
|
||||
let project_obligation = obligation.with(self.tcx(), data);
|
||||
match project::poly_project_and_unify_type(self, &project_obligation) {
|
||||
@ -931,7 +931,9 @@ 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_coinductive(data.def_id()),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(ref data)) => {
|
||||
self.tcx().trait_is_coinductive(data.def_id())
|
||||
}
|
||||
ty::PredicateKind::WellFormed(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
@ -1377,7 +1379,9 @@ 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::Clause(ty::Clause::Trait(pred)) =
|
||||
bound_predicate.skip_binder()
|
||||
{
|
||||
let bound = bound_predicate.rebind(pred.trait_ref);
|
||||
if self.infcx.probe(|_| {
|
||||
match self.match_normalize_trait_ref(
|
||||
|
@ -476,7 +476,9 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti
|
||||
trait_pred
|
||||
});
|
||||
|
||||
p = tcx.mk_predicate(new_trait_pred.map_bound(ty::PredicateKind::Trait))
|
||||
p = tcx.mk_predicate(
|
||||
new_trait_pred.map_bound(|p| ty::PredicateKind::Clause(ty::Clause::Trait(p))),
|
||||
)
|
||||
}
|
||||
}
|
||||
pretty_predicates.push(p.to_string());
|
||||
|
@ -121,14 +121,14 @@ pub fn predicate_obligations<'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::Clause(ty::Clause::Trait(t)) => {
|
||||
wf.compute_trait_pred(&t, Elaborate::None);
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(..) => {}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => {}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty, _reg))) => {
|
||||
wf.compute(ty.into());
|
||||
}
|
||||
ty::PredicateKind::Projection(t) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(t)) => {
|
||||
wf.compute_projection(t.projection_ty);
|
||||
wf.compute(match t.term.unpack() {
|
||||
ty::TermKind::Ty(ty) => ty.into(),
|
||||
@ -228,7 +228,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
||||
|
||||
// It is fine to skip the binder as we don't care about regions here.
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Projection(proj) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => {
|
||||
// The obligation comes not from the current `impl` nor the `trait` being implemented,
|
||||
// but rather from a "second order" obligation, where an associated type has a
|
||||
// projection coming from another associated type. See
|
||||
@ -245,7 +245,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
||||
cause.span = impl_item_span;
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::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);
|
||||
@ -561,9 +561,9 @@ impl<'tcx> WfPredicates<'tcx> {
|
||||
cause,
|
||||
depth,
|
||||
param_env,
|
||||
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
|
||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
||||
ty::OutlivesPredicate(rty, r),
|
||||
)),
|
||||
))),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -866,19 +866,22 @@ pub(crate) fn required_region_bounds<'tcx>(
|
||||
.filter_map(|obligation| {
|
||||
debug!(?obligation);
|
||||
match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Ambiguous
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ref t,
|
||||
ref r,
|
||||
))) => {
|
||||
// Search for a bound of the form `erased_self_ty
|
||||
// : 'a`, but be wary of something like `for<'a>
|
||||
// erased_self_ty : 'a` (we interpret a
|
||||
|
@ -89,24 +89,32 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
|
||||
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
|
||||
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
|
||||
}
|
||||
ty::PredicateKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
|
||||
chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
|
||||
),
|
||||
ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
|
||||
a: predicate.0.lower_into(interner),
|
||||
b: predicate.1.lower_into(interner),
|
||||
}),
|
||||
),
|
||||
ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
|
||||
ty: predicate.0.lower_into(interner),
|
||||
lifetime: predicate.1.lower_into(interner),
|
||||
}),
|
||||
),
|
||||
ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
|
||||
),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
|
||||
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Trait(
|
||||
predicate.trait_ref.lower_into(interner),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
|
||||
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::LifetimeOutlives(
|
||||
chalk_ir::LifetimeOutlives {
|
||||
a: predicate.0.lower_into(interner),
|
||||
b: predicate.1.lower_into(interner),
|
||||
},
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
|
||||
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::TypeOutlives(
|
||||
chalk_ir::TypeOutlives {
|
||||
ty: predicate.0.lower_into(interner),
|
||||
lifetime: predicate.1.lower_into(interner),
|
||||
},
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
|
||||
chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::AliasEq(
|
||||
predicate.lower_into(interner),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
|
||||
ty::GenericArgKind::Type(ty) => chalk_ir::DomainGoal::WellFormed(
|
||||
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
|
||||
@ -149,12 +157,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
|
||||
collect_bound_vars(interner, interner.tcx, self.kind());
|
||||
|
||||
let value = match predicate {
|
||||
ty::PredicateKind::Trait(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
|
||||
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
|
||||
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
|
||||
a: predicate.0.lower_into(interner),
|
||||
@ -162,7 +170,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
|
||||
}),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
|
||||
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
|
||||
ty: predicate.0.lower_into(interner),
|
||||
@ -170,7 +178,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
|
||||
}),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Projection(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
|
||||
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
|
||||
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
|
||||
))
|
||||
@ -605,22 +613,22 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
|
||||
let (predicate, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, self.kind());
|
||||
let value = match predicate {
|
||||
ty::PredicateKind::Trait(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
|
||||
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
|
||||
Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
|
||||
a: predicate.0.lower_into(interner),
|
||||
b: predicate.1.lower_into(interner),
|
||||
}))
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
|
||||
Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
|
||||
ty: predicate.0.lower_into(interner),
|
||||
lifetime: predicate.1.lower_into(interner),
|
||||
}))
|
||||
}
|
||||
ty::PredicateKind::Projection(predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
|
||||
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
|
||||
}
|
||||
ty::PredicateKind::WellFormed(_ty) => None,
|
||||
@ -741,20 +749,24 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
|
||||
let (predicate, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, self.kind());
|
||||
match predicate {
|
||||
ty::PredicateKind::Trait(predicate) => Some(chalk_ir::Binders::new(
|
||||
binders,
|
||||
chalk_solve::rust_ir::InlineBound::TraitBound(
|
||||
predicate.trait_ref.lower_into(interner),
|
||||
),
|
||||
)),
|
||||
ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new(
|
||||
binders,
|
||||
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
|
||||
)),
|
||||
ty::PredicateKind::TypeOutlives(_predicate) => None,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
|
||||
Some(chalk_ir::Binders::new(
|
||||
binders,
|
||||
chalk_solve::rust_ir::InlineBound::TraitBound(
|
||||
predicate.trait_ref.lower_into(interner),
|
||||
),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
|
||||
Some(chalk_ir::Binders::new(
|
||||
binders,
|
||||
chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
|
||||
))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_predicate)) => None,
|
||||
ty::PredicateKind::WellFormed(_ty) => None,
|
||||
|
||||
ty::PredicateKind::RegionOutlives(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
|
@ -86,10 +86,10 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
match obligation.predicate.kind().no_bound_vars() {
|
||||
None => None,
|
||||
Some(pred) => match pred {
|
||||
ty::PredicateKind::Trait(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
@ -101,13 +101,14 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
None
|
||||
}
|
||||
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
|
||||
Some(ty::OutlivesPredicate(r_a.into(), r_b))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(r_a, r_b),
|
||||
)) => Some(ty::OutlivesPredicate(r_a.into(), r_b)),
|
||||
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
|
||||
Some(ty::OutlivesPredicate(ty_a.into(), r_b))
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty_a,
|
||||
r_b,
|
||||
))) => Some(ty::OutlivesPredicate(ty_a.into(), r_b)),
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
@ -56,9 +56,10 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq +
|
||||
|
||||
fn not_outlives_predicate<'tcx>(p: ty::Predicate<'tcx>) -> bool {
|
||||
match p.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
|
||||
ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) => false,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
|
@ -321,10 +321,10 @@ where
|
||||
let bound_predicate = pred.kind();
|
||||
let tcx = self.cx.tcx;
|
||||
let regions = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(poly_trait_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(poly_trait_pred)) => {
|
||||
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))
|
||||
}
|
||||
ty::PredicateKind::Projection(poly_proj_pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(poly_proj_pred)) => {
|
||||
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred))
|
||||
}
|
||||
_ => return FxHashSet::default(),
|
||||
@ -451,7 +451,9 @@ where
|
||||
.filter(|p| {
|
||||
!orig_bounds.contains(p)
|
||||
|| match p.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => pred.def_id() == sized_trait,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
pred.def_id() == sized_trait
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
|
@ -67,12 +67,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||
.instantiate(cx.tcx, impl_substs)
|
||||
.predicates
|
||||
.into_iter()
|
||||
.chain(Some(
|
||||
ty::Binder::dummy(impl_trait_ref)
|
||||
.to_poly_trait_predicate()
|
||||
.map_bound(ty::PredicateKind::Trait)
|
||||
.to_predicate(infcx.tcx),
|
||||
));
|
||||
.chain(Some(ty::Binder::dummy(impl_trait_ref).to_predicate(infcx.tcx)));
|
||||
for predicate in predicates {
|
||||
debug!("testing predicate {:?}", predicate);
|
||||
let obligation = traits::Obligation::new(
|
||||
|
@ -302,12 +302,16 @@ pub(crate) fn clean_predicate<'tcx>(
|
||||
) -> Option<WherePredicate> {
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
clean_poly_trait_predicate(bound_predicate.rebind(pred), cx)
|
||||
}
|
||||
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
|
||||
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
|
||||
ty::PredicateKind::Projection(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(pred)) => {
|
||||
clean_region_outlives_predicate(pred)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(pred)) => {
|
||||
clean_type_outlives_predicate(pred, cx)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
|
||||
Some(clean_projection_predicate(bound_predicate.rebind(pred), cx))
|
||||
}
|
||||
ty::PredicateKind::ConstEvaluatable(..) => None,
|
||||
@ -689,17 +693,20 @@ fn clean_ty_generics<'tcx>(
|
||||
let param_idx = (|| {
|
||||
let bound_p = p.kind();
|
||||
match bound_p.skip_binder() {
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
|
||||
if let ty::Param(param) = pred.self_ty().kind() {
|
||||
return Some(param.index);
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
ty,
|
||||
_reg,
|
||||
))) => {
|
||||
if let ty::Param(param) = ty.kind() {
|
||||
return Some(param.index);
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Projection(p) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(p)) => {
|
||||
if let ty::Param(param) = p.projection_ty.self_ty().kind() {
|
||||
projection = Some(bound_p.rebind(p));
|
||||
return Some(param.index);
|
||||
@ -1772,8 +1779,13 @@ fn clean_middle_opaque_bounds<'tcx>(
|
||||
.filter_map(|bound| {
|
||||
let bound_predicate = bound.kind();
|
||||
let trait_ref = match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Trait(tr) => bound_predicate.rebind(tr.trait_ref),
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(tr)) => {
|
||||
bound_predicate.rebind(tr.trait_ref)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
_ty,
|
||||
reg,
|
||||
))) => {
|
||||
if let Some(r) = clean_middle_region(reg) {
|
||||
regions.push(GenericBound::Outlives(r));
|
||||
}
|
||||
@ -1792,7 +1804,9 @@ fn clean_middle_opaque_bounds<'tcx>(
|
||||
let bindings: ThinVec<_> = bounds
|
||||
.iter()
|
||||
.filter_map(|bound| {
|
||||
if let ty::PredicateKind::Projection(proj) = bound.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) =
|
||||
bound.kind().skip_binder()
|
||||
{
|
||||
if proj.projection_ty.trait_ref(cx.tcx) == trait_ref.skip_binder() {
|
||||
Some(TypeBinding {
|
||||
assoc: projection_to_path_segment(proj.projection_ty, cx),
|
||||
|
@ -132,7 +132,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId)
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| {
|
||||
if let ty::PredicateKind::Trait(pred) = pred.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder() {
|
||||
if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None }
|
||||
} else {
|
||||
None
|
||||
|
@ -25,7 +25,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::mir::{Rvalue, StatementKind};
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
|
||||
self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
|
||||
ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults,
|
||||
};
|
||||
use rustc_semver::RustcVersion;
|
||||
@ -1097,7 +1097,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
|
||||
let projection_predicates = predicates
|
||||
.iter()
|
||||
.filter_map(|predicate| {
|
||||
if let PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
|
||||
if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() {
|
||||
Some(projection_predicate)
|
||||
} else {
|
||||
None
|
||||
@ -1111,7 +1111,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
|
||||
if predicates
|
||||
.iter()
|
||||
.filter_map(|predicate| {
|
||||
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
|
||||
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
|
||||
&& trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx)
|
||||
{
|
||||
Some(trait_predicate.trait_ref.def_id)
|
||||
@ -1173,7 +1173,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
|
||||
}
|
||||
|
||||
predicates.iter().all(|predicate| {
|
||||
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
|
||||
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
|
||||
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
|
||||
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
|
||||
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
|
||||
|
@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::traits::Reveal;
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
|
||||
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
|
||||
Ty, TyCtxt,
|
||||
};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
@ -499,7 +499,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||
|
||||
let ty_predicates = tcx.predicates_of(did).predicates;
|
||||
for (p, _) in ty_predicates {
|
||||
if let PredicateKind::Trait(p) = p.kind().skip_binder()
|
||||
if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder()
|
||||
&& p.trait_ref.def_id == eq_trait_id
|
||||
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
|
||||
&& p.constness == BoundConstness::NotConst
|
||||
@ -512,14 +512,14 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||
ParamEnv::new(
|
||||
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
|
||||
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Trait(TraitPredicate {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref: TraitRef::new(
|
||||
eq_trait_id,
|
||||
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
|
||||
),
|
||||
constness: BoundConstness::NotConst,
|
||||
polarity: ImplPolarity::Positive,
|
||||
})))
|
||||
}))))
|
||||
}),
|
||||
)),
|
||||
Reveal::UserFacing,
|
||||
|
@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, FnDecl, HirId};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
|
||||
use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
|
||||
@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||
infcx
|
||||
.err_ctxt()
|
||||
.maybe_note_obligation_cause_for_async_await(db, &obligation);
|
||||
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
|
||||
if let PredicateKind::Clause(Clause::Trait(trait_pred)) = obligation.predicate.kind().skip_binder() {
|
||||
db.note(&format!(
|
||||
"`{}` doesn't implement `{}`",
|
||||
trait_pred.self_ty(),
|
||||
|
@ -17,7 +17,7 @@ use rustc_middle::mir::Mutability;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::EarlyBinder;
|
||||
use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty};
|
||||
use rustc_middle::ty::{self, Clause, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_span::{sym, Symbol};
|
||||
use rustc_trait_selection::traits::{
|
||||
@ -341,12 +341,12 @@ fn get_input_traits_and_projections<'tcx>(
|
||||
let mut projection_predicates = Vec::new();
|
||||
for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() {
|
||||
match predicate.kind().skip_binder() {
|
||||
PredicateKind::Trait(trait_predicate) => {
|
||||
PredicateKind::Clause(Clause::Trait(trait_predicate)) => {
|
||||
if trait_predicate.trait_ref.self_ty() == input {
|
||||
trait_predicates.push(trait_predicate);
|
||||
}
|
||||
}
|
||||
PredicateKind::Projection(projection_predicate) => {
|
||||
PredicateKind::Clause(Clause::Projection(projection_predicate)) => {
|
||||
if projection_predicate.projection_ty.self_ty() == input {
|
||||
projection_predicates.push(projection_predicate);
|
||||
}
|
||||
@ -403,7 +403,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||
|
||||
let mut trait_predicates = cx.tcx.param_env(callee_def_id)
|
||||
.caller_bounds().iter().filter(|predicate| {
|
||||
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
|
||||
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
|
||||
&& trait_predicate.trait_ref.self_ty() == *param_ty {
|
||||
true
|
||||
} else {
|
||||
|
@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||
.filter_map(|obligation| {
|
||||
// Note that we do not want to deal with qualified predicates here.
|
||||
match obligation.predicate.kind().no_bound_vars() {
|
||||
Some(ty::PredicateKind::Trait(pred)) if pred.def_id() != sized_trait => Some(pred),
|
||||
Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => Some(pred),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
|
@ -19,7 +19,7 @@ use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::ty::{self, Binder, ExistentialPredicate, List, PredicateKind, Ty};
|
||||
use rustc_middle::ty::{self, Binder, Clause, ExistentialPredicate, List, PredicateKind, Ty};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::sym;
|
||||
@ -698,9 +698,8 @@ fn matches_preds<'tcx>(
|
||||
cx.tcx,
|
||||
ObligationCause::dummy(),
|
||||
cx.param_env,
|
||||
cx.tcx.mk_predicate(Binder::bind_with_vars(
|
||||
PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)),
|
||||
List::empty(),
|
||||
cx.tcx.mk_predicate(Binder::dummy(
|
||||
PredicateKind::Clause(Clause::Projection(p.with_self_ty(cx.tcx, ty))),
|
||||
)),
|
||||
)),
|
||||
ExistentialPredicate::AutoTrait(p) => infcx
|
||||
|
@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{Closure, Expr, ExprKind, StmtKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
|
||||
use rustc_middle::ty::{Clause, GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{sym, BytePos, Span};
|
||||
|
||||
@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
|
||||
let mut preds = Vec::new();
|
||||
for (pred, _) in generics.predicates {
|
||||
if_chain! {
|
||||
if let PredicateKind::Trait(poly_trait_pred) = pred.kind().skip_binder();
|
||||
if let PredicateKind::Clause(Clause::Trait(poly_trait_pred)) = pred.kind().skip_binder();
|
||||
let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred));
|
||||
if let Some(trait_def_id) = trait_id;
|
||||
if trait_def_id == trait_pred.trait_ref.def_id;
|
||||
@ -63,7 +63,7 @@ fn get_projection_pred<'tcx>(
|
||||
trait_pred: TraitPredicate<'tcx>,
|
||||
) -> Option<ProjectionPredicate<'tcx>> {
|
||||
generics.predicates.iter().find_map(|(proj_pred, _)| {
|
||||
if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(Clause::Projection(pred)) = proj_pred.kind().skip_binder() {
|
||||
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred));
|
||||
if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs {
|
||||
return Some(projection_pred);
|
||||
|
@ -73,7 +73,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg:
|
||||
.flat_map(|v| v.fields.iter())
|
||||
.any(|x| matches!(cx.tcx.type_of(x.did).peel_refs().kind(), ty::Param(_)))
|
||||
&& all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() {
|
||||
PredicateKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
|
||||
PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
|
||||
_ => true,
|
||||
})
|
||||
&& subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_)))
|
||||
|
@ -25,13 +25,13 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: Option<
|
||||
let predicates = tcx.predicates_of(current);
|
||||
for (predicate, _) in predicates.predicates {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(_)
|
||||
| ty::PredicateKind::TypeOutlives(_)
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::Projection(_)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
|
||||
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"),
|
||||
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"),
|
||||
|
@ -81,7 +81,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
|
||||
match predicate.kind().skip_binder() {
|
||||
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
||||
// and check substituions to find `U`.
|
||||
ty::PredicateKind::Trait(trait_predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
|
||||
if trait_predicate
|
||||
.trait_ref
|
||||
.substs
|
||||
@ -94,7 +94,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
|
||||
},
|
||||
// For `impl Trait<Assoc=U>`, it will register a predicate of `<T as Trait>::Assoc = U`,
|
||||
// so we check the term for `U`.
|
||||
ty::PredicateKind::Projection(projection_predicate) => {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) => {
|
||||
if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() {
|
||||
if contains_ty_adt_constructor_opaque(cx, ty, needle) {
|
||||
return true;
|
||||
@ -239,7 +239,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||
ty::Opaque(def_id, _) => {
|
||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||
if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
|
||||
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||
return true;
|
||||
}
|
||||
@ -658,7 +658,7 @@ fn sig_from_bounds<'tcx>(
|
||||
|
||||
for pred in predicates {
|
||||
match pred.kind().skip_binder() {
|
||||
PredicateKind::Trait(p)
|
||||
PredicateKind::Clause(ty::Clause::Trait(p))
|
||||
if (lang_items.fn_trait() == Some(p.def_id())
|
||||
|| lang_items.fn_mut_trait() == Some(p.def_id())
|
||||
|| lang_items.fn_once_trait() == Some(p.def_id()))
|
||||
@ -671,7 +671,7 @@ fn sig_from_bounds<'tcx>(
|
||||
}
|
||||
inputs = Some(i);
|
||||
},
|
||||
PredicateKind::Projection(p)
|
||||
PredicateKind::Clause(ty::Clause::Projection(p))
|
||||
if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output()
|
||||
&& p.projection_ty.self_ty() == ty =>
|
||||
{
|
||||
@ -699,7 +699,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
|
||||
.subst_iter_copied(cx.tcx, ty.substs)
|
||||
{
|
||||
match pred.kind().skip_binder() {
|
||||
PredicateKind::Trait(p)
|
||||
PredicateKind::Clause(ty::Clause::Trait(p))
|
||||
if (lang_items.fn_trait() == Some(p.def_id())
|
||||
|| lang_items.fn_mut_trait() == Some(p.def_id())
|
||||
|| lang_items.fn_once_trait() == Some(p.def_id())) =>
|
||||
@ -712,7 +712,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
|
||||
}
|
||||
inputs = Some(i);
|
||||
},
|
||||
PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => {
|
||||
PredicateKind::Clause(ty::Clause::Projection(p)) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => {
|
||||
if output.is_some() {
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
return None;
|
||||
@ -887,7 +887,7 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc
|
||||
predicates
|
||||
.iter()
|
||||
.try_fold(false, |found, p| {
|
||||
if let PredicateKind::Trait(p) = p.kind().skip_binder()
|
||||
if let PredicateKind::Clause(ty::Clause::Trait(p)) = p.kind().skip_binder()
|
||||
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
|
||||
&& ty.index == self_ty.index
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user