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 https://github.com/rust-lang/rust-clippy/issues/13383.
This commit is contained in:
Matthias Krüger 2024-09-13 18:25:47 +02:00 committed by GitHub
commit 5343fcdf17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 6 deletions

View File

@ -17,6 +17,7 @@ macro_rules! msrv_aliases {
// names may refer to stabilized feature flags or library items
msrv_aliases! {
1,83,0 { CONST_FLOAT_BITS_CONV }
1,81,0 { LINT_REASONS_STABILIZATION }
1,80,0 { BOX_INTO_ITER}
1,77,0 { C_STR_LITERALS }

View File

@ -619,10 +619,10 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
| transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context)
| transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, &self.msrv)
| transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg)
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg)
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
| transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg)
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg)
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg)
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, &self.msrv)
| (unsound_collection_transmute::check(cx, e, from_ty, to_ty)
|| transmute_undefined_repr::check(cx, e, from_ty, to_ty))
| (eager_transmute::check(cx, e, arg, from_ty, to_ty));

View File

@ -1,4 +1,5 @@
use super::TRANSMUTE_FLOAT_TO_INT;
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::sugg;
use rustc_ast as ast;
@ -15,9 +16,13 @@ pub(super) fn check<'tcx>(
from_ty: Ty<'tcx>,
to_ty: Ty<'tcx>,
mut arg: &'tcx Expr<'_>,
const_context: bool,
msrv: &Msrv,
) -> bool {
match (&from_ty.kind(), &to_ty.kind()) {
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_)) => {
(ty::Float(float_ty), ty::Int(_) | ty::Uint(_))
if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) =>
{
span_lint_and_then(
cx,
TRANSMUTE_FLOAT_TO_INT,

View File

@ -1,4 +1,5 @@
use super::TRANSMUTE_INT_TO_FLOAT;
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::sugg;
use rustc_errors::Applicability;
@ -14,9 +15,11 @@ pub(super) fn check<'tcx>(
from_ty: Ty<'tcx>,
to_ty: Ty<'tcx>,
arg: &'tcx Expr<'_>,
const_context: bool,
msrv: &Msrv,
) -> bool {
match (&from_ty.kind(), &to_ty.kind()) {
(ty::Int(_) | ty::Uint(_), ty::Float(_)) => {
(ty::Int(_) | ty::Uint(_), ty::Float(_)) if !const_context || msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) => {
span_lint_and_then(
cx,
TRANSMUTE_INT_TO_FLOAT,

View File

@ -1,4 +1,5 @@
use super::TRANSMUTE_NUM_TO_BYTES;
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::sugg;
use rustc_errors::Applicability;
@ -14,12 +15,17 @@ pub(super) fn check<'tcx>(
from_ty: Ty<'tcx>,
to_ty: Ty<'tcx>,
arg: &'tcx Expr<'_>,
const_context: bool,
msrv: &Msrv,
) -> bool {
match (&from_ty.kind(), &to_ty.kind()) {
(ty::Int(_) | ty::Uint(_) | ty::Float(_), ty::Array(arr_ty, _)) => {
if !matches!(arr_ty.kind(), ty::Uint(UintTy::U8)) {
return false;
}
if matches!(from_ty.kind(), ty::Float(_)) && const_context && !msrv.meets(msrvs::CONST_FLOAT_BITS_CONV) {
return false;
}
span_lint_and_then(
cx,