You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f2f26bc
Browse filesBrowse the repository at this point in the historyBrowse files
Rollup merge of #164088 - RalfJung:const-check-ub, r=oli-obk
const-check: clarify when and how we can rely on non-UB assumptions
Turns out const-checking relies on `&x` being immutable. This is the "most obvious" property we get from the aliasing model, and we emit LLVM attributes and have MIR-opts that rely on it. I just didn't realize that taking away this UB would actually be a breaking change; there is code that runs on stable that we'd have to stop accepting if we took away this UB:
```rust
struct NotConstDestruct;
impl Drop for NotConstDestruct {
fn drop(&mut self) {
eprintln!("this is not const");
}
}
const _: () = {
let x = None::<NotConstDestruct>;
let ptr = std::ptr::from_ref(&x);
unsafe { ptr.cast_mut().write(Some(NotConstDestruct)) };
};
```
This means that I accidentally fixed a hole in const-checking when I added `&` immutability checking to const-eval.
r? @oli-obk
Cc @rust-lang/opsem@tmiasko
0 commit comments