mirror of https://github.com/rust-lang/rfcs.git
Merge pull request #2987 from RalfJung/raw-addr-of
RFC 2582: fix implicit auto-deref of raw pointers
This commit is contained in:
commit
0e6ebf0429
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue