Skip to content

Commit 54895b6

Browse files
committed
Fix zero_ptr suggestion for no_std crates
1 parent d822110 commit 54895b6

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

tests/ui/zero_ptr_no_std.fixed

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
3+
#![feature(lang_items, start, libc)]
4+
#![no_std]
5+
#![deny(clippy::zero_ptr)]
6+
7+
#[start]
8+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
9+
let _ = core::ptr::null::<usize>();
10+
let _ = core::ptr::null_mut::<f64>();
11+
let _: *const u8 = core::ptr::null();
12+
0
13+
}
14+
15+
#[panic_handler]
16+
fn panic(_info: &core::panic::PanicInfo) -> ! {
17+
loop {}
18+
}
19+
20+
#[lang = "eh_personality"]
21+
extern "C" fn eh_personality() {}

tests/ui/zero_ptr_no_std.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
3+
#![feature(lang_items, start, libc)]
4+
#![no_std]
5+
#![deny(clippy::zero_ptr)]
6+
7+
#[start]
8+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
9+
let _ = 0 as *const usize;
10+
let _ = 0 as *mut f64;
11+
let _: *const u8 = 0 as *const _;
12+
0
13+
}
14+
15+
#[panic_handler]
16+
fn panic(_info: &core::panic::PanicInfo) -> ! {
17+
loop {}
18+
}
19+
20+
#[lang = "eh_personality"]
21+
extern "C" fn eh_personality() {}

tests/ui/zero_ptr_no_std.stderr

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `0 as *const _` detected
2+
--> $DIR/zero_ptr_no_std.rs:9:13
3+
|
4+
LL | let _ = 0 as *const usize;
5+
| ^^^^^^^^^^^^^^^^^ help: try: `core::ptr::null::<usize>()`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/zero_ptr_no_std.rs:5:9
9+
|
10+
LL | #![deny(clippy::zero_ptr)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: `0 as *mut _` detected
14+
--> $DIR/zero_ptr_no_std.rs:10:13
15+
|
16+
LL | let _ = 0 as *mut f64;
17+
| ^^^^^^^^^^^^^ help: try: `core::ptr::null_mut::<f64>()`
18+
19+
error: `0 as *const _` detected
20+
--> $DIR/zero_ptr_no_std.rs:11:24
21+
|
22+
LL | let _: *const u8 = 0 as *const _;
23+
| ^^^^^^^^^^^^^ help: try: `core::ptr::null()`
24+
25+
error: aborting due to 3 previous errors
26+

0 commit comments

Comments
 (0)