rust/clippy_lints/src/casts
bors 34e4c9fa4a Auto merge of #12087 - marcin-serwin:ref_as_ptr_cast, r=blyxyas
Add new lint: `ref_as_ptr`

Fixes #10130

Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead.

The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention.

Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884).

---

changelog: New lint: [`ref_as_ptr`]
[#12087](https://github.com/rust-lang/rust-clippy/pull/12087)
2024-02-04 17:07:18 +00:00
..
as_ptr_cast_mut.rs Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup 2023-12-16 14:12:50 +01:00
as_underscore.rs
borrow_as_ptr.rs
cast_abs_to_unsigned.rs Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
cast_enum_constructor.rs
cast_lossless.rs Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
cast_nan_to_int.rs
cast_possible_truncation.rs
cast_possible_wrap.rs Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
cast_precision_loss.rs
cast_ptr_alignment.rs Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
cast_sign_loss.rs Merge commit '26ac6aab023393c94edf42f38f6ad31196009643' 2024-01-11 17:27:03 +01:00
cast_slice_different_sizes.rs Move some methods from tcx.hir() to tcx 2023-12-12 06:40:29 -08:00
cast_slice_from_raw_parts.rs Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
char_lit_as_u8.rs Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
fn_to_numeric_cast_any.rs
fn_to_numeric_cast_with_truncation.rs
fn_to_numeric_cast.rs
mod.rs Add ref_as_ptr lint 2024-02-04 17:38:09 +01:00
ptr_as_ptr.rs Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup 2023-12-16 14:12:50 +01:00
ptr_cast_constness.rs Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
ref_as_ptr.rs Add ref_as_ptr lint 2024-02-04 17:38:09 +01:00
unnecessary_cast.rs Pack the u128 in LitKind::Int 2024-01-19 20:10:39 -08:00
utils.rs
zero_ptr.rs