Skip to content

Commit f316479

Browse files
committed
introduce newtype'd Predicate<'tcx>
1 parent 034c25f commit f316479

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+345
-245
lines changed

src/librustc_infer/infer/canonical/query_response.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable;
2525
use rustc_middle::ty::fold::TypeFoldable;
2626
use rustc_middle::ty::relate::TypeRelation;
2727
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
28-
use rustc_middle::ty::{self, BoundVar, Const, Ty, TyCtxt};
28+
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
2929
use std::fmt::Debug;
3030

3131
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
@@ -534,10 +534,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
534534
match k1.unpack() {
535535
GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives(
536536
ty::Binder::bind(ty::OutlivesPredicate(r1, r2)),
537-
),
537+
)
538+
.to_predicate(self.tcx),
538539
GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind(
539540
ty::OutlivesPredicate(t1, r2),
540-
)),
541+
))
542+
.to_predicate(self.tcx),
541543
GenericArgKind::Const(..) => {
542544
// Consts cannot outlive one another, so we don't expect to
543545
// ecounter this branch.
@@ -666,7 +668,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
666668
param_env: self.param_env,
667669
predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
668670
sup, sub,
669-
))),
671+
)))
672+
.to_predicate(self.infcx.tcx),
670673
recursion_depth: 0,
671674
});
672675
}

src/librustc_infer/infer/combine.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_hir::def_id::DefId;
3939
use rustc_middle::ty::error::TypeError;
4040
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
4141
use rustc_middle::ty::subst::SubstsRef;
42-
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeFoldable};
42+
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
4343
use rustc_middle::ty::{IntType, UintType};
4444
use rustc_span::{Span, DUMMY_SP};
4545

@@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
307307
self.obligations.push(Obligation::new(
308308
self.trace.cause.clone(),
309309
self.param_env,
310-
ty::PredicateKind::WellFormed(b_ty),
310+
ty::PredicateKind::WellFormed(b_ty).to_predicate(self.infcx.tcx),
311311
));
312312
}
313313

@@ -398,11 +398,15 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
398398
b: &'tcx ty::Const<'tcx>,
399399
) {
400400
let predicate = if a_is_expected {
401-
ty::Predicate::ConstEquate(a, b)
401+
ty::PredicateKind::ConstEquate(a, b)
402402
} else {
403-
ty::Predicate::ConstEquate(b, a)
403+
ty::PredicateKind::ConstEquate(b, a)
404404
};
405-
self.obligations.push(Obligation::new(self.trace.cause.clone(), self.param_env, predicate));
405+
self.obligations.push(Obligation::new(
406+
self.trace.cause.clone(),
407+
self.param_env,
408+
predicate.to_predicate(self.tcx()),
409+
));
406410
}
407411
}
408412

src/librustc_infer/infer/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn explicit_outlives_bounds<'tcx>(
1111
param_env: ty::ParamEnv<'tcx>,
1212
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1313
debug!("explicit_outlives_bounds()");
14-
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate {
14+
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate.kind() {
1515
ty::PredicateKind::Projection(..)
1616
| ty::PredicateKind::Trait(..)
1717
| ty::PredicateKind::Subtype(..)

src/librustc_infer/infer/sub.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::traits::Obligation;
66
use rustc_middle::ty::fold::TypeFoldable;
77
use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
88
use rustc_middle::ty::TyVar;
9-
use rustc_middle::ty::{self, Ty, TyCtxt};
9+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1010
use std::mem;
1111

1212
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
@@ -104,7 +104,8 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
104104
a_is_expected: self.a_is_expected,
105105
a,
106106
b,
107-
})),
107+
}))
108+
.to_predicate(self.tcx()),
108109
));
109110

110111
Ok(a)

src/librustc_infer/traits/util.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,49 @@ pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
1111
pred: &ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
13-
match *pred {
13+
match pred.kind() {
1414
ty::PredicateKind::Trait(ref data, constness) => {
1515
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
16+
.to_predicate(tcx)
1617
}
1718

1819
ty::PredicateKind::RegionOutlives(ref data) => {
1920
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
21+
.to_predicate(tcx)
2022
}
2123

2224
ty::PredicateKind::TypeOutlives(ref data) => {
2325
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
26+
.to_predicate(tcx)
2427
}
2528

2629
ty::PredicateKind::Projection(ref data) => {
27-
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data))
30+
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
2831
}
2932

30-
ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
33+
ty::PredicateKind::WellFormed(data) => {
34+
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
35+
}
3136

32-
ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
37+
ty::PredicateKind::ObjectSafe(data) => {
38+
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
39+
}
3340

3441
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
35-
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
42+
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
3643
}
3744

3845
ty::PredicateKind::Subtype(ref data) => {
39-
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data))
46+
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
4047
}
4148

4249
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
43-
ty::PredicateKind::ConstEvaluatable(def_id, substs)
50+
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
4451
}
4552

46-
ty::PredicateKind::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2),
53+
ty::PredicateKind::ConstEquate(c1, c2) => {
54+
ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx)
55+
}
4756
}
4857
}
4958

@@ -145,7 +154,7 @@ impl Elaborator<'tcx> {
145154

146155
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
147156
let tcx = self.visited.tcx;
148-
match obligation.predicate {
157+
match obligation.predicate.kind() {
149158
ty::PredicateKind::Trait(ref data, _) => {
150159
// Get predicates declared on the trait.
151160
let predicates = tcx.super_predicates_of(data.def_id());
@@ -250,8 +259,9 @@ impl Elaborator<'tcx> {
250259
None
251260
}
252261
})
253-
.filter(|p| visited.insert(p))
254-
.map(|p| predicate_obligation(p, None)),
262+
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
263+
.filter(|predicate| visited.insert(predicate))
264+
.map(|predicate| predicate_obligation(predicate, None)),
255265
);
256266
}
257267
}
@@ -317,7 +327,7 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
317327

318328
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
319329
while let Some(obligation) = self.base_iterator.next() {
320-
if let ty::PredicateKind::Trait(data, _) = obligation.predicate {
330+
if let ty::PredicateKind::Trait(data, _) = obligation.predicate.kind() {
321331
return Some(data.to_poly_trait_ref());
322332
}
323333
}

src/librustc_lint/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12081208
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
12091209
let predicates = cx.tcx.predicates_of(def_id);
12101210
for &(predicate, span) in predicates.predicates {
1211-
let predicate_kind_name = match predicate {
1211+
let predicate_kind_name = match predicate.kind() {
12121212
Trait(..) => "Trait",
12131213
TypeOutlives(..) |
12141214
RegionOutlives(..) => "Lifetime",
@@ -1497,7 +1497,7 @@ impl ExplicitOutlivesRequirements {
14971497
) -> Vec<ty::Region<'tcx>> {
14981498
inferred_outlives
14991499
.iter()
1500-
.filter_map(|(pred, _)| match pred {
1500+
.filter_map(|(pred, _)| match pred.kind() {
15011501
ty::PredicateKind::RegionOutlives(outlives) => {
15021502
let outlives = outlives.skip_binder();
15031503
match outlives.0 {
@@ -1516,7 +1516,7 @@ impl ExplicitOutlivesRequirements {
15161516
) -> Vec<ty::Region<'tcx>> {
15171517
inferred_outlives
15181518
.iter()
1519-
.filter_map(|(pred, _)| match pred {
1519+
.filter_map(|(pred, _)| match pred.kind() {
15201520
ty::PredicateKind::TypeOutlives(outlives) => {
15211521
let outlives = outlives.skip_binder();
15221522
outlives.0.is_param(index).then_some(outlives.1)

src/librustc_lint/unused.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
146146
ty::Opaque(def, _) => {
147147
let mut has_emitted = false;
148148
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
149-
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate {
149+
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
150+
predicate.kind()
151+
{
150152
let trait_ref = poly_trait_predicate.skip_binder().trait_ref;
151153
let def_id = trait_ref.def_id;
152154
let descr_pre =

src/librustc_middle/ty/codec.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::arena::ArenaAllocatable;
1010
use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
1111
use crate::mir::{self, interpret::Allocation};
1212
use crate::ty::subst::SubstsRef;
13-
use crate::ty::{self, List, Ty, TyCtxt};
13+
use crate::ty::{self, List, ToPredicate, Ty, TyCtxt};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_hir::def_id::{CrateNum, DefId};
1616
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
@@ -196,7 +196,7 @@ where
196196
(0..decoder.read_usize()?)
197197
.map(|_| {
198198
// Handle shorthands first, if we have an usize > 0x80.
199-
let predicate = if decoder.positioned_at_shorthand() {
199+
let predicate_kind = if decoder.positioned_at_shorthand() {
200200
let pos = decoder.read_usize()?;
201201
assert!(pos >= SHORTHAND_OFFSET);
202202
let shorthand = pos - SHORTHAND_OFFSET;
@@ -205,6 +205,7 @@ where
205205
} else {
206206
ty::PredicateKind::decode(decoder)
207207
}?;
208+
let predicate = predicate_kind.to_predicate(tcx);
208209
Ok((predicate, Decodable::decode(decoder)?))
209210
})
210211
.collect::<Result<Vec<_>, _>>()?,

src/librustc_middle/ty/context.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
2929
use crate::ty::{AdtDef, AdtKind, Const, Region};
3030
use crate::ty::{BindingMode, BoundVar};
3131
use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid};
32-
use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, ProjectionTy};
32+
use crate::ty::{
33+
ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy,
34+
};
3335
use crate::ty::{InferConst, ParamConst};
3436
use crate::ty::{List, TyKind, TyS};
3537
use rustc_ast::ast;
@@ -2103,6 +2105,11 @@ impl<'tcx> TyCtxt<'tcx> {
21032105
self.interners.intern_ty(st)
21042106
}
21052107

2108+
#[inline]
2109+
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
2110+
Predicate { kind }
2111+
}
2112+
21062113
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
21072114
match tm {
21082115
ast::IntTy::Isize => self.types.isize,

0 commit comments

Comments
 (0)