rust/compiler/rustc_lint/src
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
..
nonstandard_style
array_into_iter.rs make the reason: field mandatory for @future_incompatible lints 2023-09-22 08:59:32 +02:00
async_fn_in_trait.rs Apply suggestions from code review 2023-10-04 18:20:05 -04:00
builtin.rs Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
context.rs Fix ICE by introducing an expr_or_init variant for outside bodies 2023-09-27 18:59:24 +02:00
deref_into_dyn_supertrait.rs make the reason: field mandatory for @future_incompatible lints 2023-09-22 08:59:32 +02:00
drop_forget_useless.rs Fix dropping_copy_types lint from linting in match-arm with side-effects 2023-07-01 16:05:55 +02:00
early.rs diagnostics: avoid wrong unused_parens on x as (T) < y 2023-08-31 20:14:49 -07:00
enum_intrinsics_non_enums.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
errors.rs feat(rustc_lint): make CheckLintName respect lint level 2023-08-30 19:24:44 +01:00
expect.rs Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
for_loops_over_fallibles.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
foreign_modules.rs Remove rustc_lint_defs::lint_array 2023-09-28 23:01:25 +02:00
hidden_unicode_codepoints.rs migrate: hidden_unicode_codepoints.rs 2023-01-09 17:07:25 -05:00
internal.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
invalid_from_utf8.rs Fix ICE by introducing an expr_or_init variant for outside bodies 2023-09-27 18:59:24 +02:00
late.rs Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors 2023-09-14 06:29:23 +00:00
let_underscore.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
levels.rs Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors 2023-09-14 06:29:23 +00:00
lib.rs Add async_fn_in_trait lint 2023-10-03 00:37:18 +00:00
lints.rs Rollup merge of #116421 - Urgau:inter-mut-invalid_ref_casting, r=oli-obk 2023-10-06 06:23:48 +02:00
map_unit_fn.rs Fix #109152, fix the scenario that we may can not get span of func 2023-03-15 14:07:39 +08:00
methods.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
multiple_supertrait_upcastable.rs Add missing feature gate in multiple_supertrait_upcastable doc 2023-07-31 12:28:53 +01:00
non_ascii_idents.rs Reword confusable idents lint 2023-08-04 16:46:08 +00:00
non_fmt_panic.rs Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
nonstandard_style.rs allow host param to be lowercase 2023-07-04 11:47:46 +00:00
noop_method_call.rs Fix noop_method_call detection for new diagnostic items 2023-09-28 08:22:59 -04:00
opaque_hidden_inferred_bound.rs non_lifetime_binders: fix ICE in lint opaque-hidden-inferred-bound 2023-10-03 13:59:59 +02:00
pass_by_value.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
passes.rs Remove rustc_lint_defs::lint_array 2023-09-28 23:01:25 +02:00
ptr_nulls.rs Improve diagnostics and add tests for function calls 2023-08-06 19:08:14 +02:00
redundant_semicolon.rs refactor: cleanup 2023-01-09 18:57:02 -05:00
reference_casting.rs Clarify invalid_reference_casting lint around interior mutable types 2023-10-04 22:06:16 +02:00
tests.rs refactor(rustc_lint): inline check_lint_name_cmdline 2023-08-30 17:35:07 +01:00
traits.rs make comments less cryptic 2023-09-06 12:09:29 +03:00
types.rs Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
unused.rs Move let expression checking to parsing 2023-09-11 15:51:18 +00:00