Skip to content

Commit c5a914b

Browse files
committed
check msrv
1 parent 8c191ad commit c5a914b

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

clippy_lints/src/casts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
752752
return;
753753
}
754754
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, &self.msrv);
755-
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to);
755+
ptr_cast_constness::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv);
756756
as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
757757
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
758758
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);

clippy_lints/src/casts/ptr_cast_constness.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg;
21
use clippy_utils::sugg::Sugg;
2+
use clippy_utils::{diagnostics::span_lint_and_sugg, msrvs::Msrv};
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, Mutability};
66
use rustc_lint::LateContext;
77
use rustc_middle::ty::{self, Ty, TypeAndMut};
8+
use rustc_semver::RustcVersion;
89

910
use super::PTR_CAST_CONSTNESS;
1011

11-
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
12+
pub(super) fn check(
13+
cx: &LateContext<'_>,
14+
expr: &Expr<'_>,
15+
cast_expr: &Expr<'_>,
16+
cast_from: Ty<'_>,
17+
cast_to: Ty<'_>,
18+
msrv: &Msrv,
19+
) {
1220
if_chain! {
21+
if msrv.meets(RustcVersion::new(1,65,0));
1322
if let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind();
1423
if let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind();
1524
if !matches!((from_mutbl, to_mutbl),

tests/ui/ptr_cast_constness.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ fn _msrv_1_37() {
4141
let mut_ptr: *mut u32 = &mut 42_u32;
4242

4343
// `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
44-
let _ = ptr.cast_mut();
45-
let _ = mut_ptr.cast_const();
44+
let _ = ptr as *mut i32;
45+
let _ = mut_ptr as *const i32;
4646
}
4747

4848
#[clippy::msrv = "1.65"]

tests/ui/ptr_cast_constness.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ error: `as` casting between raw pointers while changing its constness
1818
LL | let _ = mut_ptr as *const i32;
1919
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
2020

21-
error: `as` casting between raw pointers while changing its constness
22-
--> $DIR/ptr_cast_constness.rs:44:13
23-
|
24-
LL | let _ = ptr as *mut i32;
25-
| ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()`
26-
27-
error: `as` casting between raw pointers while changing its constness
28-
--> $DIR/ptr_cast_constness.rs:45:13
29-
|
30-
LL | let _ = mut_ptr as *const i32;
31-
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
32-
3321
error: `as` casting between raw pointers while changing its constness
3422
--> $DIR/ptr_cast_constness.rs:53:13
3523
|
@@ -42,5 +30,5 @@ error: `as` casting between raw pointers while changing its constness
4230
LL | let _ = mut_ptr as *const i32;
4331
| ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
4432

45-
error: aborting due to 7 previous errors
33+
error: aborting due to 5 previous errors
4634

0 commit comments

Comments
 (0)