Skip to content

Commit 04b228c

Browse files
committed
Address niko's nits
1 parent 1271f0b commit 04b228c

File tree

8 files changed

+173
-195
lines changed

8 files changed

+173
-195
lines changed

src/librustc/ich/impls_ty.rs

+35-35
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::WhereClauseAtom<
12941294
use traits::WhereClauseAtom::*;
12951295

12961296
mem::discriminant(self).hash_stable(hcx, hasher);
1297-
match *self {
1298-
Implemented(ref trait_ref) => trait_ref.hash_stable(hcx, hasher),
1299-
ProjectionEq(ref projection) => projection.hash_stable(hcx, hasher),
1297+
match self {
1298+
Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher),
1299+
ProjectionEq(projection) => projection.hash_stable(hcx, hasher),
13001300
}
13011301
}
13021302
}
@@ -1308,54 +1308,59 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::DomainGoal<'tcx>
13081308
use traits::DomainGoal::*;
13091309

13101310
mem::discriminant(self).hash_stable(hcx, hasher);
1311-
match *self {
1312-
Holds(ref where_clause) |
1313-
WellFormed(ref where_clause) |
1314-
FromEnv(ref where_clause) => where_clause.hash_stable(hcx, hasher),
1315-
1316-
WellFormedTy(ref ty) => ty.hash_stable(hcx, hasher),
1317-
FromEnvTy(ref ty) => ty.hash_stable(hcx, hasher),
1318-
RegionOutlives(ref predicate) => predicate.hash_stable(hcx, hasher),
1319-
TypeOutlives(ref predicate) => predicate.hash_stable(hcx, hasher),
1311+
match self {
1312+
Holds(where_clause) |
1313+
WellFormed(where_clause) |
1314+
FromEnv(where_clause) => where_clause.hash_stable(hcx, hasher),
1315+
1316+
WellFormedTy(ty) => ty.hash_stable(hcx, hasher),
1317+
FromEnvTy(ty) => ty.hash_stable(hcx, hasher),
1318+
RegionOutlives(predicate) => predicate.hash_stable(hcx, hasher),
1319+
TypeOutlives(predicate) => predicate.hash_stable(hcx, hasher),
13201320
}
13211321
}
13221322
}
13231323

1324-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::LeafGoal<'tcx> {
1324+
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
13251325
fn hash_stable<W: StableHasherResult>(&self,
13261326
hcx: &mut StableHashingContext<'a>,
13271327
hasher: &mut StableHasher<W>) {
1328-
use traits::LeafGoal::*;
1328+
use traits::Goal::*;
13291329

13301330
mem::discriminant(self).hash_stable(hcx, hasher);
1331-
match *self {
1332-
DomainGoal(ref domain_goal) => domain_goal.hash_stable(hcx, hasher),
1331+
match self {
1332+
Implies(hypotheses, goal) => {
1333+
hypotheses.hash_stable(hcx, hasher);
1334+
goal.hash_stable(hcx, hasher);
1335+
},
1336+
And(goal1, goal2) => {
1337+
goal1.hash_stable(hcx, hasher);
1338+
goal2.hash_stable(hcx, hasher);
1339+
}
1340+
Not(goal) => goal.hash_stable(hcx, hasher),
1341+
DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1342+
Quantified(quantifier, goal) => {
1343+
quantifier.hash_stable(hcx, hasher);
1344+
goal.hash_stable(hcx, hasher);
1345+
},
13331346
}
13341347
}
13351348
}
13361349

1337-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
1350+
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Clause<'tcx> {
13381351
fn hash_stable<W: StableHasherResult>(&self,
13391352
hcx: &mut StableHashingContext<'a>,
13401353
hasher: &mut StableHasher<W>) {
1341-
use traits::Goal::*;
1354+
use traits::Clause::*;
13421355

13431356
mem::discriminant(self).hash_stable(hcx, hasher);
1344-
match *self {
1345-
Implies(ref hypotheses, ref goal) => {
1357+
match self {
1358+
Implies(hypotheses, goal) => {
13461359
hypotheses.hash_stable(hcx, hasher);
13471360
goal.hash_stable(hcx, hasher);
1348-
},
1349-
And(ref goal1, ref goal2) => {
1350-
goal1.hash_stable(hcx, hasher);
1351-
goal2.hash_stable(hcx, hasher);
13521361
}
1353-
Not(ref goal) => goal.hash_stable(hcx, hasher),
1354-
Leaf(ref leaf_goal) => leaf_goal.hash_stable(hcx, hasher),
1355-
Quantified(quantifier, ref goal) => {
1356-
quantifier.hash_stable(hcx, hasher);
1357-
goal.hash_stable(hcx, hasher);
1358-
},
1362+
DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher),
1363+
ForAll(clause) => clause.hash_stable(hcx, hasher),
13591364
}
13601365
}
13611366
}
@@ -1364,8 +1369,3 @@ impl_stable_hash_for!(enum traits::QuantifierKind {
13641369
Universal,
13651370
Existential
13661371
});
1367-
1368-
impl_stable_hash_for!(struct traits::ProgramClause<'tcx> {
1369-
consequence,
1370-
conditions
1371-
});

src/librustc/traits/lowering.rs

+40-19
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use hir::{self, ImplPolarity};
1212
use hir::def_id::DefId;
1313
use hir::intravisit::{self, NestedVisitorMap, Visitor};
14-
use ty::{self, PolyTraitPredicate, TraitPredicate, PolyProjectionPredicate, TyCtxt, Predicate};
15-
use super::{DomainGoal, ProgramClause, WhereClauseAtom};
14+
use ty::{self, TyCtxt};
15+
use super::{QuantifierKind, Goal, DomainGoal, Clause, WhereClauseAtom};
1616
use rustc_data_structures::sync::Lrc;
1717
use syntax::ast;
1818

@@ -26,13 +26,13 @@ impl<T, U> Lower<Vec<U>> for Vec<T> where T: Lower<U> {
2626
}
2727
}
2828

29-
impl<'tcx> Lower<WhereClauseAtom<'tcx>> for PolyTraitPredicate<'tcx> {
29+
impl<'tcx> Lower<WhereClauseAtom<'tcx>> for ty::TraitPredicate<'tcx> {
3030
fn lower(&self) -> WhereClauseAtom<'tcx> {
3131
WhereClauseAtom::Implemented(*self)
3232
}
3333
}
3434

35-
impl<'tcx> Lower<WhereClauseAtom<'tcx>> for PolyProjectionPredicate<'tcx> {
35+
impl<'tcx> Lower<WhereClauseAtom<'tcx>> for ty::ProjectionPredicate<'tcx> {
3636
fn lower(&self) -> WhereClauseAtom<'tcx> {
3737
WhereClauseAtom::ProjectionEq(*self)
3838
}
@@ -44,27 +44,52 @@ impl<'tcx, T> Lower<DomainGoal<'tcx>> for T where T: Lower<WhereClauseAtom<'tcx>
4444
}
4545
}
4646

47-
impl<'tcx> Lower<DomainGoal<'tcx>> for Predicate<'tcx> {
47+
impl<'tcx> Lower<DomainGoal<'tcx>> for ty::RegionOutlivesPredicate<'tcx> {
4848
fn lower(&self) -> DomainGoal<'tcx> {
49-
use self::Predicate::*;
49+
DomainGoal::RegionOutlives(*self)
50+
}
51+
}
52+
53+
impl<'tcx> Lower<DomainGoal<'tcx>> for ty::TypeOutlivesPredicate<'tcx> {
54+
fn lower(&self) -> DomainGoal<'tcx> {
55+
DomainGoal::TypeOutlives(*self)
56+
}
57+
}
58+
59+
impl<'tcx, T> Lower<Goal<'tcx>> for ty::Binder<T>
60+
where T: Lower<DomainGoal<'tcx>> + ty::fold::TypeFoldable<'tcx> + Copy
61+
{
62+
fn lower(&self) -> Goal<'tcx> {
63+
match self.no_late_bound_regions() {
64+
Some(p) => p.lower().into(),
65+
None => Goal::Quantified(
66+
QuantifierKind::Universal,
67+
Box::new(self.map_bound(|p| p.lower().into()))
68+
),
69+
}
70+
}
71+
}
5072

51-
match *self {
73+
impl<'tcx> Lower<Goal<'tcx>> for ty::Predicate<'tcx> {
74+
fn lower(&self) -> Goal<'tcx> {
75+
use ty::Predicate::*;
76+
77+
match self {
5278
Trait(predicate) => predicate.lower(),
53-
RegionOutlives(predicate) => DomainGoal::RegionOutlives(predicate),
54-
TypeOutlives(predicate) => DomainGoal::TypeOutlives(predicate),
79+
RegionOutlives(predicate) => predicate.lower(),
80+
TypeOutlives(predicate) => predicate.lower(),
5581
Projection(predicate) => predicate.lower(),
56-
WellFormed(ty) => DomainGoal::WellFormedTy(ty),
82+
WellFormed(ty) => DomainGoal::WellFormedTy(*ty).into(),
5783
ObjectSafe(..) |
5884
ClosureKind(..) |
5985
Subtype(..) |
6086
ConstEvaluatable(..) => unimplemented!(),
61-
6287
}
6388
}
6489
}
6590

6691
pub fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
67-
-> Lrc<Vec<ProgramClause<'tcx>>>
92+
-> Lrc<Vec<Clause<'tcx>>>
6893
{
6994
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
7095
let item = tcx.hir.expect_item(node_id);
@@ -75,21 +100,17 @@ pub fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
75100
}
76101

77102
fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
78-
-> Lrc<Vec<ProgramClause<'tcx>>>
103+
-> Lrc<Vec<Clause<'tcx>>>
79104
{
80105
if let ImplPolarity::Negative = tcx.impl_polarity(def_id) {
81106
return Lrc::new(vec![]);
82107
}
83108

84109
let trait_ref = tcx.impl_trait_ref(def_id).unwrap();
85-
let trait_ref = ty::Binder(TraitPredicate { trait_ref }).lower();
110+
let trait_ref = ty::TraitPredicate { trait_ref }.lower();
86111
let where_clauses = tcx.predicates_of(def_id).predicates.lower();
87112

88-
let clause = ProgramClause {
89-
consequence: trait_ref,
90-
conditions: where_clauses.into_iter().map(|wc| wc.into()).collect(),
91-
};
92-
113+
let clause = Clause::Implies(where_clauses, trait_ref);
93114
Lrc::new(vec![clause])
94115
}
95116

src/librustc/traits/mod.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
248248

249249
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
250250
pub enum WhereClauseAtom<'tcx> {
251-
Implemented(ty::PolyTraitPredicate<'tcx>),
252-
ProjectionEq(ty::PolyProjectionPredicate<'tcx>),
251+
Implemented(ty::TraitPredicate<'tcx>),
252+
ProjectionEq(ty::ProjectionPredicate<'tcx>),
253253
}
254254

255255
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
@@ -259,13 +259,8 @@ pub enum DomainGoal<'tcx> {
259259
FromEnv(WhereClauseAtom<'tcx>),
260260
WellFormedTy(Ty<'tcx>),
261261
FromEnvTy(Ty<'tcx>),
262-
RegionOutlives(ty::PolyRegionOutlivesPredicate<'tcx>),
263-
TypeOutlives(ty::PolyTypeOutlivesPredicate<'tcx>),
264-
}
265-
266-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
267-
pub enum LeafGoal<'tcx> {
268-
DomainGoal(DomainGoal<'tcx>),
262+
RegionOutlives(ty::RegionOutlivesPredicate<'tcx>),
263+
TypeOutlives(ty::TypeOutlivesPredicate<'tcx>),
269264
}
270265

271266
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
@@ -276,23 +271,30 @@ pub enum QuantifierKind {
276271

277272
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
278273
pub enum Goal<'tcx> {
279-
Implies(Vec<DomainGoal<'tcx>>, Box<Goal<'tcx>>),
274+
Implies(Vec<Clause<'tcx>>, Box<Goal<'tcx>>),
280275
And(Box<Goal<'tcx>>, Box<Goal<'tcx>>),
281276
Not(Box<Goal<'tcx>>),
282-
Leaf(LeafGoal<'tcx>),
277+
DomainGoal(DomainGoal<'tcx>),
283278
Quantified(QuantifierKind, Box<ty::Binder<Goal<'tcx>>>)
284279
}
285280

286281
impl<'tcx> From<DomainGoal<'tcx>> for Goal<'tcx> {
287282
fn from(domain_goal: DomainGoal<'tcx>) -> Self {
288-
Goal::Leaf(LeafGoal::DomainGoal(domain_goal))
283+
Goal::DomainGoal(domain_goal)
284+
}
285+
}
286+
287+
impl<'tcx> From<DomainGoal<'tcx>> for Clause<'tcx> {
288+
fn from(domain_goal: DomainGoal<'tcx>) -> Self {
289+
Clause::DomainGoal(domain_goal)
289290
}
290291
}
291292

292293
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
293-
pub struct ProgramClause<'tcx> {
294-
pub consequence: DomainGoal<'tcx>,
295-
pub conditions: Vec<Goal<'tcx>>,
294+
pub enum Clause<'tcx> {
295+
Implies(Vec<Goal<'tcx>>, DomainGoal<'tcx>),
296+
DomainGoal(DomainGoal<'tcx>),
297+
ForAll(Box<ty::Binder<Clause<'tcx>>>),
296298
}
297299

298300
pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

0 commit comments

Comments
 (0)