Skip to content

Commit 9079926

Browse files
committed
elaborate
1 parent 0008496 commit 9079926

File tree

2 files changed

+23
-19
lines changed
  • src
    • librustc_infer/traits
    • librustc_trait_selection/traits

2 files changed

+23
-19
lines changed

src/librustc_infer/traits/util.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,22 @@ impl Elaborator<'tcx> {
151151

152152
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
153153
let tcx = self.visited.tcx;
154-
match obligation.predicate.kind() {
155-
ty::PredicateKind::Trait(ref data, _) => {
154+
let pred = match obligation.predicate.kint(tcx) {
155+
// We have to be careful and rebind this whenever
156+
// dealing with a predicate further down.
157+
ty::PredicateKint::ForAll(binder) => binder.skip_binder(),
158+
pred => pred,
159+
};
160+
161+
match pred {
162+
ty::PredicateKint::ForAll(_) => bug!("unexpected predicate: {:?}", pred),
163+
ty::PredicateKint::Trait(ref data, _) => {
156164
// Get predicates declared on the trait.
157165
let predicates = tcx.super_predicates_of(data.def_id());
158166

159167
let obligations = predicates.predicates.iter().map(|&(pred, span)| {
160168
predicate_obligation(
161-
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
169+
pred.subst_supertrait(tcx, &ty::Binder::bind(data.trait_ref)),
162170
Some(span),
163171
)
164172
});
@@ -173,36 +181,36 @@ impl Elaborator<'tcx> {
173181

174182
self.stack.extend(obligations);
175183
}
176-
ty::PredicateKind::WellFormed(..) => {
184+
ty::PredicateKint::WellFormed(..) => {
177185
// Currently, we do not elaborate WF predicates,
178186
// although we easily could.
179187
}
180-
ty::PredicateKind::ObjectSafe(..) => {
188+
ty::PredicateKint::ObjectSafe(..) => {
181189
// Currently, we do not elaborate object-safe
182190
// predicates.
183191
}
184-
ty::PredicateKind::Subtype(..) => {
192+
ty::PredicateKint::Subtype(..) => {
185193
// Currently, we do not "elaborate" predicates like `X <: Y`,
186194
// though conceivably we might.
187195
}
188-
ty::PredicateKind::Projection(..) => {
196+
ty::PredicateKint::Projection(..) => {
189197
// Nothing to elaborate in a projection predicate.
190198
}
191-
ty::PredicateKind::ClosureKind(..) => {
199+
ty::PredicateKint::ClosureKind(..) => {
192200
// Nothing to elaborate when waiting for a closure's kind to be inferred.
193201
}
194-
ty::PredicateKind::ConstEvaluatable(..) => {
202+
ty::PredicateKint::ConstEvaluatable(..) => {
195203
// Currently, we do not elaborate const-evaluatable
196204
// predicates.
197205
}
198-
ty::PredicateKind::ConstEquate(..) => {
206+
ty::PredicateKint::ConstEquate(..) => {
199207
// Currently, we do not elaborate const-equate
200208
// predicates.
201209
}
202-
ty::PredicateKind::RegionOutlives(..) => {
210+
ty::PredicateKint::RegionOutlives(..) => {
203211
// Nothing to elaborate from `'a: 'b`.
204212
}
205-
ty::PredicateKind::TypeOutlives(ref data) => {
213+
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
206214
// We know that `T: 'a` for some type `T`. We can
207215
// often elaborate this. For example, if we know that
208216
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -217,8 +225,6 @@ impl Elaborator<'tcx> {
217225
// consider this as evidence that `T: 'static`, but
218226
// I'm a bit wary of such constructions and so for now
219227
// I want to be conservative. --nmatsakis
220-
let ty_max = data.skip_binder().0;
221-
let r_min = data.skip_binder().1;
222228
if r_min.is_late_bound() {
223229
return;
224230
}

src/librustc_trait_selection/traits/wf.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
389389
self.out.push(traits::Obligation::new(
390390
cause,
391391
self.param_env,
392-
ty::PredicateKind::WellFormed(resolved_constant.into())
392+
ty::PredicateKint::WellFormed(resolved_constant.into())
393393
.to_predicate(self.tcx()),
394394
));
395395
}
@@ -475,10 +475,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
475475
self.out.push(traits::Obligation::new(
476476
cause,
477477
param_env,
478-
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(
479-
ty::OutlivesPredicate(rty, r),
480-
))
481-
.to_predicate(self.tcx()),
478+
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(rty, r))
479+
.to_predicate(self.tcx()),
482480
));
483481
}
484482
}

0 commit comments

Comments
 (0)