diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-10-06 06:23:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-06 06:23:48 +0200 |
| commit | 7d7004d3e64c27cdc71b06c177506edc11040410 (patch) | |
| tree | 1c8582265ef62e5595e2bb682d60c37abdbb85ce /compiler/rustc_driver_impl/src | |
| parent | 579be69de9f98f56d92b93820eaf7e6b06b517a5 (diff) | |
| parent | e46236cceb03a5f58cae91b9d8a1b18040443b5c (diff) | |
| download | rust-7d7004d3e64c27cdc71b06c177506edc11040410.tar.gz rust-7d7004d3e64c27cdc71b06c177506edc11040410.zip | |
Rollup merge of #116421 - Urgau:inter-mut-invalid_ref_casting, r=oli-obk
Clarify `invalid_reference_casting` lint around interior mutable types
This is PR intends to clarify the `invalid_reference_casting` lint around interior mutable types by adding a note for them saying that they should go through `UnsafeCell::get`.
So for this code:
```rust
let cell = &std::cell::UnsafeCell::new(0);
let _num = &mut *(cell as *const _ as *mut i32);
```
the following note will be added to the lint output:
```diff
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
--> $DIR/reference_casting.rs:68:16
|
LL | let _num = &mut *(cell as *const _ as *mut i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
+ = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
```
Suggestion are welcome around the note contents.
Fixes https://github.com/rust-lang/rust/issues/116410
cc `@RalfJung`
Diffstat (limited to 'compiler/rustc_driver_impl/src')
0 files changed, 0 insertions, 0 deletions
