blob: 3ba2eea59f0b00c91ab826580514bfd0cd72b702 [file] [log] [blame]
#![warn(clippy::borrow_as_ptr)]
#![allow(clippy::useless_vec)]
fn a() -> i32 {
0
}
#[clippy::msrv = "1.75"]
fn main() {
let val = 1;
let _p = std::ptr::addr_of!(val);
//~^ borrow_as_ptr
let _p = &0 as *const i32;
let _p = &a() as *const i32;
let vec = vec![1];
let _p = &vec.len() as *const usize;
let mut val_mut = 1;
let _p_mut = std::ptr::addr_of_mut!(val_mut);
//~^ borrow_as_ptr
let mut x: [i32; 2] = [42, 43];
let _raw = std::ptr::addr_of_mut!(x[1]).wrapping_offset(-1);
//~^ borrow_as_ptr
}
fn issue_13882() {
let mut x: [i32; 2] = [42, 43];
let _raw = (&raw mut x[1]).wrapping_offset(-1);
//~^ borrow_as_ptr
}
fn implicit_cast() {
let val = 1;
let p: *const i32 = &raw const val;
//~^ borrow_as_ptr
let mut val = 1;
let p: *mut i32 = &raw mut val;
//~^ borrow_as_ptr
let mut val = 1;
// Only lint the leftmost argument, the rightmost is ref to a temporary
core::ptr::eq(&raw const val, &1);
//~^ borrow_as_ptr
// Do not lint references to temporaries
core::ptr::eq(&0i32, &1i32);
}