Fix the MSRV and add the tests for MSRV

This commit is contained in:
rail 2021-01-05 10:17:31 +13:00
parent 4b478a5731
commit dfa5d7e818
4 changed files with 60 additions and 6 deletions

View file

@ -2968,4 +2968,6 @@ impl<'tcx> LateLintPass<'tcx> for PtrAsPtr {
}
}
}
extract_msrv_attr!(LateContext);
}

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::ptr_as_ptr)]
#![feature(custom_inner_attributes)]
fn main() {
let ptr: *const u32 = &42_u32;
@ -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>();
}

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::ptr_as_ptr)]
#![feature(custom_inner_attributes)]
fn main() {
let ptr: *const u32 = &42_u32;
@ -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;
}

View file

@ -1,5 +1,5 @@
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>()`
@ -7,28 +7,40 @@ LL | let _ = ptr as *const 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