Open
Description
Based on an example by @theemathas:
enum Never {}
static X: &Never = weird(&X);
const fn weird(a: &&Never) -> &'static Never {
// SAFETY: our argument type has an unsatisfiable
// library invariant; therefore, this code is unreachable.
unsafe { std::hint::unreachable_unchecked() };
}
error[E0080]: could not evaluate static initializer
--> src/lib.rs:3:20
|
3 | static X: &Never = weird(&X);
| ^^^^^^^^^ entering unreachable code
|
note: inside `weird`
--> src/lib.rs:8:14
|
8 | unsafe { std::hint::unreachable_unchecked() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `unreachable_unchecked`
--> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/hint.rs:109:14
|
109 | unsafe { intrinsics::unreachable() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
I can't see anything wrong about weird
. Therefore, this is UB from entirely sound code.
Cc @rust-lang/opsem @rust-lang/wg-const-eval
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Nominated for discussion during a lang team meeting.Issue: Indicates that prioritization has been requested for this issue.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessLang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langThis issue may need triage. Remove it if it has been sufficiently triaged.