]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #103996 - SUPERCILEX:docs, r=RalfJung
authorMatthias Krüger <matthias.krueger@famsik.de>
Sun, 13 Nov 2022 16:37:36 +0000 (17:37 +0100)
committerGitHub <noreply@github.com>
Sun, 13 Nov 2022 16:37:36 +0000 (17:37 +0100)
commita1b0702ea5efd2f1bacc2bb5cfac7b82abc58bc5
tree08aac459556ddc8fc45fde8331e90a206b6d4eea
parentafd7977c850d9ce06f1dd2bebb40db8cc2224a51
parent28ea0023408d9edcc61e89b9f511528e4757a53e
Rollup merge of #103996 - SUPERCILEX:docs, r=RalfJung

Add small clarification around using pointers derived from references

r? `@RalfJung`

One question about your example from https://github.com/rust-lang/libs-team/issues/122: at what point does UB arise? If writing 0 does not cause UB and the reference `x` is never read or written to (explicitly or implicitly by being wrapped in another data structure) after the call to `foo`, does UB only arise when dropping the value? I don't really get that since I thought references were always supposed to point to valid data?

```rust
fn foo(x: &mut NonZeroI32)  {
  let ptr = x as *mut NonZeroI32;
  unsafe { ptr.cast::<i32>().write(0); } // no UB here
  // What now? x is considered garbage when?
}
```