diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-16 20:10:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-16 20:10:37 +0200 |
| commit | 2667d853a63736d5d4feba464a24b8fa03881b4a (patch) | |
| tree | c801cdddce6a5be6ab04e5c2b24fba56ac83efc8 /library/core/src | |
| parent | 52d69476a6b6202b8d3f525319ca0fc635497674 (diff) | |
| parent | 91b05f8e098b310a27fa1b1eaeb7d830790d513a (diff) | |
| download | rust-2667d853a63736d5d4feba464a24b8fa03881b4a.tar.gz rust-2667d853a63736d5d4feba464a24b8fa03881b4a.zip | |
Rollup merge of #114784 - Urgau:many-improve-invalid_reference_casting-lint, r=est31
Improve `invalid_reference_casting` lint This PR improves the `invalid_reference_casting` lint: - by considering an unlimited number of casts instead only const to mut ptr - by also considering ptr-to-integer and integer-to-ptr casts - by also taking into account [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast), [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1) and [`ptr::cast_const`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const) Most of this improvements comes from skimming Github Code Search result for [`&mut \*.*as \*const`](https://github.com/search?q=lang%3Arust+%2F%26mut+%5C*.*as+%5C*const%2F&type=code) r? ``@est31`` (maybe)
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/ptr/const_ptr.rs | 1 | ||||
| -rw-r--r-- | library/core/src/ptr/mut_ptr.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 502f8a75863..ee69d89a4b7 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -55,6 +55,7 @@ impl<T: ?Sized> *const T { /// Casts to a pointer of another type. #[stable(feature = "ptr_cast", since = "1.38.0")] #[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")] + #[rustc_diagnostic_item = "const_ptr_cast"] #[inline(always)] pub const fn cast<U>(self) -> *const U { self as _ diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index d129e1d645f..9dbb3f9d322 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -112,6 +112,7 @@ impl<T: ?Sized> *mut T { /// [`cast_mut`]: #method.cast_mut #[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_const"] #[inline(always)] pub const fn cast_const(self) -> *const T { self as _ |
