Skip to content

Commit

Permalink
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, …
Browse files Browse the repository at this point in the history
…r=cjgillot

Expand, rename and improve `incorrect_fn_null_checks` lint

This PR,

 - firstly, expand the lint by now linting on references
 - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks`
 - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut`

Fixes rust-lang/rust#113601
cc ```@est31```
  • Loading branch information
matthiaskrgr committed Aug 3, 2023
2 parents ec08074 + b04da8a commit c4874fe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ pub const fn from_ref<T: ?Sized>(r: &T) -> *const T {
#[inline(always)]
#[must_use]
#[unstable(feature = "ptr_from_ref", issue = "106116")]
#[rustc_diagnostic_item = "ptr_from_mut"]
pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
r
}
Expand Down
1 change: 1 addition & 0 deletions core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl<T: ?Sized> *mut 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 = "ptr_cast"]
#[inline(always)]
pub const fn cast<U>(self) -> *mut U {
self as _
Expand Down

0 comments on commit c4874fe

Please sign in to comment.