mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
check msrv
This commit is contained in:
parent
8c191add87
commit
c5a914b181
@ -752,7 +752,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
|
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);
|
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_any::check(cx, expr, cast_expr, cast_from, cast_to);
|
||||||
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
|
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
|
||||||
|
@ -1,15 +1,24 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
|
||||||
use clippy_utils::sugg::Sugg;
|
use clippy_utils::sugg::Sugg;
|
||||||
|
use clippy_utils::{diagnostics::span_lint_and_sugg, msrvs::Msrv};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, Mutability};
|
use rustc_hir::{Expr, Mutability};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||||
|
use rustc_semver::RustcVersion;
|
||||||
|
|
||||||
use super::PTR_CAST_CONSTNESS;
|
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_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: from_mutbl, .. }) = cast_from.kind();
|
||||||
if let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind();
|
if let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind();
|
||||||
if !matches!((from_mutbl, to_mutbl),
|
if !matches!((from_mutbl, to_mutbl),
|
||||||
|
@ -41,8 +41,8 @@ fn _msrv_1_37() {
|
|||||||
let mut_ptr: *mut u32 = &mut 42_u32;
|
let mut_ptr: *mut u32 = &mut 42_u32;
|
||||||
|
|
||||||
// `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
|
// `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
|
||||||
let _ = ptr.cast_mut();
|
let _ = ptr as *mut i32;
|
||||||
let _ = mut_ptr.cast_const();
|
let _ = mut_ptr as *const i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[clippy::msrv = "1.65"]
|
#[clippy::msrv = "1.65"]
|
||||||
|
@ -18,18 +18,6 @@ error: `as` casting between raw pointers while changing its constness
|
|||||||
LL | let _ = mut_ptr as *const i32;
|
LL | let _ = mut_ptr as *const i32;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
|
| ^^^^^^^^^^^^^^^^^^^^^ 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
|
error: `as` casting between raw pointers while changing its constness
|
||||||
--> $DIR/ptr_cast_constness.rs:53:13
|
--> $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;
|
LL | let _ = mut_ptr as *const i32;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
|
| ^^^^^^^^^^^^^^^^^^^^^ 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user