Skip to content

Commit 0008496

Browse files
committed
subst_supertrait
1 parent 4943df3 commit 0008496

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

src/librustc_infer/traits/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ impl Elaborator<'tcx> {
156156
// Get predicates declared on the trait.
157157
let predicates = tcx.super_predicates_of(data.def_id());
158158

159-
let obligations = predicates.predicates.iter().map(|(pred, span)| {
159+
let obligations = predicates.predicates.iter().map(|&(pred, span)| {
160160
predicate_obligation(
161161
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
162-
Some(*span),
162+
Some(span),
163163
)
164164
});
165165
debug!("super_predicates: data={:?}", data);

src/librustc_middle/ty/mod.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,37 +1295,20 @@ impl<'tcx> Predicate<'tcx> {
12951295
// this trick achieves that).
12961296

12971297
let substs = trait_ref.skip_binder().substs;
1298-
let kind = self.kind();
1299-
let new = match kind {
1300-
&PredicateKind::Trait(ref binder, constness) => {
1301-
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
1302-
}
1303-
PredicateKind::Subtype(binder) => {
1304-
PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs)))
1305-
}
1306-
PredicateKind::RegionOutlives(binder) => {
1307-
PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
1308-
}
1309-
PredicateKind::TypeOutlives(binder) => {
1310-
PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
1311-
}
1312-
PredicateKind::Projection(binder) => {
1313-
PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs)))
1314-
}
1315-
&PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
1316-
&PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
1317-
&PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
1318-
PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind)
1319-
}
1320-
&PredicateKind::ConstEvaluatable(def_id, const_substs) => {
1321-
PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs))
1322-
}
1323-
PredicateKind::ConstEquate(c1, c2) => {
1324-
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
1325-
}
1298+
let kind = match self.kint(tcx) {
1299+
PredicateKint::ForAll(binder) => *binder.skip_binder(),
1300+
kind => kind,
1301+
};
1302+
1303+
let new = kind.subst(tcx, substs);
1304+
1305+
let rebound = if new.has_escaping_bound_vars() {
1306+
PredicateKint::ForAll(Binder::bind(tcx.intern_predicate_kint(new)))
1307+
} else {
1308+
new
13261309
};
13271310

1328-
if new != *kind { new.to_predicate(tcx) } else { self }
1311+
if rebound != *kind { rebound.to_predicate(tcx) } else { self }
13291312
}
13301313
}
13311314

0 commit comments

Comments
 (0)