Skip to content

Commit 99a9a63

Browse files
committed
Turns out opaque types can have hidden types registered during mir validation
1 parent 52bdc37 commit 99a9a63

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

compiler/rustc_const_eval/src/util/compare_types.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ pub fn is_subtype<'tcx>(
5757
// we would get unification errors because we're unable to look into opaque types,
5858
// even if they're constrained in our current function.
5959
for (key, ty) in infcx.take_opaque_types() {
60-
span_bug!(
61-
ty.hidden_type.span,
62-
"{}, {}",
63-
tcx.type_of(key.def_id).instantiate(tcx, key.args),
64-
ty.hidden_type.ty
65-
);
60+
let hidden_ty = tcx.type_of(key.def_id).instantiate(tcx, key.args);
61+
if hidden_ty != ty.hidden_type.ty {
62+
span_bug!(
63+
ty.hidden_type.span,
64+
"{}, {}",
65+
tcx.type_of(key.def_id).instantiate(tcx, key.args),
66+
ty.hidden_type.ty
67+
);
68+
}
6669
}
6770
errors.is_empty()
6871
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! ICE: https://github.com/rust-lang/rust/issues/114121
2+
//! This test checks that MIR validation never constrains
3+
//! new hidden types that *differ* from the actual hidden types.
4+
//! This test used to ICE because oli-obk assumed mir validation
5+
//! was only ever run after opaque types were revealed in MIR.
6+
7+
// compile-flags: -Zvalidate-mir
8+
// check-pass
9+
10+
fn main() {
11+
let _ = Some(()).into_iter().flat_map(|_| Some(()).into_iter().flat_map(func));
12+
}
13+
14+
fn func(_: ()) -> impl Iterator<Item = ()> {
15+
Some(()).into_iter().flat_map(|_| vec![])
16+
}

0 commit comments

Comments
 (0)