Files
rust/tests/ui
Matthias Krüger 7d7004d3e6 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`
2023-10-06 06:23:48 +02:00
..
2023-09-19 12:48:40 +00:00
2023-09-22 18:57:27 +03:00
2023-10-05 01:04:41 +00:00
2023-09-21 17:31:25 +02:00
2023-10-04 08:01:11 +08:00
2023-09-21 08:17:58 +02:00
2023-10-04 08:01:11 +08:00
2023-10-04 18:12:20 +11:00
2023-07-17 22:06:32 +00:00
2023-09-19 12:48:40 +00:00
2023-09-06 12:09:29 +03:00
2023-09-13 15:00:31 +00:00
2023-08-07 19:06:18 +00:00
2023-09-23 13:47:30 +00:00
2023-09-25 19:05:10 +02:00
2023-09-13 15:00:31 +00:00
2023-08-28 17:47:37 -03:00
2023-10-05 01:04:41 +00:00
2023-07-29 11:47:26 +02:00
2023-10-05 01:04:41 +00:00
2023-10-05 01:04:41 +00:00
2023-08-06 13:34:53 +00:00
2023-08-14 16:57:51 -07:00
2023-10-02 23:14:29 +00:00
2023-08-15 00:57:18 +08:00
2023-09-18 17:29:13 +01:00
2023-10-05 01:04:41 +00:00
2023-10-05 18:56:30 +03:00
2023-08-26 19:25:46 +00:00
2023-10-05 01:04:41 +00:00
2023-09-10 23:06:14 +02:00
2023-09-10 23:06:14 +02:00