diff options
| author | bors <bors@rust-lang.org> | 2023-06-01 01:27:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-01 01:27:32 +0000 |
| commit | ba1690bedd6ada4e8d91bfecb3d0ccc2b6de85ba (patch) | |
| tree | 6e669dc7e3fd97892062894efef4a9b56e8edad1 /library/core/src/ptr | |
| parent | 9af3865deca9c601ef32ef4ed29f7cae5fed50a9 (diff) | |
| parent | 32d4e1c3c71fa30c83405eee7ff8b9bba6a903f0 (diff) | |
| download | rust-ba1690bedd6ada4e8d91bfecb3d0ccc2b6de85ba.tar.gz rust-ba1690bedd6ada4e8d91bfecb3d0ccc2b6de85ba.zip | |
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
Diffstat (limited to 'library/core/src/ptr')
| -rw-r--r-- | library/core/src/ptr/const_ptr.rs | 1 | ||||
| -rw-r--r-- | library/core/src/ptr/mod.rs | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index c579c3672a7..926189a17b2 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -104,6 +104,7 @@ impl<T: ?Sized> *const T { /// refactored. #[stable(feature = "ptr_const_cast", since = "1.65.0")] #[rustc_const_stable(feature = "ptr_const_cast", since = "1.65.0")] + #[rustc_diagnostic_item = "ptr_cast_mut"] #[inline(always)] pub const fn cast_mut(self) -> *mut T { self as _ diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index d0cb2f715d0..acc9ca29d41 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -698,6 +698,7 @@ where #[inline(always)] #[must_use] #[unstable(feature = "ptr_from_ref", issue = "106116")] +#[rustc_diagnostic_item = "ptr_from_ref"] pub const fn from_ref<T: ?Sized>(r: &T) -> *const T { r } |
