This is one of the behaviors we no longer allow in NLL. Since it can lead to undefined behavior, I think it's definitely worth making it a hard error without waiting to turn off migration mode (#58781). Closes #60450. My ulterior motive here is making it impossible to leave variables partially initialized across a yield (see discussion at #63035), so tests are included for that.
19 lines
402 B
Rust
19 lines
402 B
Rust
#![feature(never_type)]
|
|
|
|
enum Helper<T, U> {
|
|
T(T, [!; 0]),
|
|
#[allow(dead_code)]
|
|
U(U),
|
|
}
|
|
|
|
fn transmute<T, U>(t: T) -> U {
|
|
let Helper::U(u) = Helper::T(t, []);
|
|
//~^ ERROR refutable pattern in local binding: `T(_, _)` not covered
|
|
u
|
|
//~^ ERROR use of possibly uninitialized variable: `u`
|
|
}
|
|
|
|
fn main() {
|
|
println!("{:?}", transmute::<&str, (*const u8, u64)>("type safety"));
|
|
}
|