Closed
Description
I tried this code:
static FOO: u8 = 42;
static mut BAR: &'static u8 = &FOO;
fn main() {
unsafe {
println!("{}", BAR);
foo();
println!("{}", BAR);
}
}
fn foo() {
let n = 42;
unsafe {
BAR = &n;
}
}
I expected to see this:
error[E0597]: `n` does not live long enough
--> src/main.rs:15:15
|
15 | BAR = &n;
| ------^^
| | |
| | borrowed value does not live long enough
| assignment requires that `n` is borrowed for `'static`
16 | }
17 | }
| - `n` dropped here while still borrowed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.
Instead, happens undefined behavior. Program successfully compiles in the Rust stable 1.41.0
but fails to compile in stable 1.40.0
(thats what I want).
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerArea: Lifetimes / regionsCategory: 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.Performance or correctness regression from one stable version to another.