Open
Description
enum Never {}
fn foo() -> impl Sized {
let ret = 'block: {
break 'block foo();
};
let _: Never = ret;
ret
}
results in the following MIR:
// MIR for `foo` after built
| User Type Annotations
| 0: user_ty: Canonical { value: Ty(Never), max_universe: U0, variables: [], defining_opaque_types: [DefId(0:6 ~ main[7eb4]::foo::{opaque#0})] }, span: src/main.rs:6:12: 6:17, inferred_ty: Never
| 1: user_ty: Canonical { value: Ty(Never), max_universe: U0, variables: [], defining_opaque_types: [DefId(0:6 ~ main[7eb4]::foo::{opaque#0})] }, span: src/main.rs:6:12: 6:17, inferred_ty: Never
|
fn foo() -> impl Sized {
let mut _0: impl Sized;
let _1: impl Sized;
scope 1 {
debug ret => _1;
scope 2 {
}
}
bb0: {
StorageLive(_1);
_1 = foo() -> [return: bb1, unwind: bb6];
}
bb1: {
goto -> bb3;
}
bb2: {
_1 = const ();
goto -> bb4;
}
bb3: {
goto -> bb4;
}
bb4: {
FakeRead(ForLet(None), _1);
PlaceMention(_1);
AscribeUserType((_1 as Never), +, UserTypeProjection { base: UserType(1), projs: [] });
_0 = move _1;
StorageDead(_1);
return;
}
bb5: {
FakeRead(ForMatchedPlace(None), _1);
unreachable;
}
bb6 (cleanup): {
resume;
}
}
notice the _1 = const ();
which assigns unit to impl Sized
even though its type is Never
.
This should result in a type error and therefore an ICE, but apparently we never even get to test that as the block is entirely dead code 🤔 cc @oli-obk
rust/compiler/rustc_mir_build/src/build/block.rs
Lines 342 to 354 in fbce03b
Activity