Skip to content

Commit 9d6186f

Browse files
committed
handle transmutes in const context if msrvs::CONST_FLOAT_BITS_CONV
1 parent 663ff7a commit 9d6186f

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
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, const_context)
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, const_context)
625-
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context)
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

+5-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;
@@ -16,9 +17,12 @@ pub(super) fn check<'tcx>(
1617
to_ty: Ty<'tcx>,
1718
mut arg: &'tcx Expr<'_>,
1819
const_context: bool,
20+
msrv: &Msrv,
1921
) -> bool {
2022
match (&from_ty.kind(), &to_ty.kind()) {
21-
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) if !const_context => {
23+
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_))
24+
if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) =>
25+
{
2226
span_lint_and_then(
2327
cx,
2428
TRANSMUTE_FLOAT_TO_INT,

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

+3-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;
@@ -15,9 +16,10 @@ pub(super) fn check<'tcx>(
1516
to_ty: Ty<'tcx>,
1617
arg: &'tcx Expr<'_>,
1718
const_context: bool,
19+
msrv: &Msrv,
1820
) -> bool {
1921
match (&from_ty.kind(), &to_ty.kind()) {
20-
(ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context => {
22+
(ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => {
2123
span_lint_and_then(
2224
cx,
2325
TRANSMUTE_INT_TO_FLOAT,

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

+3-3
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;
@@ -15,15 +16,14 @@ pub(super) fn check<'tcx>(
1516
to_ty: Ty<'tcx>,
1617
arg: &'tcx Expr<'_>,
1718
const_context: bool,
19+
msrv: &Msrv,
1820
) -> bool {
1921
match (&from_ty.kind(), &to_ty.kind()) {
2022
(ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => {
2123
if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) {
2224
return false;
2325
}
24-
if matches!(from_ty.kind(), ty::Float(_)) && const_context {
25-
// TODO: Remove when const_float_bits_conv is stabilized
26-
// rust#72447
26+
if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) {
2727
return false;
2828
}
2929

0 commit comments

Comments
 (0)