about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/manual_dangling_ptr.rs
blob: 581ad50113e28eb2b59638bb4d0dfada6850a78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![warn(clippy::manual_dangling_ptr)]
use std::mem;

pub fn foo(_const: *const f32, _mut: *mut i32) {}

fn main() {
    let _: *const u8 = 1 as *const _;
    //~^ manual_dangling_ptr
    let _ = 2 as *const u32;
    //~^ manual_dangling_ptr
    let _ = 4 as *mut f32;
    //~^ manual_dangling_ptr

    let _ = mem::align_of::<u8>() as *const u8;
    //~^ manual_dangling_ptr
    let _ = mem::align_of::<u32>() as *const u32;
    //~^ manual_dangling_ptr
    let _ = mem::align_of::<usize>() as *const usize;
    //~^ manual_dangling_ptr

    foo(4 as *const _, 4 as *mut _);
    //~^ manual_dangling_ptr
    //~| manual_dangling_ptr
}

fn should_not_lint() {
    let _ = 0x10 as *mut i32;
    let _ = mem::align_of::<u32>() as *const u8;

    foo(0 as _, 0 as _);
}

#[clippy::msrv = "1.83"]
fn _msrv_1_83() {
    // `{core, std}::ptr::dangling` was stabilized in 1.84. Do not lint this
    foo(4 as *const _, 4 as *mut _);
}

#[clippy::msrv = "1.84"]
fn _msrv_1_84() {
    foo(4 as *const _, 4 as *mut _);
    //~^ manual_dangling_ptr
    //~| manual_dangling_ptr
}