Skip to content

Commit

Permalink
Fix the MSRV and add the tests for MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
rail-rain committed Jan 4, 2021
1 parent 4b478a5 commit dfa5d7e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2968,4 +2968,6 @@ impl<'tcx> LateLintPass<'tcx> for PtrAsPtr {
}
}
}

extract_msrv_attr!(LateContext);
}
20 changes: 20 additions & 0 deletions tests/ui/ptr_as_ptr.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-rustfix

#![warn(clippy::ptr_as_ptr)]
#![feature(custom_inner_attributes)]

fn main() {
let ptr: *const u32 = &42_u32;
Expand Down Expand Up @@ -28,3 +29,22 @@ fn main() {
let _: *const i32 = ptr.cast();
let _: *mut i32 = mut_ptr.cast();
}

fn _msrv_1_37() {
#![clippy::msrv = "1.37"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;

// `pointer::cast` was stabilized in 1.38. Do not lint this
let _ = ptr as *const i32;
let _ = mut_ptr as *mut i32;
}

fn _msrv_1_38() {
#![clippy::msrv = "1.38"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;

let _ = ptr.cast::<i32>();
let _ = mut_ptr.cast::<i32>();
}
20 changes: 20 additions & 0 deletions tests/ui/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-rustfix

#![warn(clippy::ptr_as_ptr)]
#![feature(custom_inner_attributes)]

fn main() {
let ptr: *const u32 = &42_u32;
Expand Down Expand Up @@ -28,3 +29,22 @@ fn main() {
let _: *const i32 = ptr as *const _;
let _: *mut i32 = mut_ptr as _;
}

fn _msrv_1_37() {
#![clippy::msrv = "1.37"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;

// `pointer::cast` was stabilized in 1.38. Do not lint this
let _ = ptr as *const i32;
let _ = mut_ptr as *mut i32;
}

fn _msrv_1_38() {
#![clippy::msrv = "1.38"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;

let _ = ptr as *const i32;
let _ = mut_ptr as *mut i32;
}
24 changes: 18 additions & 6 deletions tests/ui/ptr_as_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:9:13
--> $DIR/ptr_as_ptr.rs:10:13
|
LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
|
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings`

error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:10:13
--> $DIR/ptr_as_ptr.rs:11:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`

error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:15:17
--> $DIR/ptr_as_ptr.rs:16:17
|
LL | let _ = *ptr_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()`

error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:28:25
--> $DIR/ptr_as_ptr.rs:29:25
|
LL | let _: *const i32 = ptr as *const _;
| ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()`

error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:29:23
--> $DIR/ptr_as_ptr.rs:30:23
|
LL | let _: *mut i32 = mut_ptr as _;
| ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()`

error: aborting due to 5 previous errors
error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:48:13
|
LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`

error: `as` casting between raw pointers without changing its mutability
--> $DIR/ptr_as_ptr.rs:49:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`

error: aborting due to 7 previous errors

0 comments on commit dfa5d7e

Please sign in to comment.