introduce newtype'd Predicate<'tcx>
This commit is contained in:
parent
034c25f33e
commit
f3164790bd
@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::relate::TypeRelation;
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
|
||||
use rustc_middle::ty::{self, BoundVar, Const, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
|
||||
use std::fmt::Debug;
|
||||
|
||||
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
@ -534,10 +534,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
match k1.unpack() {
|
||||
GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives(
|
||||
ty::Binder::bind(ty::OutlivesPredicate(r1, r2)),
|
||||
),
|
||||
)
|
||||
.to_predicate(self.tcx),
|
||||
GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind(
|
||||
ty::OutlivesPredicate(t1, r2),
|
||||
)),
|
||||
))
|
||||
.to_predicate(self.tcx),
|
||||
GenericArgKind::Const(..) => {
|
||||
// Consts cannot outlive one another, so we don't expect to
|
||||
// ecounter this branch.
|
||||
@ -666,7 +668,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
||||
param_env: self.param_env,
|
||||
predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
|
||||
sup, sub,
|
||||
))),
|
||||
)))
|
||||
.to_predicate(self.infcx.tcx),
|
||||
recursion_depth: 0,
|
||||
});
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{IntType, UintType};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
||||
self.obligations.push(Obligation::new(
|
||||
self.trace.cause.clone(),
|
||||
self.param_env,
|
||||
ty::PredicateKind::WellFormed(b_ty),
|
||||
ty::PredicateKind::WellFormed(b_ty).to_predicate(self.infcx.tcx),
|
||||
));
|
||||
}
|
||||
|
||||
@ -398,11 +398,15 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
||||
b: &'tcx ty::Const<'tcx>,
|
||||
) {
|
||||
let predicate = if a_is_expected {
|
||||
ty::Predicate::ConstEquate(a, b)
|
||||
ty::PredicateKind::ConstEquate(a, b)
|
||||
} else {
|
||||
ty::Predicate::ConstEquate(b, a)
|
||||
ty::PredicateKind::ConstEquate(b, a)
|
||||
};
|
||||
self.obligations.push(Obligation::new(self.trace.cause.clone(), self.param_env, predicate));
|
||||
self.obligations.push(Obligation::new(
|
||||
self.trace.cause.clone(),
|
||||
self.param_env,
|
||||
predicate.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ pub fn explicit_outlives_bounds<'tcx>(
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
|
||||
debug!("explicit_outlives_bounds()");
|
||||
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate {
|
||||
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate.kind() {
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
|
@ -6,7 +6,7 @@ use crate::traits::Obligation;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::TyVar;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||
use std::mem;
|
||||
|
||||
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
|
||||
@ -104,7 +104,8 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
|
||||
a_is_expected: self.a_is_expected,
|
||||
a,
|
||||
b,
|
||||
})),
|
||||
}))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
|
||||
Ok(a)
|
||||
|
@ -10,40 +10,49 @@ pub fn anonymize_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pred: &ty::Predicate<'tcx>,
|
||||
) -> ty::Predicate<'tcx> {
|
||||
match *pred {
|
||||
match pred.kind() {
|
||||
ty::PredicateKind::Trait(ref data, constness) => {
|
||||
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::RegionOutlives(ref data) => {
|
||||
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::TypeOutlives(ref data) => {
|
||||
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::Projection(ref data) => {
|
||||
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data))
|
||||
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
|
||||
ty::PredicateKind::WellFormed(data) => {
|
||||
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
|
||||
ty::PredicateKind::ObjectSafe(data) => {
|
||||
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::Subtype(ref data) => {
|
||||
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data))
|
||||
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs)
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
|
||||
}
|
||||
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2),
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +154,7 @@ impl Elaborator<'tcx> {
|
||||
|
||||
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
|
||||
let tcx = self.visited.tcx;
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
// Get predicates declared on the trait.
|
||||
let predicates = tcx.super_predicates_of(data.def_id());
|
||||
@ -250,8 +259,9 @@ impl Elaborator<'tcx> {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter(|p| visited.insert(p))
|
||||
.map(|p| predicate_obligation(p, None)),
|
||||
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
|
||||
.filter(|predicate| visited.insert(predicate))
|
||||
.map(|predicate| predicate_obligation(predicate, None)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -317,7 +327,7 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
|
||||
|
||||
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
|
||||
while let Some(obligation) = self.base_iterator.next() {
|
||||
if let ty::PredicateKind::Trait(data, _) = obligation.predicate {
|
||||
if let ty::PredicateKind::Trait(data, _) = obligation.predicate.kind() {
|
||||
return Some(data.to_poly_trait_ref());
|
||||
}
|
||||
}
|
||||
|
@ -1208,7 +1208,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
|
||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||
let predicates = cx.tcx.predicates_of(def_id);
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
let predicate_kind_name = match predicate {
|
||||
let predicate_kind_name = match predicate.kind() {
|
||||
Trait(..) => "Trait",
|
||||
TypeOutlives(..) |
|
||||
RegionOutlives(..) => "Lifetime",
|
||||
@ -1497,7 +1497,7 @@ impl ExplicitOutlivesRequirements {
|
||||
) -> Vec<ty::Region<'tcx>> {
|
||||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred {
|
||||
.filter_map(|(pred, _)| match pred.kind() {
|
||||
ty::PredicateKind::RegionOutlives(outlives) => {
|
||||
let outlives = outlives.skip_binder();
|
||||
match outlives.0 {
|
||||
@ -1516,7 +1516,7 @@ impl ExplicitOutlivesRequirements {
|
||||
) -> Vec<ty::Region<'tcx>> {
|
||||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred {
|
||||
.filter_map(|(pred, _)| match pred.kind() {
|
||||
ty::PredicateKind::TypeOutlives(outlives) => {
|
||||
let outlives = outlives.skip_binder();
|
||||
outlives.0.is_param(index).then_some(outlives.1)
|
||||
|
@ -146,7 +146,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
||||
ty::Opaque(def, _) => {
|
||||
let mut has_emitted = false;
|
||||
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate {
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
|
||||
predicate.kind()
|
||||
{
|
||||
let trait_ref = poly_trait_predicate.skip_binder().trait_ref;
|
||||
let def_id = trait_ref.def_id;
|
||||
let descr_pre =
|
||||
|
@ -10,7 +10,7 @@ use crate::arena::ArenaAllocatable;
|
||||
use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
|
||||
use crate::mir::{self, interpret::Allocation};
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{self, List, Ty, TyCtxt};
|
||||
use crate::ty::{self, List, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
|
||||
@ -196,7 +196,7 @@ where
|
||||
(0..decoder.read_usize()?)
|
||||
.map(|_| {
|
||||
// Handle shorthands first, if we have an usize > 0x80.
|
||||
let predicate = if decoder.positioned_at_shorthand() {
|
||||
let predicate_kind = if decoder.positioned_at_shorthand() {
|
||||
let pos = decoder.read_usize()?;
|
||||
assert!(pos >= SHORTHAND_OFFSET);
|
||||
let shorthand = pos - SHORTHAND_OFFSET;
|
||||
@ -205,6 +205,7 @@ where
|
||||
} else {
|
||||
ty::PredicateKind::decode(decoder)
|
||||
}?;
|
||||
let predicate = predicate_kind.to_predicate(tcx);
|
||||
Ok((predicate, Decodable::decode(decoder)?))
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
|
@ -29,7 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
|
||||
use crate::ty::{AdtDef, AdtKind, Const, Region};
|
||||
use crate::ty::{BindingMode, BoundVar};
|
||||
use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid};
|
||||
use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, ProjectionTy};
|
||||
use crate::ty::{
|
||||
ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy,
|
||||
};
|
||||
use crate::ty::{InferConst, ParamConst};
|
||||
use crate::ty::{List, TyKind, TyS};
|
||||
use rustc_ast::ast;
|
||||
@ -2103,6 +2105,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self.interners.intern_ty(st)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
|
||||
Predicate { kind }
|
||||
}
|
||||
|
||||
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
ast::IntTy::Isize => self.types.isize,
|
||||
|
@ -1016,7 +1016,17 @@ impl<'tcx> GenericPredicates<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub type Predicate<'tcx> = PredicateKind<'tcx>;
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)]
|
||||
#[derive(HashStable, TypeFoldable)]
|
||||
pub struct Predicate<'tcx> {
|
||||
kind: PredicateKind<'tcx>,
|
||||
}
|
||||
|
||||
impl Predicate<'tcx> {
|
||||
pub fn kind(&self) -> PredicateKind<'tcx> {
|
||||
self.kind
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
||||
#[derive(HashStable, TypeFoldable)]
|
||||
@ -1081,7 +1091,7 @@ impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PredicateKind<'tcx> {
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
/// Performs a substitution suitable for going from a
|
||||
/// poly-trait-ref to supertraits that must hold if that
|
||||
/// poly-trait-ref holds. This is slightly different from a normal
|
||||
@ -1153,7 +1163,7 @@ impl<'tcx> PredicateKind<'tcx> {
|
||||
// this trick achieves that).
|
||||
|
||||
let substs = &trait_ref.skip_binder().substs;
|
||||
match *self {
|
||||
match self.kind() {
|
||||
PredicateKind::Trait(ref binder, constness) => {
|
||||
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
|
||||
}
|
||||
@ -1181,6 +1191,7 @@ impl<'tcx> PredicateKind<'tcx> {
|
||||
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
|
||||
}
|
||||
}
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1298,57 +1309,67 @@ pub trait ToPredicate<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>;
|
||||
}
|
||||
|
||||
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::PredicateKind::Trait(
|
||||
ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }),
|
||||
self.constness,
|
||||
)
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::PredicateKind::Trait(
|
||||
ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }),
|
||||
self.constness,
|
||||
)
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness)
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness)
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::RegionOutlives(*self)
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::RegionOutlives(*self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::TypeOutlives(*self)
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::TypeOutlives(*self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
|
||||
fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Projection(*self)
|
||||
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Projection(*self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PredicateKind<'tcx> {
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_trait_ref(&self) -> Option<PolyTraitRef<'tcx>> {
|
||||
match *self {
|
||||
match self.kind() {
|
||||
PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
|
||||
PredicateKind::Projection(..)
|
||||
| PredicateKind::Subtype(..)
|
||||
@ -1363,7 +1384,7 @@ impl<'tcx> PredicateKind<'tcx> {
|
||||
}
|
||||
|
||||
pub fn to_opt_type_outlives(&self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
|
||||
match *self {
|
||||
match self.kind() {
|
||||
PredicateKind::TypeOutlives(data) => Some(data),
|
||||
PredicateKind::Trait(..)
|
||||
| PredicateKind::Projection(..)
|
||||
|
@ -2031,7 +2031,7 @@ define_print_and_forward_display! {
|
||||
}
|
||||
|
||||
ty::Predicate<'tcx> {
|
||||
match *self {
|
||||
match self.kind() {
|
||||
ty::PredicateKind::Trait(ref data, constness) => {
|
||||
if let hir::Constness::Const = constness {
|
||||
p!(write("const "));
|
||||
@ -2058,7 +2058,7 @@ define_print_and_forward_display! {
|
||||
print_value_path(def_id, substs),
|
||||
write("` can be evaluated"))
|
||||
}
|
||||
ty::Predicate::ConstEquate(c1, c2) => {
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
p!(write("the constant `"),
|
||||
print(c1),
|
||||
write("` equals `"),
|
||||
|
@ -219,6 +219,12 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::Predicate<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self.kind())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::PredicateKind<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
@ -242,7 +248,7 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
|
||||
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
|
||||
}
|
||||
ty::Predicate::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -469,8 +475,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
|
||||
type Lifted = ty::Predicate<'tcx>;
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
|
||||
type Lifted = ty::PredicateKind<'tcx>;
|
||||
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
||||
match *self {
|
||||
ty::PredicateKind::Trait(ref binder, constness) => {
|
||||
@ -500,8 +506,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
|
||||
tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs))
|
||||
}
|
||||
ty::Predicate::ConstEquate(c1, c2) => {
|
||||
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::Predicate::ConstEquate(c1, c2))
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -616,6 +616,7 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
|
||||
}
|
||||
ExistentialPredicate::Projection(p) => {
|
||||
ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty)))
|
||||
.to_predicate(tcx)
|
||||
}
|
||||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let trait_ref =
|
||||
|
@ -576,7 +576,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
let mut found = false;
|
||||
for predicate in bounds.predicates {
|
||||
if let ty::PredicateKind::TypeOutlives(binder) = predicate {
|
||||
if let ty::PredicateKind::TypeOutlives(binder) = predicate.kind() {
|
||||
if let ty::OutlivesPredicate(_, ty::RegionKind::ReStatic) =
|
||||
binder.skip_binder()
|
||||
{
|
||||
|
@ -27,8 +27,8 @@ use rustc_middle::ty::cast::CastTy;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts};
|
||||
use rustc_middle::ty::{
|
||||
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPolyTraitRef, Ty,
|
||||
TyCtxt, UserType, UserTypeAnnotationIndex,
|
||||
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPolyTraitRef,
|
||||
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
|
||||
};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
@ -1016,7 +1016,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
self.prove_predicate(
|
||||
ty::PredicateKind::WellFormed(inferred_ty),
|
||||
ty::PredicateKind::WellFormed(inferred_ty).to_predicate(self.tcx()),
|
||||
Locations::All(span),
|
||||
ConstraintCategory::TypeAnnotation,
|
||||
);
|
||||
@ -1268,7 +1268,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
obligations.obligations.push(traits::Obligation::new(
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(revealed_ty),
|
||||
ty::PredicateKind::WellFormed(revealed_ty).to_predicate(infcx.tcx),
|
||||
));
|
||||
obligations.add(
|
||||
infcx
|
||||
@ -2028,7 +2028,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
),
|
||||
}),
|
||||
hir::Constness::NotConst,
|
||||
),
|
||||
)
|
||||
.to_predicate(self.tcx()),
|
||||
),
|
||||
&traits::SelectionError::Unimplemented,
|
||||
false,
|
||||
@ -2708,11 +2709,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
|
||||
fn prove_predicates(
|
||||
&mut self,
|
||||
predicates: impl IntoIterator<Item = ty::Predicate<'tcx>>,
|
||||
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory,
|
||||
) {
|
||||
for predicate in predicates {
|
||||
let predicate = predicate.to_predicate(self.tcx());
|
||||
debug!("prove_predicates(predicate={:?}, locations={:?})", predicate, locations,);
|
||||
|
||||
self.prove_predicate(predicate, locations, category);
|
||||
|
@ -23,7 +23,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
|
||||
loop {
|
||||
let predicates = tcx.predicates_of(current);
|
||||
for (predicate, _) in predicates.predicates {
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::RegionOutlives(_)
|
||||
| ty::PredicateKind::TypeOutlives(_)
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
@ -46,7 +46,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
|
||||
match pred.skip_binder().self_ty().kind {
|
||||
ty::Param(ref p) => {
|
||||
// Allow `T: ?const Trait`
|
||||
if *constness == hir::Constness::NotConst
|
||||
if constness == hir::Constness::NotConst
|
||||
&& feature_allowed(tcx, def_id, sym::const_trait_bound_opt_out)
|
||||
{
|
||||
continue;
|
||||
|
@ -90,7 +90,7 @@ where
|
||||
fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool {
|
||||
let ty::GenericPredicates { parent: _, predicates } = predicates;
|
||||
for (predicate, _span) in predicates {
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(poly_predicate, _) => {
|
||||
let ty::TraitPredicate { trait_ref } = *poly_predicate.skip_binder();
|
||||
if self.visit_trait(trait_ref) {
|
||||
|
@ -1168,7 +1168,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
|
||||
|
||||
for predicate in &bounds.predicates {
|
||||
if let ty::PredicateKind::Projection(projection) = &predicate {
|
||||
if let ty::PredicateKind::Projection(projection) = predicate.kind() {
|
||||
if projection.skip_binder().ty.references_error() {
|
||||
// No point on adding these obligations since there's a type error involved.
|
||||
return ty_var;
|
||||
@ -1269,7 +1269,7 @@ crate fn required_region_bounds(
|
||||
traits::elaborate_predicates(tcx, predicates)
|
||||
.filter_map(|obligation| {
|
||||
debug!("required_region_bounds(obligation={:?})", obligation);
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
|
@ -341,7 +341,8 @@ impl AutoTraitFinder<'tcx> {
|
||||
already_visited.remove(&pred);
|
||||
self.add_user_pred(
|
||||
&mut user_computed_preds,
|
||||
ty::PredicateKind::Trait(pred, hir::Constness::NotConst),
|
||||
ty::PredicateKind::Trait(pred, hir::Constness::NotConst)
|
||||
.to_predicate(self.tcx),
|
||||
);
|
||||
predicates.push_back(pred);
|
||||
} else {
|
||||
@ -412,9 +413,9 @@ impl AutoTraitFinder<'tcx> {
|
||||
let mut should_add_new = true;
|
||||
user_computed_preds.retain(|&old_pred| {
|
||||
if let (
|
||||
&ty::PredicateKind::Trait(new_trait, _),
|
||||
ty::PredicateKind::Trait(new_trait, _),
|
||||
ty::PredicateKind::Trait(old_trait, _),
|
||||
) = (&new_pred, old_pred)
|
||||
) = (new_pred.kind(), old_pred.kind())
|
||||
{
|
||||
if new_trait.def_id() == old_trait.def_id() {
|
||||
let new_substs = new_trait.skip_binder().trait_ref.substs;
|
||||
@ -632,8 +633,8 @@ impl AutoTraitFinder<'tcx> {
|
||||
//
|
||||
// We check this by calling is_of_param on the relevant types
|
||||
// from the various possible predicates
|
||||
match &predicate {
|
||||
&ty::PredicateKind::Trait(p, _) => {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(p, _) => {
|
||||
if self.is_param_no_infer(p.skip_binder().trait_ref.substs)
|
||||
&& !only_projections
|
||||
&& is_new_pred
|
||||
@ -642,7 +643,7 @@ impl AutoTraitFinder<'tcx> {
|
||||
}
|
||||
predicates.push_back(p);
|
||||
}
|
||||
&ty::PredicateKind::Projection(p) => {
|
||||
ty::PredicateKind::Projection(p) => {
|
||||
debug!(
|
||||
"evaluate_nested_obligations: examining projection predicate {:?}",
|
||||
predicate
|
||||
@ -767,12 +768,12 @@ impl AutoTraitFinder<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
&ty::PredicateKind::RegionOutlives(ref binder) => {
|
||||
ty::PredicateKind::RegionOutlives(ref binder) => {
|
||||
if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
&ty::PredicateKind::TypeOutlives(ref binder) => {
|
||||
ty::PredicateKind::TypeOutlives(ref binder) => {
|
||||
match (
|
||||
binder.no_bound_vars(),
|
||||
binder.map_bound_ref(|pred| pred.0).no_bound_vars(),
|
||||
|
@ -252,7 +252,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
.emit();
|
||||
return;
|
||||
}
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref trait_predicate, _) => {
|
||||
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
|
||||
|
||||
@ -471,7 +471,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
predicate: ty::PredicateKind::Trait(
|
||||
predicate,
|
||||
hir::Constness::NotConst,
|
||||
),
|
||||
)
|
||||
.to_predicate(self.tcx),
|
||||
..obligation.clone()
|
||||
};
|
||||
if self.predicate_may_hold(&unit_obligation) {
|
||||
@ -616,7 +617,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
ty::Predicate::ConstEquate(..) => {
|
||||
ty::PredicateKind::ConstEquate(..) => {
|
||||
// Errors for `ConstEquate` predicates show up as
|
||||
// `SelectionError::ConstEvalFailure`,
|
||||
// not `Unimplemented`.
|
||||
@ -1046,10 +1047,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
return true;
|
||||
}
|
||||
|
||||
let (cond, error) = match (cond, error) {
|
||||
(&ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(ref error, _)) => {
|
||||
(cond, error)
|
||||
}
|
||||
let (cond, error) = match (cond.kind(), error.kind()) {
|
||||
(ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => (cond, error),
|
||||
_ => {
|
||||
// FIXME: make this work in other cases too.
|
||||
return false;
|
||||
@ -1057,7 +1056,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
};
|
||||
|
||||
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(*cond)) {
|
||||
if let ty::PredicateKind::Trait(implication, _) = obligation.predicate {
|
||||
if let ty::PredicateKind::Trait(implication, _) = obligation.predicate.kind() {
|
||||
let error = error.to_poly_trait_ref();
|
||||
let implication = implication.to_poly_trait_ref();
|
||||
// FIXME: I'm just not taking associated types at all here.
|
||||
@ -1137,7 +1136,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
//
|
||||
// this can fail if the problem was higher-ranked, in which
|
||||
// cause I have no idea for a good error message.
|
||||
if let ty::PredicateKind::Projection(ref data) = predicate {
|
||||
if let ty::PredicateKind::Projection(ref data) = predicate.kind() {
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
let (data, _) = self.replace_bound_vars_with_fresh_vars(
|
||||
obligation.cause.span,
|
||||
@ -1417,7 +1416,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut err = match predicate {
|
||||
let mut err = match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
let trait_ref = data.to_poly_trait_ref();
|
||||
let self_ty = trait_ref.self_ty();
|
||||
@ -1662,7 +1661,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
if let (
|
||||
ty::PredicateKind::Trait(pred, _),
|
||||
ObligationCauseCode::BindingObligation(item_def_id, span),
|
||||
) = (&obligation.predicate, &obligation.cause.code)
|
||||
) = (obligation.predicate.kind(), &obligation.cause.code)
|
||||
{
|
||||
if let (Some(generics), true) = (
|
||||
self.tcx.hir().get_if_local(*item_def_id).as_ref().and_then(|n| n.generics()),
|
||||
|
@ -1242,7 +1242,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// the type. The last generator (`outer_generator` below) has information about where the
|
||||
// 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 {
|
||||
let (mut trait_ref, mut target_ty) = match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(p, _) => {
|
||||
(Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
let infcx = self.selcx.infcx();
|
||||
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
let trait_obligation = obligation.with(*data);
|
||||
|
||||
@ -523,7 +523,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::Predicate::ConstEquate(c1, c2) => {
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
|
||||
|
||||
let stalled_on = &mut pending_obligation.stalled_on;
|
||||
|
@ -333,7 +333,7 @@ pub fn normalize_param_env_or_error<'tcx>(
|
||||
// This works fairly well because trait matching does not actually care about param-env
|
||||
// TypeOutlives predicates - these are normally used by regionck.
|
||||
let outlives_predicates: Vec<_> = predicates
|
||||
.drain_filter(|predicate| match predicate {
|
||||
.drain_filter(|predicate| match predicate.kind() {
|
||||
ty::PredicateKind::TypeOutlives(..) => true,
|
||||
_ => false,
|
||||
})
|
||||
|
@ -245,7 +245,7 @@ fn predicates_reference_self(
|
||||
.iter()
|
||||
.map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
|
||||
.filter_map(|(predicate, &sp)| {
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
// In the case of a trait predicate, we can skip the "self" type.
|
||||
if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) {
|
||||
@ -304,19 +304,22 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
// Search for a predicate like `Self : Sized` amongst the trait bounds.
|
||||
let predicates = tcx.predicates_of(def_id);
|
||||
let predicates = predicates.instantiate_identity(tcx).predicates;
|
||||
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| match obligation.predicate {
|
||||
ty::PredicateKind::Trait(ref trait_pred, _) => {
|
||||
trait_pred.def_id() == sized_def_id && trait_pred.skip_binder().self_ty().is_param(0)
|
||||
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref trait_pred, _) => {
|
||||
trait_pred.def_id() == sized_def_id
|
||||
&& trait_pred.skip_binder().self_ty().is_param(0)
|
||||
}
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => false,
|
||||
}
|
||||
ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => false,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
|
||||
let mut obligations: Vec<_> = result
|
||||
.obligations
|
||||
.iter()
|
||||
.filter(|obligation| match obligation.predicate {
|
||||
.filter(|obligation| match obligation.predicate.kind() {
|
||||
// We found a `T: Foo<X = U>` predicate, let's check
|
||||
// if `U` references any unresolved type
|
||||
// variables. In principle, we only care if this
|
||||
@ -930,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
|
||||
let infcx = selcx.infcx();
|
||||
for predicate in env_predicates {
|
||||
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
|
||||
if let ty::PredicateKind::Projection(data) = predicate {
|
||||
if let ty::PredicateKind::Projection(data) = predicate.kind() {
|
||||
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
|
||||
|
||||
let is_match = same_def_id
|
||||
@ -1166,7 +1166,7 @@ fn confirm_object_candidate<'cx, 'tcx>(
|
||||
|
||||
// select only those projections that are actually projecting an
|
||||
// item with the correct name
|
||||
let env_predicates = env_predicates.filter_map(|o| match o.predicate {
|
||||
let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() {
|
||||
ty::PredicateKind::Projection(data) => {
|
||||
if data.projection_def_id() == obligation.predicate.item_def_id {
|
||||
Some(data)
|
||||
|
@ -15,7 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
|
||||
// `&T`, accounts for about 60% percentage of the predicates
|
||||
// we have to prove. No need to canonicalize and all that for
|
||||
// such cases.
|
||||
if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate {
|
||||
if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind() {
|
||||
if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
|
||||
if trait_ref.def_id() == sized_def_id {
|
||||
if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) {
|
||||
|
@ -413,7 +413,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
None => self.check_recursion_limit(&obligation, &obligation)?,
|
||||
}
|
||||
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref t, _) => {
|
||||
debug_assert!(!t.has_escaping_bound_vars());
|
||||
let obligation = obligation.with(*t);
|
||||
@ -510,7 +510,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
ty::Predicate::ConstEquate(c1, c2) => {
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
debug!("evaluate_predicate_recursively: equating consts c1={:?} c2={:?}", c1, c2);
|
||||
|
||||
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
||||
@ -675,8 +675,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// trait refs. This is important because it's only a cycle
|
||||
// if the regions match exactly.
|
||||
let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
|
||||
let tcx = self.tcx();
|
||||
let cycle = cycle.map(|stack| {
|
||||
ty::PredicateKind::Trait(stack.obligation.predicate, hir::Constness::NotConst)
|
||||
.to_predicate(tcx)
|
||||
});
|
||||
if self.coinductive_match(cycle) {
|
||||
debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref);
|
||||
@ -791,7 +793,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
|
||||
let result = match predicate {
|
||||
let result = match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
|
||||
_ => false,
|
||||
};
|
||||
@ -2921,7 +2923,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
obligations.push(Obligation::new(
|
||||
obligation.cause.clone(),
|
||||
obligation.param_env,
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind),
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ pub fn predicate_obligations<'a, 'tcx>(
|
||||
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
||||
|
||||
// (*) ok to skip binders, because wf code is prepared for it
|
||||
match *predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref t, _) => {
|
||||
wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*)
|
||||
}
|
||||
@ -102,7 +102,7 @@ pub fn predicate_obligations<'a, 'tcx>(
|
||||
wf.compute(ty);
|
||||
}
|
||||
}
|
||||
ty::Predicate::ConstEquate(c1, c2) => {
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
wf.compute(c1.ty);
|
||||
wf.compute(c2.ty);
|
||||
}
|
||||
@ -170,7 +170,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
||||
hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::TyAlias(ty) => ty.span,
|
||||
_ => impl_item_ref.span,
|
||||
};
|
||||
match pred {
|
||||
match pred.kind() {
|
||||
ty::PredicateKind::Projection(proj) => {
|
||||
// The obligation comes not from the current `impl` nor the `trait` being
|
||||
// implemented, but rather from a "second order" obligation, like in
|
||||
@ -216,6 +216,10 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
fn cause(&mut self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
|
||||
traits::ObligationCause::new(self.span, self.body_id, code)
|
||||
}
|
||||
@ -275,9 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
self.out.extend(obligations);
|
||||
}
|
||||
|
||||
let tcx = self.tcx();
|
||||
self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map(
|
||||
|ty| {
|
||||
traits::Obligation::new(cause.clone(), param_env, ty::PredicateKind::WellFormed(ty))
|
||||
traits::Obligation::new(
|
||||
cause.clone(),
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(ty).to_predicate(tcx),
|
||||
)
|
||||
},
|
||||
));
|
||||
}
|
||||
@ -307,7 +316,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
let obligations = self.nominal_obligations(def_id, substs);
|
||||
self.out.extend(obligations);
|
||||
|
||||
let predicate = ty::PredicateKind::ConstEvaluatable(def_id, substs);
|
||||
let predicate =
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(self.tcx());
|
||||
let cause = self.cause(traits::MiscObligation);
|
||||
self.out.push(traits::Obligation::new(cause, self.param_env, predicate));
|
||||
}
|
||||
@ -415,7 +425,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
param_env,
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(
|
||||
ty::OutlivesPredicate(rty, r),
|
||||
)),
|
||||
))
|
||||
.to_predicate(self.tcx()),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -495,16 +506,17 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
// obligations that don't refer to Self and
|
||||
// checking those
|
||||
|
||||
let defer_to_coercion = self.infcx.tcx.features().object_safe_for_dispatch;
|
||||
let defer_to_coercion = self.tcx().features().object_safe_for_dispatch;
|
||||
|
||||
if !defer_to_coercion {
|
||||
let cause = self.cause(traits::MiscObligation);
|
||||
let component_traits = data.auto_traits().chain(data.principal_def_id());
|
||||
let tcx = self.tcx();
|
||||
self.out.extend(component_traits.map(|did| {
|
||||
traits::Obligation::new(
|
||||
cause.clone(),
|
||||
param_env,
|
||||
ty::PredicateKind::ObjectSafe(did),
|
||||
ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
|
||||
)
|
||||
}));
|
||||
}
|
||||
@ -530,7 +542,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
self.out.push(traits::Obligation::new(
|
||||
cause,
|
||||
param_env,
|
||||
ty::PredicateKind::WellFormed(ty),
|
||||
ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx()),
|
||||
));
|
||||
} else {
|
||||
// Yes, resolved, proceed with the result.
|
||||
|
@ -38,8 +38,7 @@ use rustc_middle::traits::{
|
||||
use rustc_middle::ty::fold::TypeFolder;
|
||||
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, BoundRegion, Predicate, Region, RegionKind, Ty, TyCtxt, TyKind, TypeFoldable,
|
||||
TypeVisitor,
|
||||
self, Binder, BoundRegion, Region, RegionKind, Ty, TyCtxt, TyKind, TypeFoldable, TypeVisitor,
|
||||
};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
||||
@ -78,8 +77,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
|
||||
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
|
||||
let clauses = self.environment.into_iter().filter_map(|clause| match clause {
|
||||
ChalkEnvironmentClause::Predicate(predicate) => {
|
||||
match predicate {
|
||||
ty::Predicate::Trait(predicate, _) => {
|
||||
match &predicate.kind() {
|
||||
ty::PredicateKind::Trait(predicate, _) => {
|
||||
let (predicate, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, predicate);
|
||||
|
||||
@ -100,9 +99,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
|
||||
)
|
||||
}
|
||||
// FIXME(chalk): need to add RegionOutlives/TypeOutlives
|
||||
ty::Predicate::RegionOutlives(_) => None,
|
||||
ty::Predicate::TypeOutlives(_) => None,
|
||||
ty::Predicate::Projection(predicate) => {
|
||||
ty::PredicateKind::RegionOutlives(_) => None,
|
||||
ty::PredicateKind::TypeOutlives(_) => None,
|
||||
ty::PredicateKind::Projection(predicate) => {
|
||||
let (predicate, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, predicate);
|
||||
|
||||
@ -122,12 +121,14 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
|
||||
.intern(interner),
|
||||
)
|
||||
}
|
||||
ty::Predicate::WellFormed(..)
|
||||
| ty::Predicate::ObjectSafe(..)
|
||||
| ty::Predicate::ClosureKind(..)
|
||||
| ty::Predicate::Subtype(..)
|
||||
| ty::Predicate::ConstEvaluatable(..)
|
||||
| ty::Predicate::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
|
||||
ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => {
|
||||
bug!("unexpected predicate {}", predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
ChalkEnvironmentClause::TypeFromEnv(ty) => Some(
|
||||
@ -154,17 +155,17 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
|
||||
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
|
||||
match self {
|
||||
Predicate::Trait(predicate, _) => predicate.lower_into(interner),
|
||||
match self.kind() {
|
||||
ty::PredicateKind::Trait(predicate, _) => predicate.lower_into(interner),
|
||||
// FIXME(chalk): we need to register constraints.
|
||||
Predicate::RegionOutlives(_predicate) => {
|
||||
ty::PredicateKind::RegionOutlives(_predicate) => {
|
||||
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
|
||||
}
|
||||
Predicate::TypeOutlives(_predicate) => {
|
||||
ty::PredicateKind::TypeOutlives(_predicate) => {
|
||||
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
|
||||
}
|
||||
Predicate::Projection(predicate) => predicate.lower_into(interner),
|
||||
Predicate::WellFormed(ty) => match ty.kind {
|
||||
ty::PredicateKind::Projection(predicate) => predicate.lower_into(interner),
|
||||
ty::PredicateKind::WellFormed(ty) => match ty.kind {
|
||||
// These types are always WF.
|
||||
ty::Str | ty::Placeholder(..) | ty::Error | ty::Never => {
|
||||
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
|
||||
@ -188,11 +189,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
|
||||
//
|
||||
// We can defer this, but ultimately we'll want to express
|
||||
// some of these in terms of chalk operations.
|
||||
Predicate::ObjectSafe(..)
|
||||
| Predicate::ClosureKind(..)
|
||||
| Predicate::Subtype(..)
|
||||
| Predicate::ConstEvaluatable(..)
|
||||
| Predicate::ConstEquate(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
|
||||
ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => {
|
||||
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -439,8 +442,8 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
|
||||
self,
|
||||
interner: &RustInterner<'tcx>,
|
||||
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
|
||||
match &self {
|
||||
Predicate::Trait(predicate, _) => {
|
||||
match &self.kind() {
|
||||
ty::PredicateKind::Trait(predicate, _) => {
|
||||
let (predicate, binders, _named_regions) =
|
||||
collect_bound_vars(interner, interner.tcx, predicate);
|
||||
|
||||
@ -449,16 +452,16 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
|
||||
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
|
||||
))
|
||||
}
|
||||
Predicate::RegionOutlives(_predicate) => None,
|
||||
Predicate::TypeOutlives(_predicate) => None,
|
||||
Predicate::Projection(_predicate) => None,
|
||||
Predicate::WellFormed(_ty) => None,
|
||||
ty::PredicateKind::RegionOutlives(_predicate) => None,
|
||||
ty::PredicateKind::TypeOutlives(_predicate) => None,
|
||||
ty::PredicateKind::Projection(_predicate) => None,
|
||||
ty::PredicateKind::WellFormed(_ty) => None,
|
||||
|
||||
Predicate::ObjectSafe(..)
|
||||
| Predicate::ClosureKind(..)
|
||||
| Predicate::Subtype(..)
|
||||
| Predicate::ConstEvaluatable(..)
|
||||
| Predicate::ConstEquate(..) => bug!("unexpected predicate {}", &self),
|
||||
ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
// region relationships.
|
||||
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
|
||||
assert!(!obligation.has_escaping_bound_vars());
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
|
@ -40,7 +40,7 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
|
||||
}
|
||||
|
||||
fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
|
||||
match p {
|
||||
match p.kind() {
|
||||
ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
|
||||
ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
|
@ -7,8 +7,8 @@ use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
|
||||
use rustc_middle::ty::{
|
||||
self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable,
|
||||
Variance,
|
||||
self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, ToPredicate, Ty, TyCtxt,
|
||||
TypeFoldable, Variance,
|
||||
};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::infer::InferCtxtBuilderExt;
|
||||
@ -141,7 +141,9 @@ impl AscribeUserTypeCx<'me, 'tcx> {
|
||||
|
||||
self.relate(self_ty, Variance::Invariant, impl_self_ty)?;
|
||||
|
||||
self.prove_predicate(ty::PredicateKind::WellFormed(impl_self_ty));
|
||||
self.prove_predicate(
|
||||
ty::PredicateKind::WellFormed(impl_self_ty).to_predicate(self.tcx()),
|
||||
);
|
||||
}
|
||||
|
||||
// In addition to proving the predicates, we have to
|
||||
@ -155,7 +157,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
|
||||
// them? This would only be relevant if some input
|
||||
// type were ill-formed but did not appear in `ty`,
|
||||
// which...could happen with normalization...
|
||||
self.prove_predicate(ty::PredicateKind::WellFormed(ty));
|
||||
self.prove_predicate(ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1596,7 +1596,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
"conv_object_ty_poly_trait_ref: observing object predicate `{:?}`",
|
||||
obligation.predicate
|
||||
);
|
||||
match obligation.predicate {
|
||||
match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(pred, _) => {
|
||||
associated_types.entry(span).or_default().extend(
|
||||
tcx.associated_items(pred.def_id())
|
||||
|
@ -12,7 +12,7 @@ use rustc_infer::infer::LateBoundRegionConversionTime;
|
||||
use rustc_infer::infer::{InferOk, InferResult};
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::{self, GenericParamDefKind, Ty};
|
||||
use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_trait_selection::traits::error_reporting::ArgKind;
|
||||
@ -206,7 +206,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
obligation.predicate
|
||||
);
|
||||
|
||||
if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate {
|
||||
if let ty::PredicateKind::Projection(ref proj_predicate) =
|
||||
obligation.predicate.kind()
|
||||
{
|
||||
// Given a Projection predicate, we can potentially infer
|
||||
// the complete signature.
|
||||
self.deduce_sig_from_projection(Some(obligation.cause.span), proj_predicate)
|
||||
@ -529,7 +531,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
|
||||
supplied_ty,
|
||||
closure_body_region,
|
||||
))),
|
||||
)))
|
||||
.to_predicate(self.tcx),
|
||||
));
|
||||
}
|
||||
|
||||
@ -641,7 +644,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// where R is the return type we are expecting. This type `T`
|
||||
// will be our output.
|
||||
let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
|
||||
if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate {
|
||||
if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate.kind() {
|
||||
self.deduce_future_output_from_projection(obligation.cause.span, proj_predicate)
|
||||
} else {
|
||||
None
|
||||
|
@ -596,7 +596,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
while !queue.is_empty() {
|
||||
let obligation = queue.remove(0);
|
||||
debug!("coerce_unsized resolve step: {:?}", obligation);
|
||||
let trait_pred = match obligation.predicate {
|
||||
let trait_pred = match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(trait_pred, _)
|
||||
if traits.contains(&trait_pred.def_id()) =>
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::{CloneTraitLangItem, DerefTraitLangItem};
|
||||
use rustc_hir::{is_range_literal, Node};
|
||||
use rustc_middle::ty::adjustment::AllowTwoPhase;
|
||||
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, AssocItem, ToPredicate, Ty, TypeAndMut};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -654,7 +654,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
},
|
||||
// `U`
|
||||
ty: expected,
|
||||
}));
|
||||
}))
|
||||
.to_predicate(self.tcx);
|
||||
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
|
||||
let impls_deref = self.infcx.predicate_may_hold(&obligation);
|
||||
|
||||
|
@ -230,12 +230,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
||||
// could be extended easily also to the other `Predicate`.
|
||||
let predicate_matches_closure = |p: &'_ Predicate<'tcx>| {
|
||||
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
|
||||
match (predicate, p) {
|
||||
match (predicate.kind(), p.kind()) {
|
||||
(ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
|
||||
relator.relate(a, b).is_ok()
|
||||
relator.relate(&a, &b).is_ok()
|
||||
}
|
||||
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
|
||||
relator.relate(a, b).is_ok()
|
||||
relator.relate(&a, &b).is_ok()
|
||||
}
|
||||
_ => predicate == p,
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||
};
|
||||
|
||||
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
|
||||
.filter_map(|obligation| match obligation.predicate {
|
||||
.filter_map(|obligation| match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => {
|
||||
let span = predicates
|
||||
.predicates
|
||||
|
@ -401,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
obligations.push(traits::Obligation::new(
|
||||
cause,
|
||||
self.param_env,
|
||||
ty::PredicateKind::WellFormed(method_ty),
|
||||
ty::PredicateKind::WellFormed(method_ty).to_predicate(tcx),
|
||||
));
|
||||
|
||||
let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig };
|
||||
|
@ -796,23 +796,26 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
||||
// FIXME: do we want to commit to this behavior for param bounds?
|
||||
|
||||
let bounds = self.param_env.caller_bounds.iter().filter_map(|predicate| match *predicate {
|
||||
ty::PredicateKind::Trait(ref trait_predicate, _) => {
|
||||
match trait_predicate.skip_binder().trait_ref.self_ty().kind {
|
||||
ty::Param(ref p) if *p == param_ty => Some(trait_predicate.to_poly_trait_ref()),
|
||||
_ => None,
|
||||
let bounds =
|
||||
self.param_env.caller_bounds.iter().filter_map(|predicate| match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref trait_predicate, _) => {
|
||||
match trait_predicate.skip_binder().trait_ref.self_ty().kind {
|
||||
ty::Param(ref p) if *p == param_ty => {
|
||||
Some(trait_predicate.to_poly_trait_ref())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => None,
|
||||
});
|
||||
ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Projection(..)
|
||||
| ty::PredicateKind::RegionOutlives(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::TypeOutlives(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
| ty::PredicateKind::ConstEquate(..) => None,
|
||||
});
|
||||
|
||||
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
|
||||
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);
|
||||
|
@ -575,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut collect_type_param_suggestions =
|
||||
|self_ty: Ty<'_>, parent_pred: &ty::Predicate<'_>, obligation: &str| {
|
||||
if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) =
|
||||
(&self_ty.kind, parent_pred)
|
||||
(&self_ty.kind, parent_pred.kind())
|
||||
{
|
||||
if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind {
|
||||
let node = def.did.as_local().map(|def_id| {
|
||||
@ -626,8 +626,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
let mut format_pred = |pred| {
|
||||
match pred {
|
||||
let mut format_pred = |pred: ty::Predicate<'tcx>| {
|
||||
match pred.kind() {
|
||||
ty::PredicateKind::Projection(pred) => {
|
||||
// `<Foo as Iterator>::Item = String`.
|
||||
let trait_ref =
|
||||
@ -946,7 +946,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// this isn't perfect (that is, there are cases when
|
||||
// implementing a trait would be legal but is rejected
|
||||
// here).
|
||||
unsatisfied_predicates.iter().all(|(p, _)| match p {
|
||||
unsatisfied_predicates.iter().all(|(p, _)| match p.kind() {
|
||||
// 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,
|
||||
|
@ -2223,7 +2223,7 @@ fn bounds_from_generic_predicates(
|
||||
let mut projections = vec![];
|
||||
for (predicate, _) in predicates.predicates {
|
||||
debug!("predicate {:?}", predicate);
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(trait_predicate, _) => {
|
||||
let entry = types.entry(trait_predicate.skip_binder().self_ty()).or_default();
|
||||
let def_id = trait_predicate.skip_binder().def_id();
|
||||
@ -2769,7 +2769,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||
ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: tcx.arena.alloc_from_iter(self.param_env.caller_bounds.iter().filter_map(
|
||||
|&predicate| match predicate {
|
||||
|&predicate| match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _)
|
||||
if data.skip_binder().self_ty().is_param(index) =>
|
||||
{
|
||||
@ -3379,7 +3379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.register_predicate(traits::Obligation::new(
|
||||
cause,
|
||||
self.param_env,
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs),
|
||||
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(self.tcx),
|
||||
));
|
||||
}
|
||||
|
||||
@ -3428,7 +3428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.register_predicate(traits::Obligation::new(
|
||||
cause,
|
||||
self.param_env,
|
||||
ty::PredicateKind::WellFormed(ty),
|
||||
ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx),
|
||||
));
|
||||
}
|
||||
|
||||
@ -3857,7 +3857,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.borrow()
|
||||
.pending_obligations()
|
||||
.into_iter()
|
||||
.filter_map(move |obligation| match obligation.predicate {
|
||||
.filter_map(move |obligation| match obligation.predicate.kind() {
|
||||
ty::PredicateKind::Projection(ref data) => {
|
||||
Some((data.to_poly_trait_ref(self.tcx), obligation))
|
||||
}
|
||||
@ -4208,7 +4208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate {
|
||||
if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate.kind() {
|
||||
// Collect the argument position for all arguments that could have caused this
|
||||
// `FulfillmentError`.
|
||||
let mut referenced_in = final_arg_types
|
||||
@ -4255,7 +4255,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
if let hir::ExprKind::Path(qpath) = &path.kind {
|
||||
if let hir::QPath::Resolved(_, path) = &qpath {
|
||||
for error in errors {
|
||||
if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate {
|
||||
if let ty::PredicateKind::Trait(predicate, _) =
|
||||
error.obligation.predicate.kind()
|
||||
{
|
||||
// If any of the type arguments in this path segment caused the
|
||||
// `FullfillmentError`, point at its span (#61860).
|
||||
for arg in path
|
||||
@ -5327,7 +5329,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate {
|
||||
projection_ty,
|
||||
ty: expected,
|
||||
}));
|
||||
}))
|
||||
.to_predicate(self.tcx);
|
||||
let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate);
|
||||
|
||||
debug!("suggest_missing_await: trying obligation {:?}", obligation);
|
||||
|
@ -425,7 +425,8 @@ fn check_type_defn<'tcx, F>(
|
||||
fcx.register_predicate(traits::Obligation::new(
|
||||
cause,
|
||||
fcx.param_env,
|
||||
ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs),
|
||||
ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs)
|
||||
.to_predicate(fcx.tcx),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ fn type_param_predicates(
|
||||
let extra_predicates = extend.into_iter().chain(
|
||||
icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
|
||||
.into_iter()
|
||||
.filter(|(predicate, _)| match predicate {
|
||||
.filter(|(predicate, _)| match predicate.kind() {
|
||||
ty::PredicateKind::Trait(ref data, _) => {
|
||||
data.skip_binder().self_ty().is_param(index)
|
||||
}
|
||||
@ -996,7 +996,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
|
||||
// which will, in turn, reach indirect supertraits.
|
||||
for &(pred, span) in superbounds {
|
||||
debug!("superbound: {:?}", pred);
|
||||
if let ty::PredicateKind::Trait(bound, _) = pred {
|
||||
if let ty::PredicateKind::Trait(bound, _) = pred.kind() {
|
||||
tcx.at(span).super_predicates_of(bound.def_id());
|
||||
}
|
||||
}
|
||||
@ -1901,7 +1901,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||
let re_root_empty = tcx.lifetimes.re_root_empty;
|
||||
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
|
||||
predicates.push((
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate)),
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate))
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
));
|
||||
}
|
||||
@ -1930,7 +1931,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||
&hir::GenericBound::Outlives(ref lifetime) => {
|
||||
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
|
||||
let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region));
|
||||
predicates.push((ty::PredicateKind::TypeOutlives(pred), lifetime.span))
|
||||
predicates.push((
|
||||
ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx),
|
||||
lifetime.span,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1947,7 +1951,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
|
||||
};
|
||||
let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
|
||||
|
||||
(ty::PredicateKind::RegionOutlives(pred), span)
|
||||
(ty::PredicateKind::RegionOutlives(pred).to_predicate(icx.tcx), span)
|
||||
}))
|
||||
}
|
||||
|
||||
@ -2118,7 +2122,7 @@ fn predicates_from_bound<'tcx>(
|
||||
hir::GenericBound::Outlives(ref lifetime) => {
|
||||
let region = astconv.ast_region_to_region(lifetime, None);
|
||||
let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region));
|
||||
vec![(ty::PredicateKind::TypeOutlives(pred), lifetime.span)]
|
||||
vec![(ty::PredicateKind::TypeOutlives(pred).to_predicate(astconv.tcx()), lifetime.span)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ pub fn setup_constraining_predicates<'tcx>(
|
||||
changed = false;
|
||||
|
||||
for j in i..predicates.len() {
|
||||
if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0 {
|
||||
if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0.kind() {
|
||||
// Note that we can skip binder here because the impl
|
||||
// trait ref never contains any late-bound regions.
|
||||
let projection = poly_projection.skip_binder();
|
||||
|
@ -204,7 +204,7 @@ 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 {
|
||||
if let ty::PredicateKind::Projection(proj) = predicate.kind() {
|
||||
let projection_ty = proj.skip_binder().projection_ty;
|
||||
let projected_ty = proj.skip_binder().ty;
|
||||
|
||||
@ -368,7 +368,7 @@ fn check_predicates<'tcx>(
|
||||
|
||||
fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: &ty::Predicate<'tcx>, span: Span) {
|
||||
debug!("can_specialize_on(predicate = {:?})", predicate);
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
// Global predicates are either always true or always false, so we
|
||||
// are fine to specialize on.
|
||||
_ if predicate.is_global() => (),
|
||||
@ -401,7 +401,7 @@ fn trait_predicate_kind<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
predicate: &ty::Predicate<'tcx>,
|
||||
) -> Option<TraitSpecializationKind> {
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
|
||||
Some(tcx.trait_def(pred.def_id()).specialization_kind)
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
|
||||
|
||||
// process predicates and convert to `RequiredPredicates` entry, see below
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
match predicate {
|
||||
match predicate.kind() {
|
||||
ty::PredicateKind::TypeOutlives(predicate) => {
|
||||
let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder();
|
||||
insert_outlives_predicate(
|
||||
|
@ -3,7 +3,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
|
||||
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -30,7 +30,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
|
||||
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
|
||||
let mut pred: Vec<String> = predicates
|
||||
.iter()
|
||||
.map(|(out_pred, _)| match out_pred {
|
||||
.map(|(out_pred, _)| match out_pred.kind() {
|
||||
ty::PredicateKind::RegionOutlives(p) => p.to_string(),
|
||||
ty::PredicateKind::TypeOutlives(p) => p.to_string(),
|
||||
err => bug!("unexpected predicate {:?}", err),
|
||||
@ -82,22 +82,26 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|
||||
.iter()
|
||||
.map(|(&def_id, set)| {
|
||||
let predicates = &*tcx.arena.alloc_from_iter(set.iter().filter_map(
|
||||
|(ty::OutlivesPredicate(kind1, region2), &span)| match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate(
|
||||
ty1, region2,
|
||||
))),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::PredicateKind::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate(
|
||||
region1, region2,
|
||||
))),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Const(_) => {
|
||||
// Generic consts don't impose any constraints.
|
||||
None
|
||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||
match kind1.unpack() {
|
||||
GenericArgKind::Type(ty1) => Some((
|
||||
ty::PredicateKind::TypeOutlives(ty::Binder::bind(
|
||||
ty::OutlivesPredicate(ty1, region2),
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Lifetime(region1) => Some((
|
||||
ty::PredicateKind::RegionOutlives(ty::Binder::bind(
|
||||
ty::OutlivesPredicate(region1, region2),
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
)),
|
||||
GenericArgKind::Const(_) => {
|
||||
// Generic consts don't impose any constraints.
|
||||
None
|
||||
}
|
||||
}
|
||||
},
|
||||
));
|
||||
|
@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pred: ty::Predicate<'tcx>,
|
||||
) -> FxHashSet<GenericParamDef> {
|
||||
let regions = match pred {
|
||||
let regions = match pred.kind() {
|
||||
ty::PredicateKind::Trait(poly_trait_pred, _) => {
|
||||
tcx.collect_referenced_late_bound_regions(&poly_trait_pred)
|
||||
}
|
||||
@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||
.iter()
|
||||
.filter(|p| {
|
||||
!orig_bounds.contains(p)
|
||||
|| match p {
|
||||
|| match p.kind() {
|
||||
ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ impl Clean<WherePredicate> for hir::WherePredicate<'_> {
|
||||
|
||||
impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
|
||||
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
|
||||
match *self {
|
||||
match self.kind() {
|
||||
ty::PredicateKind::Trait(ref pred, _) => Some(pred.clean(cx)),
|
||||
ty::PredicateKind::Subtype(ref pred) => Some(pred.clean(cx)),
|
||||
ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx),
|
||||
@ -763,7 +763,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
|
||||
if let ty::Param(param) = outlives.skip_binder().0.kind {
|
||||
return Some(param.index);
|
||||
}
|
||||
} else if let ty::PredicateKind::Projection(p) = p {
|
||||
} else if let ty::PredicateKind::Projection(p) = p.kind() {
|
||||
if let ty::Param(param) = p.skip_binder().projection_ty.self_ty().kind {
|
||||
projection = Some(p);
|
||||
return Some(param.index);
|
||||
@ -1661,7 +1661,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
.filter_map(|predicate| {
|
||||
let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() {
|
||||
tr
|
||||
} else if let ty::PredicateKind::TypeOutlives(pred) = *predicate {
|
||||
} else if let ty::PredicateKind::TypeOutlives(pred) = predicate.kind() {
|
||||
// these should turn up at the end
|
||||
if let Some(r) = pred.skip_binder().1.clean(cx) {
|
||||
regions.push(GenericBound::Outlives(r));
|
||||
@ -1682,7 +1682,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|pred| {
|
||||
if let ty::PredicateKind::Projection(proj) = *pred {
|
||||
if let ty::PredicateKind::Projection(proj) = pred.kind() {
|
||||
let proj = proj.skip_binder();
|
||||
if proj.projection_ty.trait_ref(cx.tcx)
|
||||
== *trait_ref.skip_binder()
|
||||
|
@ -141,7 +141,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId)
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| {
|
||||
if let ty::PredicateKind::Trait(ref pred, _) = *pred {
|
||||
if let ty::PredicateKind::Trait(ref pred, _) = pred.kind() {
|
||||
if pred.skip_binder().trait_ref.self_ty() == self_ty {
|
||||
Some(pred.def_id())
|
||||
} else {
|
||||
|
@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend {
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
for FulfillmentError { obligation, .. } in send_errors {
|
||||
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
|
||||
if let Trait(trait_pred, _) = obligation.predicate {
|
||||
if let Trait(trait_pred, _) = obligation.predicate.kind() {
|
||||
let trait_ref = trait_pred.to_poly_trait_ref();
|
||||
db.note(&*format!(
|
||||
"`{}` doesn't implement `{}`",
|
||||
|
@ -1496,8 +1496,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
||||
if let ty::Opaque(def_id, _) = ret_ty.kind {
|
||||
// one of the associated types must be Self
|
||||
for predicate in cx.tcx.predicates_of(def_id).predicates {
|
||||
match predicate {
|
||||
(ty::PredicateKind::Projection(poly_projection_predicate), _) => {
|
||||
match predicate.0.kind() {
|
||||
ty::PredicateKind::Projection(poly_projection_predicate) => {
|
||||
let binder = poly_projection_predicate.ty();
|
||||
let associated_type = binder.skip_binder();
|
||||
|
||||
@ -1506,7 +1506,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
||||
return;
|
||||
}
|
||||
},
|
||||
(_, _) => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied())
|
||||
.filter(|p| !p.is_global())
|
||||
.filter_map(|obligation| {
|
||||
if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate {
|
||||
if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() {
|
||||
if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars()
|
||||
{
|
||||
return None;
|
||||
|
@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo
|
||||
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
|
||||
ty::Opaque(ref def_id, _) => {
|
||||
for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate {
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() {
|
||||
if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user