-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
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).
tesuji and Aaron1011ecstatic-morse, darksv, jonas-schievink, parasyte, 95th and 3 more
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.