mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 00:17:44 +00:00
![]() 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` |
||
---|---|---|
.. | ||
nonstandard_style | ||
array_into_iter.rs | ||
async_fn_in_trait.rs | ||
builtin.rs | ||
context.rs | ||
deref_into_dyn_supertrait.rs | ||
drop_forget_useless.rs | ||
early.rs | ||
enum_intrinsics_non_enums.rs | ||
errors.rs | ||
expect.rs | ||
for_loops_over_fallibles.rs | ||
foreign_modules.rs | ||
hidden_unicode_codepoints.rs | ||
internal.rs | ||
invalid_from_utf8.rs | ||
late.rs | ||
let_underscore.rs | ||
levels.rs | ||
lib.rs | ||
lints.rs | ||
map_unit_fn.rs | ||
methods.rs | ||
multiple_supertrait_upcastable.rs | ||
non_ascii_idents.rs | ||
non_fmt_panic.rs | ||
nonstandard_style.rs | ||
noop_method_call.rs | ||
opaque_hidden_inferred_bound.rs | ||
pass_by_value.rs | ||
passes.rs | ||
ptr_nulls.rs | ||
redundant_semicolon.rs | ||
reference_casting.rs | ||
tests.rs | ||
traits.rs | ||
types.rs | ||
unused.rs |