1
Fork 0
rust/compiler/rustc_span/src
bors ba1690bedd Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber
Uplift `clippy::cast_ref_to_mut` lint

This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc.

## `cast_ref_to_mut`

(deny-by-default)

The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability.

### Example

```rust,compile_fail
fn x(r: &i32) {
    unsafe {
        *(r as *const i32 as *mut i32) += 1;
    }
}
```

### Explanation

Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-06-01 01:27:32 +00:00
..
analyze_source_file remove redundant closures (clippy::redundant_closure) 2021-01-03 13:34:24 +01:00
edit_distance Add test for precise algorithm used 2023-02-19 22:59:22 +00:00
source_map Auto merge of #106810 - oli-obk:resolver_reverse_plumbing, r=petrochenkov 2023-01-19 05:23:40 +00:00
symbol Move the Lock into symbol::Interner 2021-09-15 18:46:45 +02:00
analyze_source_file.rs more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
caching_source_map_view.rs Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
def_id.rs Only depend on CFG_VERSION in rustc_interface 2023-05-17 23:54:21 -05:00
edit_distance.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
edition.rs Rename rust_2015 => is_rust_2015 2023-02-02 08:17:13 +00:00
fatal_error.rs Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
hygiene.rs Lower the tracing level of some very verbose messages 2023-05-30 16:03:24 +00:00
lib.rs Remove ExpnKind::Inlined. 2023-05-25 16:43:14 +00:00
profiling.rs Remove an unnecessary use of with_session_globals. 2023-03-31 15:34:00 +11:00
source_map.rs Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
span_encoding.rs Refactor SyntaxContext::ctxt logic. 2023-04-18 18:00:21 +00:00
symbol.rs Add diagnostic items for ptr::cast_mut and ptr::from_ref 2023-05-31 12:26:36 +02:00
tests.rs Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00