Take lifetime extension into account in ref_as_ptr
This commit is contained in:
parent
5a52c8aee9
commit
5ab42d8e6a
@ -1,7 +1,7 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
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::source::snippet_with_applicability;
|
||||||
use clippy_utils::sugg::Sugg;
|
use clippy_utils::sugg::Sugg;
|
||||||
|
use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, Mutability, Ty, TyKind};
|
use rustc_hir::{Expr, Mutability, Ty, TyKind};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
@ -9,7 +9,12 @@
|
|||||||
|
|
||||||
use super::REF_AS_PTR;
|
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) = (
|
let (cast_from, cast_to) = (
|
||||||
cx.typeck_results().expr_ty(cast_expr),
|
cx.typeck_results().expr_ty(cast_expr),
|
||||||
cx.typeck_results().expr_ty(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(..))
|
if matches!(cast_from.kind(), ty::Ref(..))
|
||||||
&& let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind()
|
&& 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 core_or_std = if is_no_std_crate(cx) { "core" } else { "std" };
|
||||||
let fn_name = match to_mutbl {
|
let fn_name = match to_mutbl {
|
||||||
|
@ -1,55 +1,61 @@
|
|||||||
#![warn(clippy::ref_as_ptr)]
|
#![warn(clippy::ref_as_ptr)]
|
||||||
#![allow(clippy::unnecessary_mut_passed)]
|
#![allow(clippy::unnecessary_mut_passed)]
|
||||||
|
|
||||||
|
fn f<T>(_: T) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = std::ptr::from_ref(&1u8);
|
f(std::ptr::from_ref(&1u8));
|
||||||
let _ = std::ptr::from_ref::<u32>(&2u32);
|
f(std::ptr::from_ref::<u32>(&2u32));
|
||||||
let _ = std::ptr::from_ref::<f64>(&3.0f64);
|
f(std::ptr::from_ref::<f64>(&3.0f64));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&4) as *const f32;
|
f(std::ptr::from_ref(&4) as *const f32);
|
||||||
let _ = std::ptr::from_ref::<f32>(&5.0f32) as *const u32;
|
f(std::ptr::from_ref::<f32>(&5.0f32) as *const u32);
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&mut 6u8);
|
f(std::ptr::from_ref(&mut 6u8));
|
||||||
let _ = std::ptr::from_ref::<u32>(&mut 7u32);
|
f(std::ptr::from_ref::<u32>(&mut 7u32));
|
||||||
let _ = std::ptr::from_ref::<f64>(&mut 8.0f64);
|
f(std::ptr::from_ref::<f64>(&mut 8.0f64));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&mut 9) as *const f32;
|
f(std::ptr::from_ref(&mut 9) as *const f32);
|
||||||
let _ = std::ptr::from_ref::<f32>(&mut 10.0f32) as *const u32;
|
f(std::ptr::from_ref::<f32>(&mut 10.0f32) as *const u32);
|
||||||
|
|
||||||
let _ = std::ptr::from_mut(&mut 11u8);
|
f(std::ptr::from_mut(&mut 11u8));
|
||||||
let _ = std::ptr::from_mut::<u32>(&mut 12u32);
|
f(std::ptr::from_mut::<u32>(&mut 12u32));
|
||||||
let _ = std::ptr::from_mut::<f64>(&mut 13.0f64);
|
f(std::ptr::from_mut::<f64>(&mut 13.0f64));
|
||||||
|
|
||||||
let _ = std::ptr::from_mut(&mut 14) as *const f32;
|
f(std::ptr::from_mut(&mut 14) as *const f32);
|
||||||
let _ = std::ptr::from_mut::<f32>(&mut 15.0f32) as *const u32;
|
f(std::ptr::from_mut::<f32>(&mut 15.0f32) as *const u32);
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&1u8);
|
f(std::ptr::from_ref(&1u8));
|
||||||
let _ = std::ptr::from_ref::<u32>(&2u32);
|
f(std::ptr::from_ref::<u32>(&2u32));
|
||||||
let _ = std::ptr::from_ref::<f64>(&3.0f64);
|
f(std::ptr::from_ref::<f64>(&3.0f64));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&4) as *const f32;
|
f(std::ptr::from_ref(&4) as *const f32);
|
||||||
let _ = std::ptr::from_ref::<f32>(&5.0f32) as *const u32;
|
f(std::ptr::from_ref::<f32>(&5.0f32) as *const u32);
|
||||||
|
|
||||||
let val = 1;
|
let val = 1;
|
||||||
let _ = std::ptr::from_ref(&val);
|
f(std::ptr::from_ref(&val));
|
||||||
let _ = std::ptr::from_ref::<i32>(&val);
|
f(std::ptr::from_ref::<i32>(&val));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref(&val) as *const f32;
|
f(std::ptr::from_ref(&val) as *const f32);
|
||||||
let _ = std::ptr::from_ref::<i32>(&val) as *const f64;
|
f(std::ptr::from_ref::<i32>(&val) as *const f64);
|
||||||
|
|
||||||
let mut val: u8 = 2;
|
let mut val: u8 = 2;
|
||||||
let _ = std::ptr::from_mut::<u8>(&mut val);
|
f(std::ptr::from_mut::<u8>(&mut val));
|
||||||
let _ = std::ptr::from_mut(&mut val);
|
f(std::ptr::from_mut(&mut val));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref::<u8>(&mut val);
|
f(std::ptr::from_ref::<u8>(&mut val));
|
||||||
let _ = std::ptr::from_ref(&mut val);
|
f(std::ptr::from_ref(&mut val));
|
||||||
|
|
||||||
let _ = std::ptr::from_ref::<u8>(&mut val) as *const f64;
|
f(std::ptr::from_ref::<u8>(&mut val) as *const f64);
|
||||||
let _: *const Option<u8> = std::ptr::from_ref(&mut val) as *const _;
|
f::<*const Option<u8>>(std::ptr::from_ref(&mut val) as *const _);
|
||||||
|
|
||||||
let _ = std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i));
|
f(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));
|
f(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_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"]
|
#[clippy::msrv = "1.75"]
|
||||||
@ -58,8 +64,8 @@ fn _msrv_1_75() {
|
|||||||
let mut_val = &mut 42_i32;
|
let mut_val = &mut 42_i32;
|
||||||
|
|
||||||
// `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this
|
// `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this
|
||||||
let _ = val as *const i32;
|
f(val as *const i32);
|
||||||
let _ = mut_val as *mut i32;
|
f(mut_val as *mut i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[clippy::msrv = "1.76"]
|
#[clippy::msrv = "1.76"]
|
||||||
@ -67,18 +73,18 @@ fn _msrv_1_76() {
|
|||||||
let val = &42_i32;
|
let val = &42_i32;
|
||||||
let mut_val = &mut 42_i32;
|
let mut_val = &mut 42_i32;
|
||||||
|
|
||||||
let _ = std::ptr::from_ref::<i32>(val);
|
f(std::ptr::from_ref::<i32>(val));
|
||||||
let _ = std::ptr::from_mut::<i32>(mut_val);
|
f(std::ptr::from_mut::<i32>(mut_val));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(val: &[u8]) {
|
fn foo(val: &[u8]) {
|
||||||
let _ = std::ptr::from_ref(val);
|
f(std::ptr::from_ref(val));
|
||||||
let _ = std::ptr::from_ref::<[u8]>(val);
|
f(std::ptr::from_ref::<[u8]>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar(val: &mut str) {
|
fn bar(val: &mut str) {
|
||||||
let _ = std::ptr::from_mut(val);
|
f(std::ptr::from_mut(val));
|
||||||
let _ = std::ptr::from_mut::<str>(val);
|
f(std::ptr::from_mut::<str>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct X<'a>(&'a i32);
|
struct X<'a>(&'a i32);
|
||||||
|
@ -1,55 +1,61 @@
|
|||||||
#![warn(clippy::ref_as_ptr)]
|
#![warn(clippy::ref_as_ptr)]
|
||||||
#![allow(clippy::unnecessary_mut_passed)]
|
#![allow(clippy::unnecessary_mut_passed)]
|
||||||
|
|
||||||
|
fn f<T>(_: T) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = &1u8 as *const _;
|
f(&1u8 as *const _);
|
||||||
let _ = &2u32 as *const u32;
|
f(&2u32 as *const u32);
|
||||||
let _ = &3.0f64 as *const f64;
|
f(&3.0f64 as *const f64);
|
||||||
|
|
||||||
let _ = &4 as *const _ as *const f32;
|
f(&4 as *const _ as *const f32);
|
||||||
let _ = &5.0f32 as *const f32 as *const u32;
|
f(&5.0f32 as *const f32 as *const u32);
|
||||||
|
|
||||||
let _ = &mut 6u8 as *const _;
|
f(&mut 6u8 as *const _);
|
||||||
let _ = &mut 7u32 as *const u32;
|
f(&mut 7u32 as *const u32);
|
||||||
let _ = &mut 8.0f64 as *const f64;
|
f(&mut 8.0f64 as *const f64);
|
||||||
|
|
||||||
let _ = &mut 9 as *const _ as *const f32;
|
f(&mut 9 as *const _ as *const f32);
|
||||||
let _ = &mut 10.0f32 as *const f32 as *const u32;
|
f(&mut 10.0f32 as *const f32 as *const u32);
|
||||||
|
|
||||||
let _ = &mut 11u8 as *mut _;
|
f(&mut 11u8 as *mut _);
|
||||||
let _ = &mut 12u32 as *mut u32;
|
f(&mut 12u32 as *mut u32);
|
||||||
let _ = &mut 13.0f64 as *mut f64;
|
f(&mut 13.0f64 as *mut f64);
|
||||||
|
|
||||||
let _ = &mut 14 as *mut _ as *const f32;
|
f(&mut 14 as *mut _ as *const f32);
|
||||||
let _ = &mut 15.0f32 as *mut f32 as *const u32;
|
f(&mut 15.0f32 as *mut f32 as *const u32);
|
||||||
|
|
||||||
let _ = &1u8 as *const _;
|
f(&1u8 as *const _);
|
||||||
let _ = &2u32 as *const u32;
|
f(&2u32 as *const u32);
|
||||||
let _ = &3.0f64 as *const f64;
|
f(&3.0f64 as *const f64);
|
||||||
|
|
||||||
let _ = &4 as *const _ as *const f32;
|
f(&4 as *const _ as *const f32);
|
||||||
let _ = &5.0f32 as *const f32 as *const u32;
|
f(&5.0f32 as *const f32 as *const u32);
|
||||||
|
|
||||||
let val = 1;
|
let val = 1;
|
||||||
let _ = &val as *const _;
|
f(&val as *const _);
|
||||||
let _ = &val as *const i32;
|
f(&val as *const i32);
|
||||||
|
|
||||||
let _ = &val as *const _ as *const f32;
|
f(&val as *const _ as *const f32);
|
||||||
let _ = &val as *const i32 as *const f64;
|
f(&val as *const i32 as *const f64);
|
||||||
|
|
||||||
let mut val: u8 = 2;
|
let mut val: u8 = 2;
|
||||||
let _ = &mut val as *mut u8;
|
f(&mut val as *mut u8);
|
||||||
let _ = &mut val as *mut _;
|
f(&mut val as *mut _);
|
||||||
|
|
||||||
let _ = &mut val as *const u8;
|
f(&mut val as *const u8);
|
||||||
let _ = &mut val as *const _;
|
f(&mut val as *const _);
|
||||||
|
|
||||||
let _ = &mut val as *const u8 as *const f64;
|
f(&mut val as *const u8 as *const f64);
|
||||||
let _: *const Option<u8> = &mut val as *const _ as *const _;
|
f::<*const Option<u8>>(&mut val as *const _ as *const _);
|
||||||
|
|
||||||
let _ = &std::array::from_fn(|i| i * i) as *const [usize; 7];
|
f(&std::array::from_fn(|i| i * i) as *const [usize; 7]);
|
||||||
let _ = &mut std::array::from_fn(|i| i * i) as *const [usize; 8];
|
f(&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(&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"]
|
#[clippy::msrv = "1.75"]
|
||||||
@ -58,8 +64,8 @@ fn _msrv_1_75() {
|
|||||||
let mut_val = &mut 42_i32;
|
let mut_val = &mut 42_i32;
|
||||||
|
|
||||||
// `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this
|
// `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this
|
||||||
let _ = val as *const i32;
|
f(val as *const i32);
|
||||||
let _ = mut_val as *mut i32;
|
f(mut_val as *mut i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[clippy::msrv = "1.76"]
|
#[clippy::msrv = "1.76"]
|
||||||
@ -67,18 +73,18 @@ fn _msrv_1_76() {
|
|||||||
let val = &42_i32;
|
let val = &42_i32;
|
||||||
let mut_val = &mut 42_i32;
|
let mut_val = &mut 42_i32;
|
||||||
|
|
||||||
let _ = val as *const i32;
|
f(val as *const i32);
|
||||||
let _ = mut_val as *mut i32;
|
f(mut_val as *mut i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(val: &[u8]) {
|
fn foo(val: &[u8]) {
|
||||||
let _ = val as *const _;
|
f(val as *const _);
|
||||||
let _ = val as *const [u8];
|
f(val as *const [u8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar(val: &mut str) {
|
fn bar(val: &mut str) {
|
||||||
let _ = val as *mut _;
|
f(val as *mut _);
|
||||||
let _ = val as *mut str;
|
f(val as *mut str);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct X<'a>(&'a i32);
|
struct X<'a>(&'a i32);
|
||||||
|
@ -1,266 +1,266 @@
|
|||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&1u8 as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)`
|
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::ref-as-ptr` implied by `-D warnings`
|
= note: `-D clippy::ref-as-ptr` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::ref_as_ptr)]`
|
= help: to override `-D warnings` add `#[allow(clippy::ref_as_ptr)]`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&2u32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&2u32)`
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&2u32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&3.0f64 as *const f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&3.0f64)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&3.0f64)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&4 as *const _ as *const f32);
|
||||||
| ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)`
|
| ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&5.0f32 as *const f32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&5.0f32)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&5.0f32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&mut 6u8 as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 6u8)`
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 6u8)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 7u32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&mut 7u32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&mut 7u32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 8.0f64 as *const f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&mut 8.0f64)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&mut 8.0f64)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 9 as *const _ as *const f32);
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 9)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut 9)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 10.0f32 as *const f32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&mut 10.0f32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&mut 10.0f32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&mut 11u8 as *mut _);
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 11u8)`
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 11u8)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 12u32 as *mut u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<u32>(&mut 12u32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<u32>(&mut 12u32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 13.0f64 as *mut f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<f64>(&mut 13.0f64)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<f64>(&mut 13.0f64)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 14 as *mut _ as *const f32);
|
||||||
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 14)`
|
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut 14)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut 15.0f32 as *mut f32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<f32>(&mut 15.0f32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<f32>(&mut 15.0f32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&1u8 as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)`
|
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&1u8)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&2u32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&2u32)`
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u32>(&2u32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&3.0f64 as *const f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&3.0f64)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f64>(&3.0f64)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&4 as *const _ as *const f32);
|
||||||
| ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)`
|
| ^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&4)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&5.0f32 as *const f32 as *const u32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&5.0f32)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<f32>(&5.0f32)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&val as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)`
|
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&val as *const i32);
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(&val)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(&val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&val as *const _ as *const f32);
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)`
|
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&val as *const i32 as *const f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(&val)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(&val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut val as *mut u8);
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<u8>(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<u8>(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&mut val as *mut _);
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut val as *const u8);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u8>(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u8>(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(&mut val as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(&mut val as *const u8 as *const f64);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u8>(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<u8>(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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<u8> = &mut val as *const _ as *const _;
|
LL | f::<*const Option<u8>>(&mut val as *const _ as *const _);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)`
|
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&mut val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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];
|
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))`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 7]>(&std::array::from_fn(|i| i * i))`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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];
|
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))`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[usize; 8]>(&mut std::array::from_fn(|i| i * i))`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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];
|
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))`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<[usize; 9]>(&mut std::array::from_fn(|i| i * i))`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(val as *const i32);
|
||||||
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(val)`
|
| ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<i32>(val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(mut_val as *mut i32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<i32>(mut_val)`
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<i32>(mut_val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(val as *const _);
|
||||||
| ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)`
|
| ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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];
|
LL | f(val as *const [u8]);
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _;
|
LL | f(val as *mut _);
|
||||||
| ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)`
|
| ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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;
|
LL | f(val as *mut str);
|
||||||
| ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<str>(val)`
|
| ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::<str>(val)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _
|
LL | self.0 as *const _ as *const _
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _
|
LL | self.0 as *const _ as *const _
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _
|
LL | self.0 as *const _ as *const _
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _
|
LL | self.0 as *const _ as *const _
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)`
|
||||||
|
|
||||||
error: reference as raw pointer
|
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 _
|
LL | self.0 as *mut _ as *mut _
|
||||||
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)`
|
| ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)`
|
||||||
|
Loading…
Reference in New Issue
Block a user