Skip to content

Commit 5343fcd

Browse files
authored
Rollup merge of #130305 - tspiteri:clippy-msrv-for-const_float_bits_conv, r=flip1995
Clippy: consider msrv for const context for const_float_bits_conv When `const_float_bits_conv` was stabilized for 1.83.0, clippy lints started to be triggered in const context ignoring MSRV. This PR makes the lints trigger in const context only when the MSRV meets 1.83.0. Fixes rust-lang/rust-clippy#13383.
2 parents 7d36bfa + 581f192 commit 5343fcd

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

src/tools/clippy/clippy_config/src/msrvs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ macro_rules! msrv_aliases {
1717

1818
// names may refer to stabilized feature flags or library items
1919
msrv_aliases! {
20-
1,81,0 { LINT_REASONS_STABILIZATION }
20+
1,83,0 { CONST_FLOAT_BITS_CONV }
21+
1,81,0 { LINT_REASONS_STABILIZATION }
2122
1,80,0 { BOX_INTO_ITER}
2223
1,77,0 { C_STR_LITERALS }
2324
1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT }

src/tools/clippy/clippy_lints/src/transmute/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
619619
| transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context)
620620
| transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, &self.msrv)
621621
| transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg)
622-
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg)
622+
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
623623
| transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg)
624-
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg)
625-
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg)
624+
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
625+
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
626626
| (unsound_collection_transmute::check(cx, e, from_ty, to_ty)
627627
|| transmute_undefined_repr::check(cx, e, from_ty, to_ty))
628628
| (eager_transmute::check(cx, e, arg, from_ty, to_ty));

src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::TRANSMUTE_FLOAT_TO_INT;
2+
use clippy_config::msrvs::{self, Msrv};
23
use clippy_utils::diagnostics::span_lint_and_then;
34
use clippy_utils::sugg;
45
use rustc_ast as ast;
@@ -15,9 +16,13 @@ pub(super) fn check<'tcx>(
1516
from_ty: Ty<'tcx>,
1617
to_ty: Ty<'tcx>,
1718
mut arg: &'tcx Expr<'_>,
19+
const_context: bool,
20+
msrv: &Msrv,
1821
) -> bool {
1922
match (&from_ty.kind(), &to_ty.kind()) {
20-
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) => {
23+
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_))
24+
if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) =>
25+
{
2126
span_lint_and_then(
2227
cx,
2328
TRANSMUTE_FLOAT_TO_INT,

src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::TRANSMUTE_INT_TO_FLOAT;
2+
use clippy_config::msrvs::{self, Msrv};
23
use clippy_utils::diagnostics::span_lint_and_then;
34
use clippy_utils::sugg;
45
use rustc_errors::Applicability;
@@ -14,9 +15,11 @@ pub(super) fn check<'tcx>(
1415
from_ty: Ty<'tcx>,
1516
to_ty: Ty<'tcx>,
1617
arg: &'tcx Expr<'_>,
18+
const_context: bool,
19+
msrv: &Msrv,
1720
) -> bool {
1821
match (&from_ty.kind(), &to_ty.kind()) {
19-
(ty::Int(_) | ty::Uint(_), ty::Float(_)) => {
22+
(ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => {
2023
span_lint_and_then(
2124
cx,
2225
TRANSMUTE_INT_TO_FLOAT,

src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::TRANSMUTE_NUM_TO_BYTES;
2+
use clippy_config::msrvs::{self, Msrv};
23
use clippy_utils::diagnostics::span_lint_and_then;
34
use clippy_utils::sugg;
45
use rustc_errors::Applicability;
@@ -14,12 +15,17 @@ pub(super) fn check<'tcx>(
1415
from_ty: Ty<'tcx>,
1516
to_ty: Ty<'tcx>,
1617
arg: &'tcx Expr<'_>,
18+
const_context: bool,
19+
msrv: &Msrv,
1720
) -> bool {
1821
match (&from_ty.kind(), &to_ty.kind()) {
1922
(ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => {
2023
if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) {
2124
return false;
2225
}
26+
if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) {
27+
return false;
28+
}
2329

2430
span_lint_and_then(
2531
cx,

0 commit comments

Comments
 (0)