Skip to content

Commit fc04c41

Browse files
committed
add a debug assertion that only outlives-oblig. result from norm.
1 parent 6288faa commit fc04c41

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/librustc_traits/normalize_erasing_regions.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,35 @@
1010

1111
use rustc::traits::{Normalized, ObligationCause};
1212
use rustc::traits::query::NoSolution;
13-
use rustc::ty::{ParamEnvAnd, Ty, TyCtxt};
13+
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
1414
use rustc::util::common::CellUsizeExt;
1515

1616
crate fn normalize_ty_after_erasing_regions<'tcx>(
1717
tcx: TyCtxt<'_, 'tcx, 'tcx>,
1818
goal: ParamEnvAnd<'tcx, Ty<'tcx>>,
1919
) -> Ty<'tcx> {
2020
let ParamEnvAnd { param_env, value } = goal;
21-
tcx.sess.perf_stats.normalize_ty_after_erasing_regions.increment();
21+
tcx.sess
22+
.perf_stats
23+
.normalize_ty_after_erasing_regions
24+
.increment();
2225
tcx.infer_ctxt().enter(|infcx| {
2326
let cause = ObligationCause::dummy();
2427
match infcx.at(&cause, param_env).normalize(&value) {
25-
Ok(Normalized { value: normalized_value, obligations: _ }) => {
26-
// ^^^^^^^^^^^
27-
// We don't care about the `obligations`,
28-
// they are always only region relations,
29-
// and we are about to erase those anyway.
28+
Ok(Normalized {
29+
value: normalized_value,
30+
obligations: normalized_obligations,
31+
}) => {
32+
// We don't care about the `obligations`; they are
33+
// always only region relations, and we are about to
34+
// erase those anyway:
35+
debug_assert_eq!(
36+
normalized_obligations
37+
.iter()
38+
.find(|p| not_outlives_predicate(&p.predicate)),
39+
None,
40+
);
41+
3042
let normalized_value = infcx.resolve_type_vars_if_possible(&normalized_value);
3143
let normalized_value = infcx.tcx.erase_regions(&normalized_value);
3244
tcx.lift_to_global(&normalized_value).unwrap()
@@ -35,3 +47,16 @@ crate fn normalize_ty_after_erasing_regions<'tcx>(
3547
}
3648
})
3749
}
50+
51+
fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool {
52+
match p {
53+
ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false,
54+
ty::Predicate::Trait(..)
55+
| ty::Predicate::Projection(..)
56+
| ty::Predicate::WellFormed(..)
57+
| ty::Predicate::ObjectSafe(..)
58+
| ty::Predicate::ClosureKind(..)
59+
| ty::Predicate::Subtype(..)
60+
| ty::Predicate::ConstEvaluatable(..) => true,
61+
}
62+
}

0 commit comments

Comments
 (0)