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 'a859e5cc1c' into clippyup 2023-12-16 14:12:50 +01:00
as_underscore.rs Merge commit 'f51aade56f' into clippyup 2022-08-31 09:24:45 -04:00
borrow_as_ptr.rs Merge commit '37f4c1725d' into clippyup 2023-07-02 14:59:02 +02:00
cast_abs_to_unsigned.rs Merge commit '09ac14c901' into clippyup 2023-11-02 17:35:56 +01:00
cast_enum_constructor.rs Merge commit 'd0cf3481a8' into clippyup 2022-03-24 14:50:04 +01:00
cast_lossless.rs Merge commit '09ac14c901' into clippyup 2023-11-02 17:35:56 +01:00
cast_nan_to_int.rs Merge commit '435a8ad86c' into clippyup 2023-05-20 15:39:26 +02:00
cast_possible_truncation.rs Merge commit '7671c283a5' into clippyup 2023-09-25 11:28:58 +02:00
cast_possible_wrap.rs Merge commit 'edb720b199' into clippyup 2023-11-16 19:13:24 +01:00
cast_precision_loss.rs Merge commit 'b7f3f7f608' into clippyup 2021-10-07 11:21:30 +02:00
cast_ptr_alignment.rs Merge commit '09ac14c901' into clippyup 2023-11-02 17:35:56 +01:00
cast_sign_loss.rs Merge commit '26ac6aab02' 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 'edb720b199' into clippyup 2023-11-16 19:13:24 +01:00
char_lit_as_u8.rs Merge commit 'edb720b199' into clippyup 2023-11-16 19:13:24 +01:00
fn_to_numeric_cast.rs Merge commit 'ac0e10aa68' into clippyup 2022-10-06 09:44:38 +02:00
fn_to_numeric_cast_any.rs Merge commit 'ac0e10aa68' into clippyup 2022-10-06 09:44:38 +02:00
fn_to_numeric_cast_with_truncation.rs Merge commit 'ac0e10aa68' into clippyup 2022-10-06 09:44:38 +02:00
mod.rs Add ref_as_ptr lint 2024-02-04 17:38:09 +01:00
ptr_as_ptr.rs Merge commit 'a859e5cc1c' into clippyup 2023-12-16 14:12:50 +01:00
ptr_cast_constness.rs Merge commit 'edb720b199' 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 Improve AdtDef interning. 2022-03-11 13:31:24 +11:00
zero_ptr.rs Merge commit '7671c283a5' into clippyup 2023-09-25 11:28:58 +02:00