Skip to content

Commit 9dfb004

Browse files
committed
Add regression test
Add regression test for ICE with intrinsics in unifying coercions.
1 parent d409676 commit 9dfb004

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for #149143.
2+
// The compiler did not check for a coercion from intrinsics
3+
// to fn ptrs in all possible code paths that could lead to such a coercion.
4+
// This caused an ICE during a later sanity check.
5+
6+
use std::mem::transmute;
7+
8+
fn main() {
9+
unsafe {
10+
let f = if true { transmute } else { safe_transmute };
11+
//~^ ERROR `if` and `else` have incompatible type
12+
13+
let _: i64 = f(5i64);
14+
}
15+
}
16+
17+
unsafe fn safe_transmute<A, B>(x: A) -> B {
18+
panic!()
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: `if` and `else` have incompatible types
2+
--> $DIR/intrinsic-in-unifying-coercion-149143.rs:10:46
3+
|
4+
LL | let f = if true { transmute } else { safe_transmute };
5+
| --------- ^^^^^^^^^^^^^^ cannot coerce intrinsics to function pointers
6+
| |
7+
| expected because of this
8+
|
9+
= note: expected fn item `unsafe fn(_) -> _ {std::intrinsics::transmute::<_, _>}`
10+
found fn item `unsafe fn(_) -> _ {safe_transmute::<_, _>}`
11+
= note: different fn items have unique types, even if their signatures are the same
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)