Skip to content

Commit

Permalink
Rollup merge of #103996 - SUPERCILEX:docs, r=RalfJung
Browse files Browse the repository at this point in the history
Add small clarification around using pointers derived from references

r? `@RalfJung`

One question about your example from rust-lang/libs-team#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?
}
```
  • Loading branch information
matthiaskrgr committed Nov 13, 2022
2 parents 92c06b5 + b776a79 commit e5b6ca1
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit e5b6ca1

Please sign in to comment.