Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PredicateKint -> PredicateKind, the beginning of the end
  • Loading branch information
lcnr committed Jul 27, 2020
commit 9852b42b581bbc4843460f4654a2dbd859bd9034
20 changes: 11 additions & 9 deletions src/librustc_infer/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
GenericArg<'tcx>,
ty::Region<'tcx>,
>| match k1.unpack() {
GenericArgKind::Lifetime(r1) => self.tcx.intern_predicate_kint(
ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
),
GenericArgKind::Type(t1) => self.tcx.intern_predicate_kint(
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(t1, r2)),
),
GenericArgKind::Lifetime(r1) => {
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Type(t1) => {
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
.to_predicate(self.tcx)
}
GenericArgKind::Const(..) => {
// Consts cannot outlive one another, so we don't expect to
// ecounter this branch.
Expand All @@ -545,9 +547,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
};

let predicate = if let Some(constraint) = constraint.no_bound_vars() {
to_predicate(constraint).to_predicate(self.tcx)
to_predicate(constraint)
} else {
ty::PredicateKint::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
ty::PredicateKind::ForAll(constraint.map_bound(to_predicate)).to_predicate(self.tcx)
};

Obligation::new(cause.clone(), param_env, predicate)
Expand Down Expand Up @@ -670,7 +672,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
self.obligations.push(Obligation {
cause: self.cause.clone(),
param_env: self.param_env,
predicate: ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(sup, sub))
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
.to_predicate(self.infcx.tcx),
recursion_depth: 0,
});
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_infer/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
self.obligations.push(Obligation::new(
self.trace.cause.clone(),
self.param_env,
ty::PredicateKint::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
));
}

Expand Down Expand Up @@ -400,9 +400,9 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
b: &'tcx ty::Const<'tcx>,
) {
let predicate = if a_is_expected {
ty::PredicateKint::ConstEquate(a, b)
ty::PredicateKind::ConstEquate(a, b)
} else {
ty::PredicateKint::ConstEquate(b, a)
ty::PredicateKind::ConstEquate(b, a)
};
self.obligations.push(Obligation::new(
self.trace.cause.clone(),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_infer/infer/outlives/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::infer::{GenericKind, InferCtxt};
use crate::traits::query::OutlivesBound;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_middle::ty::{self, TyCtxt};

use super::explicit_outlives_bounds;

Expand Down Expand Up @@ -69,15 +69,15 @@ pub struct OutlivesEnvironment<'tcx> {
pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;

impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
let mut env = OutlivesEnvironment {
param_env,
free_region_map: Default::default(),
region_bound_pairs_map: Default::default(),
region_bound_pairs_accum: vec![],
};

env.add_outlives_bounds(None, explicit_outlives_bounds(param_env));
env.add_outlives_bounds(None, explicit_outlives_bounds(tcx, param_env));

env
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_infer/infer/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ pub mod obligations;
pub mod verify;

use rustc_middle::traits::query::OutlivesBound;
use rustc_middle::ty;
use rustc_middle::ty::{self, TyCtxt};

pub fn explicit_outlives_bounds<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
debug!("explicit_outlives_bounds()");
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_infer/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
compare_ty: impl Fn(Ty<'tcx>) -> bool,
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
) -> impl Iterator<Item = ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
let tcx = self.tcx;
predicates
.filter_map(|p| p.to_opt_type_outlives())
.filter_map(move |p| p.to_opt_type_outlives(tcx))
.filter_map(|p| p.no_bound_vars())
.filter(move |p| compare_ty(p.0))
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
self.fields.obligations.push(Obligation::new(
self.fields.trace.cause.clone(),
self.fields.param_env,
ty::PredicateKint::Subtype(ty::SubtypePredicate {
ty::PredicateKind::Subtype(ty::SubtypePredicate {
a_is_expected: self.a_is_expected,
a,
b,
Expand Down
81 changes: 41 additions & 40 deletions src/librustc_infer/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> ty::Predicate<'tcx> {
let kind = pred.kint(tcx);
let kind = pred.kind();
let new = match kind {
ty::PredicateKint::ForAll(binder) => {
ty::PredicateKint::ForAll(tcx.anonymize_late_bound_regions(binder))
ty::PredicateKind::ForAll(binder) => {
ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder))
}
&ty::PredicateKint::Trait(data, constness) => ty::PredicateKint::Trait(data, constness),
&ty::PredicateKind::Trait(data, constness) => ty::PredicateKind::Trait(data, constness),

&ty::PredicateKint::RegionOutlives(data) => ty::PredicateKint::RegionOutlives(data),
&ty::PredicateKind::RegionOutlives(data) => ty::PredicateKind::RegionOutlives(data),

&ty::PredicateKint::TypeOutlives(data) => ty::PredicateKint::TypeOutlives(data),
&ty::PredicateKind::TypeOutlives(data) => ty::PredicateKind::TypeOutlives(data),

&ty::PredicateKint::Projection(data) => ty::PredicateKint::Projection(data),
&ty::PredicateKind::Projection(data) => ty::PredicateKind::Projection(data),

&ty::PredicateKint::WellFormed(data) => ty::PredicateKint::WellFormed(data),
&ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),

&ty::PredicateKint::ObjectSafe(data) => ty::PredicateKint::ObjectSafe(data),
&ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),

&ty::PredicateKint::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKint::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)
}

&ty::PredicateKint::Subtype(data) => ty::PredicateKint::Subtype(data),
&ty::PredicateKind::Subtype(data) => ty::PredicateKind::Subtype(data),

&ty::PredicateKint::ConstEvaluatable(def_id, substs) => {
ty::PredicateKint::ConstEvaluatable(def_id, substs)
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs)
}

&ty::PredicateKint::ConstEquate(c1, c2) => ty::PredicateKint::ConstEquate(c1, c2),
&ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
};

if new != *kind { new.to_predicate(tcx) } else { pred }
Expand Down Expand Up @@ -145,22 +145,22 @@ fn predicate_obligation<'tcx>(
}

impl Elaborator<'tcx> {
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
FilterToTraits::new(self)
pub fn filter_to_traits(self) -> FilterToTraits<'tcx, Self> {
FilterToTraits::new(self.visited.tcx, self)
}

fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
let pred = match obligation.predicate.kint(tcx) {
// We have to be careful and rebind this whenever
let pred = match obligation.predicate.kind() {
// We have to be careful and rebind this when
// dealing with a predicate further down.
ty::PredicateKint::ForAll(binder) => binder.skip_binder(),
ty::PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
pred => pred,
};

match pred {
ty::PredicateKint::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
ty::PredicateKint::Trait(ref data, _) => {
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
ty::PredicateKind::Trait(data, _) => {
// Get predicates declared on the trait.
let predicates = tcx.super_predicates_of(data.def_id());

Expand All @@ -181,36 +181,36 @@ impl Elaborator<'tcx> {

self.stack.extend(obligations);
}
ty::PredicateKint::WellFormed(..) => {
ty::PredicateKind::WellFormed(..) => {
// Currently, we do not elaborate WF predicates,
// although we easily could.
}
ty::PredicateKint::ObjectSafe(..) => {
ty::PredicateKind::ObjectSafe(..) => {
// Currently, we do not elaborate object-safe
// predicates.
}
ty::PredicateKint::Subtype(..) => {
ty::PredicateKind::Subtype(..) => {
// Currently, we do not "elaborate" predicates like `X <: Y`,
// though conceivably we might.
}
ty::PredicateKint::Projection(..) => {
ty::PredicateKind::Projection(..) => {
// Nothing to elaborate in a projection predicate.
}
ty::PredicateKint::ClosureKind(..) => {
ty::PredicateKind::ClosureKind(..) => {
// Nothing to elaborate when waiting for a closure's kind to be inferred.
}
ty::PredicateKint::ConstEvaluatable(..) => {
ty::PredicateKind::ConstEvaluatable(..) => {
// Currently, we do not elaborate const-evaluatable
// predicates.
}
ty::PredicateKint::ConstEquate(..) => {
ty::PredicateKind::ConstEquate(..) => {
// Currently, we do not elaborate const-equate
// predicates.
}
ty::PredicateKint::RegionOutlives(..) => {
ty::PredicateKind::RegionOutlives(..) => {
// Nothing to elaborate from `'a: 'b`.
}
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
ty::PredicateKind::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
Expand Down Expand Up @@ -240,15 +240,15 @@ impl Elaborator<'tcx> {
if r.is_late_bound() {
None
} else {
Some(ty::PredicateKint::RegionOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
r, r_min,
)))
}
}

Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name);
Some(ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty, r_min,
)))
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl Iterator for Elaborator<'tcx> {
// Supertrait iterator
///////////////////////////////////////////////////////////////////////////

pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
pub type Supertraits<'tcx> = FilterToTraits<'tcx, Elaborator<'tcx>>;

pub fn supertraits<'tcx>(
tcx: TyCtxt<'tcx>,
Expand All @@ -315,22 +315,23 @@ pub fn transitive_bounds<'tcx>(

/// A filter around an iterator of predicates that makes it yield up
/// just trait references.
pub struct FilterToTraits<I> {
pub struct FilterToTraits<'tcx, I> {
tcx: TyCtxt<'tcx>,
base_iterator: I,
}

impl<I> FilterToTraits<I> {
fn new(base: I) -> FilterToTraits<I> {
FilterToTraits { base_iterator: base }
impl<'tcx, I> FilterToTraits<'tcx, I> {
fn new(tcx: TyCtxt<'tcx>, base: I) -> FilterToTraits<'tcx, I> {
FilterToTraits { tcx, base_iterator: base }
}
}

impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<'tcx, I> {
type Item = ty::PolyTraitRef<'tcx>;

fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
while let Some(obligation) = self.base_iterator.next() {
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref(self.tcx) {
return Some(data);
}
}
Expand Down
Loading