Skip to content

Commit 2745c87

Browse files
committed
Dont suggest suboptimal_flops unavailable in nostd
Fixes #10634
1 parent 0c44586 commit 2745c87

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

clippy_lints/src/floating_point_arithmetic.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use clippy_utils::consts::{
22
constant, constant_simple, Constant,
33
Constant::{Int, F32, F64},
44
};
5-
use clippy_utils::diagnostics::span_lint_and_sugg;
6-
use clippy_utils::higher;
7-
use clippy_utils::{eq_expr_value, get_parent_expr, in_constant, numeric_literal, peel_blocks, sugg};
5+
use clippy_utils::{
6+
diagnostics::span_lint_and_sugg, eq_expr_value, get_parent_expr, higher, in_constant, is_no_std_crate,
7+
numeric_literal, peel_blocks, sugg,
8+
};
89
use if_chain::if_chain;
910
use rustc_errors::Applicability;
1011
use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp};
@@ -452,6 +453,9 @@ fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'
452453

453454
// TODO: Fix rust-lang/rust-clippy#4735
454455
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+
}
455459
if let ExprKind::Binary(
456460
Spanned {
457461
node: op @ (BinOpKind::Add | BinOpKind::Sub),
@@ -566,6 +570,9 @@ fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a
566570
}
567571

568572
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+
}
569576
if_chain! {
570577
if let Some(higher::If { cond, then, r#else: Some(r#else) }) = higher::If::hir(expr);
571578
let if_body_expr = peel_blocks(then);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(lang_items, start)]
2+
#![warn(clippy::imprecise_flops)]
3+
#![warn(clippy::suboptimal_flops)]
4+
#![no_std]
5+
6+
// The following should not lint, as the suggested methods {f32,f64}.mul_add()
7+
// and {f32,f64}::abs() are not available in no_std
8+
9+
pub fn mul_add() {
10+
let a: f64 = 1234.567;
11+
let b: f64 = 45.67834;
12+
let c: f64 = 0.0004;
13+
let _ = a * b + c;
14+
}
15+
16+
fn fake_abs1(num: f64) -> f64 {
17+
if num >= 0.0 { num } else { -num }
18+
}
19+
20+
#[start]
21+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
22+
0
23+
}
24+
25+
#[panic_handler]
26+
fn panic(_info: &core::panic::PanicInfo) -> ! {
27+
loop {}
28+
}
29+
30+
#[lang = "eh_personality"]
31+
extern "C" fn eh_personality() {}

0 commit comments

Comments
 (0)