check msrv

This commit is contained in:
Centri3 2023-05-14 19:31:12 -05:00
parent 8c191add87
commit c5a914b181
4 changed files with 15 additions and 18 deletions

View File

@ -752,7 +752,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
return;
}
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to);
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);

View File

@ -1,15 +1,24 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::sugg::Sugg;
use clippy_utils::{diagnostics::span_lint_and_sugg, msrvs::Msrv};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Expr, Mutability};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty, TypeAndMut};
use rustc_semver::RustcVersion;
use super::PTR_CAST_CONSTNESS;
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
pub(super) fn check(
cx: &LateContext<'_>,
expr: &Expr<'_>,
cast_expr: &Expr<'_>,
cast_from: Ty<'_>,
cast_to: Ty<'_>,
msrv: &Msrv,
) {
if_chain! {
if msrv.meets(RustcVersion::new(1,65,0));
if let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind();
if let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind();
if !matches!((from_mutbl, to_mutbl),

View File

@ -41,8 +41,8 @@ fn _msrv_1_37() {
let mut_ptr: *mut u32 = &mut 42_u32;
// `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
let _ = ptr.cast_mut();
let _ = mut_ptr.cast_const();
let _ = ptr as *mut i32;
let _ = mut_ptr as *const i32;
}
#[clippy::msrv = "1.65"]

View File

@ -18,18 +18,6 @@ error: `as` casting between raw pointers while changing its constness
LL | let _ = mut_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
error: `as` casting between raw pointers while changing its constness
--> $DIR/ptr_cast_constness.rs:44:13
|
LL | let _ = ptr as *mut i32;
| ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()`
error: `as` casting between raw pointers while changing its constness
--> $DIR/ptr_cast_constness.rs:45:13
|
LL | let _ = mut_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
error: `as` casting between raw pointers while changing its constness
--> $DIR/ptr_cast_constness.rs:53:13
|
@ -42,5 +30,5 @@ error: `as` casting between raw pointers while changing its constness
LL | let _ = mut_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
error: aborting due to 7 previous errors
error: aborting due to 5 previous errors