Skip to content

Commit 9353170

Browse files
committed
Auto merge of #10730 - blyxyas:no_std_mul_add, r=Jarcho
`imprecise_flops`: Globally ignore `#[no_std]` crates Really small fix. Fixes #10728 changelog: [`imprecise_flops`]: Fix false positives with `#[no_std]`
2 parents 824f2e7 + 0dd2501 commit 9353170

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

clippy_lints/src/floating_point_arithmetic.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'
453453

454454
// TODO: Fix rust-lang/rust-clippy#4735
455455
fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
456-
if is_no_std_crate(cx) {
457-
return; // The suggested methods are not available in core
458-
}
459456
if let ExprKind::Binary(
460457
Spanned {
461458
node: op @ (BinOpKind::Add | BinOpKind::Sub),
@@ -570,9 +567,6 @@ fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a
570567
}
571568

572569
fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) {
573-
if is_no_std_crate(cx) {
574-
return; // The suggested methods are not available in core
575-
}
576570
if_chain! {
577571
if let Some(higher::If { cond, then, r#else: Some(r#else) }) = higher::If::hir(expr);
578572
let if_body_expr = peel_blocks(then);
@@ -737,15 +731,15 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
737731

738732
impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
739733
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
740-
// All of these operations are currently not const.
734+
// All of these operations are currently not const and are in std.
741735
if in_constant(cx, expr.hir_id) {
742736
return;
743737
}
744738

745739
if let ExprKind::MethodCall(path, receiver, args, _) = &expr.kind {
746740
let recv_ty = cx.typeck_results().expr_ty(receiver);
747741

748-
if recv_ty.is_floating_point() {
742+
if recv_ty.is_floating_point() && !is_no_std_crate(cx) {
749743
match path.ident.name.as_str() {
750744
"ln" => check_ln1p(cx, expr, receiver),
751745
"log" => check_log_base(cx, expr, receiver, args),
@@ -756,10 +750,12 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
756750
}
757751
}
758752
} else {
759-
check_expm1(cx, expr);
760-
check_mul_add(cx, expr);
761-
check_custom_abs(cx, expr);
762-
check_log_division(cx, expr);
753+
if !is_no_std_crate(cx) {
754+
check_expm1(cx, expr);
755+
check_mul_add(cx, expr);
756+
check_custom_abs(cx, expr);
757+
check_log_division(cx, expr);
758+
}
763759
check_radians(cx, expr);
764760
}
765761
}

0 commit comments

Comments
 (0)