Closed
Description
All of the below code seems to be neccesary to reproduce the bug; If ALL_THE_NUMS
is accessed directly within main, the program works as expected.
Example:
fn get_element() -> &'static u32 {
return &ALL_THE_NUMS[0];
}
const ALL_THE_NUMS : [u32; 1] = [
1
];
fn main(){
println!("Num is {}", get_element());
}
I expected to see this happen: Num is 1
as the output, or a compiler error if I'm doing something wrong here (am I?)
Instead, this happened: Num is 32766
or some other garbage value is output
Meta
rustc --version --verbose
:
rustc 1.25.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.25.0
LLVM version: 6.0
Also tested on master-branch version: (same result)
rustc 1.27.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.27.0-dev
LLVM version: 6.0
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerCategory: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.Bugs fixed, but only when NLL is enabled.Performance or correctness regression from one stable version to another.