Closed
Description
#![feature(const_fn)]
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
union Transmute<T: Copy, U: Copy> {
from: T,
to: U,
}
Transmute { from: t }.to
}
const fn wat(x: u64) -> &'static u64 {
unsafe { transmute(&x) }
}
const X: u64 = *wat(42);
fn main() {
println!("{}", X);
}
produces
error[E0080]: constant evaluation error
--> src/main.rs:18:20
|
18 | println!("{}", X);
| ^ referenced constant has errors
without any additional info. If the value is not dereferenced, but instead fed to llvm, we get an ICE in trans:
#![feature(const_fn)]
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
union Transmute<T: Copy, U: Copy> {
from: T,
to: U,
}
Transmute { from: t }.to
}
const fn wat(x: u64) -> u64 {
unsafe { transmute(&x) }
}
const X: u64 = wat(42);
fn main() {
println!("{}", X);
}
results in
error: internal compiler error: librustc_mir/monomorphize/collector.rs:1131: alloc id without corresponding allocation: 39
Even though it should be reporting a dangling pointer const eval error
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Messages for errors, warnings, and lintsCategory: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.