Merge pull request #2987 from RalfJung/raw-addr-of

RFC 2582: fix implicit auto-deref of raw pointers
This commit is contained in:
Mark Rousskov 2020-10-04 19:18:10 -04:00 committed by GitHub
commit 0e6ebf0429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -198,14 +198,14 @@ This has the side-effect of being able to entirely remove reference-to-pointer-*
```rust ```rust
let x: *mut Struct = NonNull::dangling().as_ptr(); let x: *mut Struct = NonNull::dangling().as_ptr();
let field: *mut Field = &mut x.field; let field: *mut Field = &mut (*x).field;
``` ```
The lint as described in this RFC would nudge people to instead write The lint as described in this RFC would nudge people to instead write
```rust ```rust
let x: *mut Struct = NonNull::dangling().as_ptr(); let x: *mut Struct = NonNull::dangling().as_ptr();
let field: *mut Field = &raw mut x.field; let field: *mut Field = &raw mut (*x).field;
``` ```
which is better, but still UB: we emit a `getelementptr inbounds` for the `.field` offset computation. which is better, but still UB: we emit a `getelementptr inbounds` for the `.field` offset computation.