Skip to content

Commit 7f39b0c

Browse files
committed
subst_supertrait
1 parent 1fda8c2 commit 7f39b0c

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
@@ -1303,37 +1303,20 @@ impl<'tcx> Predicate<'tcx> {
13031303
// this trick achieves that).
13041304

13051305
let substs = trait_ref.skip_binder().substs;
1306-
let kind = self.kind();
1307-
let new = match kind {
1308-
&PredicateKind::Trait(ref binder, constness) => {
1309-
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
1310-
}
1311-
PredicateKind::Subtype(binder) => {
1312-
PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs)))
1313-
}
1314-
PredicateKind::RegionOutlives(binder) => {
1315-
PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
1316-
}
1317-
PredicateKind::TypeOutlives(binder) => {
1318-
PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
1319-
}
1320-
PredicateKind::Projection(binder) => {
1321-
PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs)))
1322-
}
1323-
&PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
1324-
&PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
1325-
&PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
1326-
PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind)
1327-
}
1328-
&PredicateKind::ConstEvaluatable(def_id, const_substs) => {
1329-
PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs))
1330-
}
1331-
PredicateKind::ConstEquate(c1, c2) => {
1332-
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
1333-
}
1306+
let kind = match self.kint(tcx) {
1307+
PredicateKint::ForAll(binder) => *binder.skip_binder(),
1308+
kind => kind,
1309+
};
1310+
1311+
let new = kind.subst(tcx, substs);
1312+
1313+
let rebound = if new.has_escaping_bound_vars() {
1314+
PredicateKint::ForAll(Binder::bind(tcx.intern_predicate_kint(new)))
1315+
} else {
1316+
new
13341317
};
13351318

1336-
if new != *kind { new.to_predicate(tcx) } else { self }
1319+
if rebound != *kind { rebound.to_predicate(tcx) } else { self }
13371320
}
13381321
}
13391322

0 commit comments

Comments
 (0)