From 5ab42d8e6a7fac7cfe5f06b7467d97c1138ebd46 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sat, 10 Feb 2024 09:21:15 -0500 Subject: [PATCH] Take lifetime extension into account in `ref_as_ptr` --- clippy_lints/src/casts/ref_as_ptr.rs | 12 +- tests/ui/ref_as_ptr.fixed | 88 +++++----- tests/ui/ref_as_ptr.rs | 88 +++++----- tests/ui/ref_as_ptr.stderr | 244 +++++++++++++-------------- 4 files changed, 226 insertions(+), 206 deletions(-) diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs index d600d2aec1b..9d5a486336d 100644 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ b/clippy_lints/src/casts/ref_as_ptr.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_no_std_crate; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; +use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode}; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability, Ty, TyKind}; use rustc_lint::LateContext; @@ -9,7 +9,12 @@ use super::REF_AS_PTR; -pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to_hir_ty: &Ty<'_>) { +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + expr: &'tcx Expr<'_>, + cast_expr: &'tcx Expr<'_>, + cast_to_hir_ty: &Ty<'_>, +) { let (cast_from, cast_to) = ( cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr), @@ -17,6 +22,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, if matches!(cast_from.kind(), ty::Ref(..)) && let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind() + && let Some(use_cx) = expr_use_ctxt(cx, expr) + // TODO: only block the lint if `cast_expr` is a temporary + && !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_)) { let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" }; let fn_name = match to_mutbl { diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index 7a946393f25..466a628a002 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -1,55 +1,61 @@ #![warn(clippy::ref_as_ptr)] #![allow(clippy::unnecessary_mut_passed)] +fn f(_: T) {} + fn main() { - let _ = std::ptr::from_ref(&1u8); - let _ = std::ptr::from_ref::(&2u32); - let _ = std::ptr::from_ref::(&3.0f64); + f(std::ptr::from_ref(&1u8)); + f(std::ptr::from_ref::(&2u32)); + f(std::ptr::from_ref::(&3.0f64)); - let _ = std::ptr::from_ref(&4) as *const f32; - let _ = std::ptr::from_ref::(&5.0f32) as *const u32; + f(std::ptr::from_ref(&4) as *const f32); + f(std::ptr::from_ref::(&5.0f32) as *const u32); - let _ = std::ptr::from_ref(&mut 6u8); - let _ = std::ptr::from_ref::(&mut 7u32); - let _ = std::ptr::from_ref::(&mut 8.0f64); + f(std::ptr::from_ref(&mut 6u8)); + f(std::ptr::from_ref::(&mut 7u32)); + f(std::ptr::from_ref::(&mut 8.0f64)); - let _ = std::ptr::from_ref(&mut 9) as *const f32; - let _ = std::ptr::from_ref::(&mut 10.0f32) as *const u32; + f(std::ptr::from_ref(&mut 9) as *const f32); + f(std::ptr::from_ref::(&mut 10.0f32) as *const u32); - let _ = std::ptr::from_mut(&mut 11u8); - let _ = std::ptr::from_mut::(&mut 12u32); - let _ = std::ptr::from_mut::(&mut 13.0f64); + f(std::ptr::from_mut(&mut 11u8)); + f(std::ptr::from_mut::(&mut 12u32)); + f(std::ptr::from_mut::(&mut 13.0f64)); - let _ = std::ptr::from_mut(&mut 14) as *const f32; - let _ = std::ptr::from_mut::(&mut 15.0f32) as *const u32; + f(std::ptr::from_mut(&mut 14) as *const f32); + f(std::ptr::from_mut::(&mut 15.0f32) as *const u32); - let _ = std::ptr::from_ref(&1u8); - let _ = std::ptr::from_ref::(&2u32); - let _ = std::ptr::from_ref::(&3.0f64); + f(std::ptr::from_ref(&1u8)); + f(std::ptr::from_ref::(&2u32)); + f(std::ptr::from_ref::(&3.0f64)); - let _ = std::ptr::from_ref(&4) as *const f32; - let _ = std::ptr::from_ref::(&5.0f32) as *const u32; + f(std::ptr::from_ref(&4) as *const f32); + f(std::ptr::from_ref::(&5.0f32) as *const u32); let val = 1; - let _ = std::ptr::from_ref(&val); - let _ = std::ptr::from_ref::(&val); + f(std::ptr::from_ref(&val)); + f(std::ptr::from_ref::(&val)); - let _ = std::ptr::from_ref(&val) as *const f32; - let _ = std::ptr::from_ref::(&val) as *const f64; + f(std::ptr::from_ref(&val) as *const f32); + f(std::ptr::from_ref::(&val) as *const f64); let mut val: u8 = 2; - let _ = std::ptr::from_mut::(&mut val); - let _ = std::ptr::from_mut(&mut val); + f(std::ptr::from_mut::(&mut val)); + f(std::ptr::from_mut(&mut val)); - let _ = std::ptr::from_ref::(&mut val); - let _ = std::ptr::from_ref(&mut val); + f(std::ptr::from_ref::(&mut val)); + f(std::ptr::from_ref(&mut val)); - let _ = std::ptr::from_ref::(&mut val) as *const f64; - let _: *const Option = std::ptr::from_ref(&mut val) as *const _; + f(std::ptr::from_ref::(&mut val) as *const f64); + f::<*const Option>(std::ptr::from_ref(&mut val) as *const _); - let _ = std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i)); - let _ = std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i)); - let _ = std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i)); + f(std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))); + f(std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))); + f(std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))); + + let _ = &String::new() as *const _; + let _ = &mut String::new() as *mut _; + const FOO: *const String = &String::new() as *const _; } #[clippy::msrv = "1.75"] @@ -58,8 +64,8 @@ fn _msrv_1_75() { let mut_val = &mut 42_i32; // `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this - let _ = val as *const i32; - let _ = mut_val as *mut i32; + f(val as *const i32); + f(mut_val as *mut i32); } #[clippy::msrv = "1.76"] @@ -67,18 +73,18 @@ fn _msrv_1_76() { let val = &42_i32; let mut_val = &mut 42_i32; - let _ = std::ptr::from_ref::(val); - let _ = std::ptr::from_mut::(mut_val); + f(std::ptr::from_ref::(val)); + f(std::ptr::from_mut::(mut_val)); } fn foo(val: &[u8]) { - let _ = std::ptr::from_ref(val); - let _ = std::ptr::from_ref::<[u8]>(val); + f(std::ptr::from_ref(val)); + f(std::ptr::from_ref::<[u8]>(val)); } fn bar(val: &mut str) { - let _ = std::ptr::from_mut(val); - let _ = std::ptr::from_mut::(val); + f(std::ptr::from_mut(val)); + f(std::ptr::from_mut::(val)); } struct X<'a>(&'a i32); diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index 6f745505b46..0fdc753dc22 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -1,55 +1,61 @@ #![warn(clippy::ref_as_ptr)] #![allow(clippy::unnecessary_mut_passed)] +fn f(_: T) {} + fn main() { - let _ = &1u8 as *const _; - let _ = &2u32 as *const u32; - let _ = &3.0f64 as *const f64; + f(&1u8 as *const _); + f(&2u32 as *const u32); + f(&3.0f64 as *const f64); - let _ = &4 as *const _ as *const f32; - let _ = &5.0f32 as *const f32 as *const u32; + f(&4 as *const _ as *const f32); + f(&5.0f32 as *const f32 as *const u32); - let _ = &mut 6u8 as *const _; - let _ = &mut 7u32 as *const u32; - let _ = &mut 8.0f64 as *const f64; + f(&mut 6u8 as *const _); + f(&mut 7u32 as *const u32); + f(&mut 8.0f64 as *const f64); - let _ = &mut 9 as *const _ as *const f32; - let _ = &mut 10.0f32 as *const f32 as *const u32; + f(&mut 9 as *const _ as *const f32); + f(&mut 10.0f32 as *const f32 as *const u32); - let _ = &mut 11u8 as *mut _; - let _ = &mut 12u32 as *mut u32; - let _ = &mut 13.0f64 as *mut f64; + f(&mut 11u8 as *mut _); + f(&mut 12u32 as *mut u32); + f(&mut 13.0f64 as *mut f64); - let _ = &mut 14 as *mut _ as *const f32; - let _ = &mut 15.0f32 as *mut f32 as *const u32; + f(&mut 14 as *mut _ as *const f32); + f(&mut 15.0f32 as *mut f32 as *const u32); - let _ = &1u8 as *const _; - let _ = &2u32 as *const u32; - let _ = &3.0f64 as *const f64; + f(&1u8 as *const _); + f(&2u32 as *const u32); + f(&3.0f64 as *const f64); - let _ = &4 as *const _ as *const f32; - let _ = &5.0f32 as *const f32 as *const u32; + f(&4 as *const _ as *const f32); + f(&5.0f32 as *const f32 as *const u32); let val = 1; - let _ = &val as *const _; - let _ = &val as *const i32; + f(&val as *const _); + f(&val as *const i32); - let _ = &val as *const _ as *const f32; - let _ = &val as *const i32 as *const f64; + f(&val as *const _ as *const f32); + f(&val as *const i32 as *const f64); let mut val: u8 = 2; - let _ = &mut val as *mut u8; - let _ = &mut val as *mut _; + f(&mut val as *mut u8); + f(&mut val as *mut _); - let _ = &mut val as *const u8; - let _ = &mut val as *const _; + f(&mut val as *const u8); + f(&mut val as *const _); - let _ = &mut val as *const u8 as *const f64; - let _: *const Option = &mut val as *const _ as *const _; + f(&mut val as *const u8 as *const f64); + f::<*const Option>(&mut val as *const _ as *const _); - let _ = &std::array::from_fn(|i| i * i) as *const [usize; 7]; - let _ = &mut std::array::from_fn(|i| i * i) as *const [usize; 8]; - let _ = &mut std::array::from_fn(|i| i * i) as *mut [usize; 9]; + f(&std::array::from_fn(|i| i * i) as *const [usize; 7]); + f(&mut std::array::from_fn(|i| i * i) as *const [usize; 8]); + f(&mut std::array::from_fn(|i| i * i) as *mut [usize; 9]); + + let _ = &String::new() as *const _; + let _ = &mut String::new() as *mut _; + const FOO: *const String = &String::new() as *const _; } #[clippy::msrv = "1.75"] @@ -58,8 +64,8 @@ fn _msrv_1_75() { let mut_val = &mut 42_i32; // `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this - let _ = val as *const i32; - let _ = mut_val as *mut i32; + f(val as *const i32); + f(mut_val as *mut i32); } #[clippy::msrv = "1.76"] @@ -67,18 +73,18 @@ fn _msrv_1_76() { let val = &42_i32; let mut_val = &mut 42_i32; - let _ = val as *const i32; - let _ = mut_val as *mut i32; + f(val as *const i32); + f(mut_val as *mut i32); } fn foo(val: &[u8]) { - let _ = val as *const _; - let _ = val as *const [u8]; + f(val as *const _); + f(val as *const [u8]); } fn bar(val: &mut str) { - let _ = val as *mut _; - let _ = val as *mut str; + f(val as *mut _); + f(val as *mut str); } struct X<'a>(&'a i32); diff --git a/tests/ui/ref_as_ptr.stderr b/tests/ui/ref_as_ptr.stderr index 16cdaec50cf..c5e9af38aea 100644 --- a/tests/ui/ref_as_ptr.stderr +++ b/tests/ui/ref_as_ptr.stderr @@ -1,266 +1,266 @@ error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:5:13 + --> tests/ui/ref_as_ptr.rs:7:7 | -LL | let _ = &1u8 as *const _; - | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)` +LL | f(&1u8 as *const _); + | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)` | = note: `-D clippy::ref-as-ptr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ref_as_ptr)]` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:6:13 + --> tests/ui/ref_as_ptr.rs:8:7 | -LL | let _ = &2u32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` +LL | f(&2u32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:7:13 + --> tests/ui/ref_as_ptr.rs:9:7 | -LL | let _ = &3.0f64 as *const f64; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` +LL | f(&3.0f64 as *const f64); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:9:13 + --> tests/ui/ref_as_ptr.rs:11:7 | -LL | let _ = &4 as *const _ as *const f32; - | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` +LL | f(&4 as *const _ as *const f32); + | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:10:13 + --> tests/ui/ref_as_ptr.rs:12:7 | -LL | let _ = &5.0f32 as *const f32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` +LL | f(&5.0f32 as *const f32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:12:13 + --> tests/ui/ref_as_ptr.rs:14:7 | -LL | let _ = &mut 6u8 as *const _; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 6u8)` +LL | f(&mut 6u8 as *const _); + | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 6u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:13:13 + --> tests/ui/ref_as_ptr.rs:15:7 | -LL | let _ = &mut 7u32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 7u32)` +LL | f(&mut 7u32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 7u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:14:13 + --> tests/ui/ref_as_ptr.rs:16:7 | -LL | let _ = &mut 8.0f64 as *const f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 8.0f64)` +LL | f(&mut 8.0f64 as *const f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 8.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:16:13 + --> tests/ui/ref_as_ptr.rs:18:7 | -LL | let _ = &mut 9 as *const _ as *const f32; - | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 9)` +LL | f(&mut 9 as *const _ as *const f32); + | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 9)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:17:13 + --> tests/ui/ref_as_ptr.rs:19:7 | -LL | let _ = &mut 10.0f32 as *const f32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 10.0f32)` +LL | f(&mut 10.0f32 as *const f32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut 10.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:19:13 + --> tests/ui/ref_as_ptr.rs:21:7 | -LL | let _ = &mut 11u8 as *mut _; - | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 11u8)` +LL | f(&mut 11u8 as *mut _); + | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 11u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:20:13 + --> tests/ui/ref_as_ptr.rs:22:7 | -LL | let _ = &mut 12u32 as *mut u32; - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 12u32)` +LL | f(&mut 12u32 as *mut u32); + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 12u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:21:13 + --> tests/ui/ref_as_ptr.rs:23:7 | -LL | let _ = &mut 13.0f64 as *mut f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 13.0f64)` +LL | f(&mut 13.0f64 as *mut f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 13.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:23:13 + --> tests/ui/ref_as_ptr.rs:25:7 | -LL | let _ = &mut 14 as *mut _ as *const f32; - | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 14)` +LL | f(&mut 14 as *mut _ as *const f32); + | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 14)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:24:13 + --> tests/ui/ref_as_ptr.rs:26:7 | -LL | let _ = &mut 15.0f32 as *mut f32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 15.0f32)` +LL | f(&mut 15.0f32 as *mut f32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut 15.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:26:13 + --> tests/ui/ref_as_ptr.rs:28:7 | -LL | let _ = &1u8 as *const _; - | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)` +LL | f(&1u8 as *const _); + | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:27:13 + --> tests/ui/ref_as_ptr.rs:29:7 | -LL | let _ = &2u32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` +LL | f(&2u32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&2u32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:28:13 + --> tests/ui/ref_as_ptr.rs:30:7 | -LL | let _ = &3.0f64 as *const f64; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` +LL | f(&3.0f64 as *const f64); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&3.0f64)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:30:13 + --> tests/ui/ref_as_ptr.rs:32:7 | -LL | let _ = &4 as *const _ as *const f32; - | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` +LL | f(&4 as *const _ as *const f32); + | ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:31:13 + --> tests/ui/ref_as_ptr.rs:33:7 | -LL | let _ = &5.0f32 as *const f32 as *const u32; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` +LL | f(&5.0f32 as *const f32 as *const u32); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&5.0f32)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:34:13 + --> tests/ui/ref_as_ptr.rs:36:7 | -LL | let _ = &val as *const _; - | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` +LL | f(&val as *const _); + | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:35:13 + --> tests/ui/ref_as_ptr.rs:37:7 | -LL | let _ = &val as *const i32; - | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` +LL | f(&val as *const i32); + | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:37:13 + --> tests/ui/ref_as_ptr.rs:39:7 | -LL | let _ = &val as *const _ as *const f32; - | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` +LL | f(&val as *const _ as *const f32); + | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:38:13 + --> tests/ui/ref_as_ptr.rs:40:7 | -LL | let _ = &val as *const i32 as *const f64; - | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` +LL | f(&val as *const i32 as *const f64); + | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:41:13 + --> tests/ui/ref_as_ptr.rs:43:7 | -LL | let _ = &mut val as *mut u8; - | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut val)` +LL | f(&mut val as *mut u8); + | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:42:13 + --> tests/ui/ref_as_ptr.rs:44:7 | -LL | let _ = &mut val as *mut _; - | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut val)` +LL | f(&mut val as *mut _); + | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:44:13 + --> tests/ui/ref_as_ptr.rs:46:7 | -LL | let _ = &mut val as *const u8; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` +LL | f(&mut val as *const u8); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:45:13 + --> tests/ui/ref_as_ptr.rs:47:7 | -LL | let _ = &mut val as *const _; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` +LL | f(&mut val as *const _); + | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:47:13 + --> tests/ui/ref_as_ptr.rs:49:7 | -LL | let _ = &mut val as *const u8 as *const f64; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` +LL | f(&mut val as *const u8 as *const f64); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:48:32 + --> tests/ui/ref_as_ptr.rs:50:28 | -LL | let _: *const Option = &mut val as *const _ as *const _; - | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` +LL | f::<*const Option>(&mut val as *const _ as *const _); + | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:50:13 + --> tests/ui/ref_as_ptr.rs:52:7 | -LL | let _ = &std::array::from_fn(|i| i * i) as *const [usize; 7]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))` +LL | f(&std::array::from_fn(|i| i * i) as *const [usize; 7]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:51:13 + --> tests/ui/ref_as_ptr.rs:53:7 | -LL | let _ = &mut std::array::from_fn(|i| i * i) as *const [usize; 8]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))` +LL | f(&mut std::array::from_fn(|i| i * i) as *const [usize; 8]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:52:13 + --> tests/ui/ref_as_ptr.rs:54:7 | -LL | let _ = &mut std::array::from_fn(|i| i * i) as *mut [usize; 9]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))` +LL | f(&mut std::array::from_fn(|i| i * i) as *mut [usize; 9]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:70:13 + --> tests/ui/ref_as_ptr.rs:76:7 | -LL | let _ = val as *const i32; - | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(val)` +LL | f(val as *const i32); + | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:71:13 + --> tests/ui/ref_as_ptr.rs:77:7 | -LL | let _ = mut_val as *mut i32; - | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(mut_val)` +LL | f(mut_val as *mut i32); + | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(mut_val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:75:13 + --> tests/ui/ref_as_ptr.rs:81:7 | -LL | let _ = val as *const _; - | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)` +LL | f(val as *const _); + | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:76:13 + --> tests/ui/ref_as_ptr.rs:82:7 | -LL | let _ = val as *const [u8]; - | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)` +LL | f(val as *const [u8]); + | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:80:13 + --> tests/ui/ref_as_ptr.rs:86:7 | -LL | let _ = val as *mut _; - | ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)` +LL | f(val as *mut _); + | ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:81:13 + --> tests/ui/ref_as_ptr.rs:87:7 | -LL | let _ = val as *mut str; - | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(val)` +LL | f(val as *mut str); + | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:88:9 + --> tests/ui/ref_as_ptr.rs:94:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:92:9 + --> tests/ui/ref_as_ptr.rs:98:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:100:9 + --> tests/ui/ref_as_ptr.rs:106:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:104:9 + --> tests/ui/ref_as_ptr.rs:110:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:108:9 + --> tests/ui/ref_as_ptr.rs:114:9 | LL | self.0 as *mut _ as *mut _ | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)`