diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 6178addfff12..48e4e83ef34e 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -99,10 +99,15 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { LitFloatType::Unsuffixed => None, }; let (is_whole, is_inf, mut float_str) = match fty { - FloatTy::F16 | FloatTy::F128 => { + FloatTy::F128 => { // FIXME(f16_f128): do a check like the others when parsing is available return; }, + FloatTy::F16 => { + let value = sym_str.parse::().unwrap(); + + (value.fract() == 0.0, value.is_infinite(), formatter.format(value)) + }, FloatTy::F32 => { let value = sym_str.parse::().unwrap(); diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index 946114e10419..e7adbaac614a 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -62,16 +62,10 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply { } fn check_mul(cx: &LateContext<'_>, mul_expr: &Expr<'_>, lit: &Expr<'_>, exp: &Expr<'_>) { - const F16_ONE: u16 = 1.0_f16.to_bits(); - const F128_ONE: u128 = 1.0_f128.to_bits(); if let ExprKind::Lit(l) = lit.kind && matches!( consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)), - Constant::Int(1) - | Constant::F16(F16_ONE) - | Constant::F32(1.0) - | Constant::F64(1.0) - | Constant::F128(F128_ONE) + Constant::Int(1) | Constant::F16(1.0) | Constant::F32(1.0) | Constant::F64(1.0) | Constant::F128(1.0) ) && cx.typeck_results().expr_ty(exp).is_numeric() { diff --git a/clippy_lints/src/operators/float_cmp.rs b/clippy_lints/src/operators/float_cmp.rs index eb2353cfd90b..5bd34d4087f2 100644 --- a/clippy_lints/src/operators/float_cmp.rs +++ b/clippy_lints/src/operators/float_cmp.rs @@ -68,18 +68,18 @@ fn get_lint_and_message(is_local: bool, is_comparing_arrays: bool) -> (&'static ( FLOAT_CMP, if is_comparing_arrays { - "strict comparison of `f32` or `f64` arrays" + "strict comparison of floating point arrays" } else { - "strict comparison of `f32` or `f64`" + "strict comparison of floating point values" }, ) } else { ( FLOAT_CMP_CONST, if is_comparing_arrays { - "strict comparison of `f32` or `f64` constant arrays" + "strict comparison of floating point constant arrays" } else { - "strict comparison of `f32` or `f64` constant" + "strict comparison of floating point constant" }, ) } @@ -87,12 +87,15 @@ fn get_lint_and_message(is_local: bool, is_comparing_arrays: bool) -> (&'static fn is_allowed(val: &Constant) -> bool { match val { - // FIXME(f16_f128): add when equality check is available on all platforms + &Constant::F16(f) => f == 0.0 || f.is_infinite(), &Constant::F32(f) => f == 0.0 || f.is_infinite(), &Constant::F64(f) => f == 0.0 || f.is_infinite(), + &Constant::F128(f) => f == 0.0 || f.is_infinite(), Constant::Vec(vec) => vec.iter().all(|f| match f { + Constant::F16(f) => *f == 0.0 || (*f).is_infinite(), Constant::F32(f) => *f == 0.0 || (*f).is_infinite(), Constant::F64(f) => *f == 0.0 || (*f).is_infinite(), + Constant::F128(f) => *f == 0.0 || (*f).is_infinite(), _ => false, }), _ => false, diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 7b8c7f3f0d6b..9f27caddea85 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -10,7 +10,7 @@ use crate::{clip, is_direct_expn_of, sext, sym, unsext}; use rustc_abi::Size; use rustc_apfloat::Float; -use rustc_apfloat::ieee::{Half, Quad}; +use rustc_apfloat::ieee::Quad; use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, PatExpr, PatExprKind, QPath, TyKind, UnOp}; @@ -38,16 +38,14 @@ pub enum Constant { Char(char), /// An integer's bit representation. Int(u128), - /// An `f16` bitcast to a `u16`. - // FIXME(f16_f128): use `f16` once builtins are available on all host tools platforms. - F16(u16), + /// An `f16`. + F16(f16), /// An `f32`. F32(f32), /// An `f64`. F64(f64), /// An `f128` bitcast to a `u128`. - // FIXME(f16_f128): use `f128` once builtins are available on all host tools platforms. - F128(u128), + F128(f128), /// `true` or `false`. Bool(bool), /// An array of constants. @@ -169,8 +167,7 @@ impl Hash for Constant { i.hash(state); }, Self::F16(f) => { - // FIXME(f16_f128): once conversions to/from `f128` are available on all platforms, - f.hash(state); + f64::from(f).to_bits().hash(state); }, Self::F32(f) => { f64::from(f).to_bits().hash(state); @@ -179,7 +176,7 @@ impl Hash for Constant { f.to_bits().hash(state); }, Self::F128(f) => { - f.hash(state); + f.to_bits().hash(state); }, Self::Bool(b) => { b.hash(state); @@ -281,14 +278,9 @@ impl Constant { self } - fn parse_f16(s: &str) -> Self { - let f: Half = s.parse().unwrap(); - Self::F16(f.to_bits().try_into().unwrap()) - } - fn parse_f128(s: &str) -> Self { let f: Quad = s.parse().unwrap(); - Self::F128(f.to_bits()) + Self::F128(f128::from_bits(f.to_bits())) } pub fn new_numeric_min<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { @@ -394,18 +386,20 @@ impl Constant { pub fn is_pos_infinity(&self) -> bool { match *self { - // FIXME(f16_f128): add f16 and f128 when constants are available + Constant::F16(x) => x == f16::INFINITY, Constant::F32(x) => x == f32::INFINITY, Constant::F64(x) => x == f64::INFINITY, + Constant::F128(x) => x == f128::INFINITY, _ => false, } } pub fn is_neg_infinity(&self) -> bool { match *self { - // FIXME(f16_f128): add f16 and f128 when constants are available + Constant::F16(x) => x == f16::NEG_INFINITY, Constant::F32(x) => x == f32::NEG_INFINITY, Constant::F64(x) => x == f64::NEG_INFINITY, + Constant::F128(x) => x == f128::NEG_INFINITY, _ => false, } } @@ -420,14 +414,14 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n.get()), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { - // FIXME(f16_f128): just use `parse()` directly when available for `f16`/`f128` - FloatTy::F16 => Constant::parse_f16(is.as_str()), + FloatTy::F16 => Constant::F16(is.as_str().parse().unwrap()), FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), + // FIXME(f16_f128): just use `parse()` directly when available for `f128` FloatTy::F128 => Constant::parse_f128(is.as_str()), }, LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { - ty::Float(FloatTy::F16) => Constant::parse_f16(is.as_str()), + ty::Float(FloatTy::F16) => Constant::F16(is.as_str().parse().unwrap()), ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), ty::Float(FloatTy::F128) => Constant::parse_f128(is.as_str()), @@ -932,6 +926,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { } } + #[expect(clippy::too_many_lines)] fn binop(&self, op: BinOpKind, left: &Expr<'_>, right: &Expr<'_>) -> Option { let l = self.expr(left)?; let r = self.expr(right); @@ -1003,7 +998,20 @@ impl<'tcx> ConstEvalCtxt<'tcx> { }, _ => None, }, - // FIXME(f16_f128): add these types when binary operations are available on all platforms + (Constant::F16(l), Some(Constant::F16(r))) => match op { + BinOpKind::Add => Some(Constant::F16(l + r)), + BinOpKind::Sub => Some(Constant::F16(l - r)), + BinOpKind::Mul => Some(Constant::F16(l * r)), + BinOpKind::Div => Some(Constant::F16(l / r)), + BinOpKind::Rem => Some(Constant::F16(l % r)), + BinOpKind::Eq => Some(Constant::Bool(l == r)), + BinOpKind::Ne => Some(Constant::Bool(l != r)), + BinOpKind::Lt => Some(Constant::Bool(l < r)), + BinOpKind::Le => Some(Constant::Bool(l <= r)), + BinOpKind::Ge => Some(Constant::Bool(l >= r)), + BinOpKind::Gt => Some(Constant::Bool(l > r)), + _ => None, + }, (Constant::F32(l), Some(Constant::F32(r))) => match op { BinOpKind::Add => Some(Constant::F32(l + r)), BinOpKind::Sub => Some(Constant::F32(l - r)), @@ -1032,6 +1040,20 @@ impl<'tcx> ConstEvalCtxt<'tcx> { BinOpKind::Gt => Some(Constant::Bool(l > r)), _ => None, }, + (Constant::F128(l), Some(Constant::F128(r))) => match op { + BinOpKind::Add => Some(Constant::F128(l + r)), + BinOpKind::Sub => Some(Constant::F128(l - r)), + BinOpKind::Mul => Some(Constant::F128(l * r)), + BinOpKind::Div => Some(Constant::F128(l / r)), + BinOpKind::Rem => Some(Constant::F128(l % r)), + BinOpKind::Eq => Some(Constant::Bool(l == r)), + BinOpKind::Ne => Some(Constant::Bool(l != r)), + BinOpKind::Lt => Some(Constant::Bool(l < r)), + BinOpKind::Le => Some(Constant::Bool(l <= r)), + BinOpKind::Ge => Some(Constant::Bool(l >= r)), + BinOpKind::Gt => Some(Constant::Bool(l > r)), + _ => None, + }, (l, r) => match (op, l, r) { (BinOpKind::And, Constant::Bool(false), _) => Some(Constant::Bool(false)), (BinOpKind::Or, Constant::Bool(true), _) => Some(Constant::Bool(true)), @@ -1053,10 +1075,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, val: ConstValue, ty: Ty<'tcx>) -> O (ConstValue::Scalar(Scalar::Int(int)), _) => match ty.kind() { ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)), ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))), - ty::Float(FloatTy::F16) => Some(Constant::F16(int.into())), + ty::Float(FloatTy::F16) => Some(Constant::F16(f16::from_bits(int.into()))), ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(int.into()))), ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(int.into()))), - ty::Float(FloatTy::F128) => Some(Constant::F128(int.into())), + ty::Float(FloatTy::F128) => Some(Constant::F128(f128::from_bits(int.into()))), ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))), _ => None, }, @@ -1076,10 +1098,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, val: ConstValue, ty: Ty<'tcx>) -> O let range = alloc_range(offset + size * idx, size); let val = alloc.read_scalar(&tcx, range, /* read_provenance */ false).ok()?; res.push(match flt { - FloatTy::F16 => Constant::F16(val.to_u16().discard_err()?), + FloatTy::F16 => Constant::F16(f16::from_bits(val.to_u16().discard_err()?)), FloatTy::F32 => Constant::F32(f32::from_bits(val.to_u32().discard_err()?)), FloatTy::F64 => Constant::F64(f64::from_bits(val.to_u64().discard_err()?)), - FloatTy::F128 => Constant::F128(val.to_u128().discard_err()?), + FloatTy::F128 => Constant::F128(f128::from_bits(val.to_u128().discard_err()?)), }); } Some(Constant::Vec(res)) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 46c5af058ccc..ab44434e1fdb 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1,4 +1,6 @@ #![feature(box_patterns)] +#![feature(f128)] +#![feature(f16)] #![feature(if_let_guard)] #![feature(macro_metavar_expr)] #![feature(never_type)] diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index b7ed596d811e..aee122e2298e 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -165,11 +165,9 @@ pub fn association_with_structures_should_not_trigger_the_lint() { pub fn hard_coded_allowed() { let _ = 1f16 + 1f16; - //~^ arithmetic_side_effects let _ = 1f32 + 1f32; let _ = 1f64 + 1f64; let _ = 1f128 + 1f128; - //~^ arithmetic_side_effects let _ = Saturating(0u32) + Saturating(0u32); let _ = String::new() + ""; diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr index 22742a82601a..1aa4a74a7948 100644 --- a/tests/ui/arithmetic_side_effects.stderr +++ b/tests/ui/arithmetic_side_effects.stderr @@ -1,797 +1,785 @@ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:167:13 + --> tests/ui/arithmetic_side_effects.rs:174:13 | -LL | let _ = 1f16 + 1f16; - | ^^^^^^^^^^^ +LL | let _ = String::new() + &String::new(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:171:13 - | -LL | let _ = 1f128 + 1f128; - | ^^^^^^^^^^^^^ - -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:176:13 - | -LL | let _ = String::new() + &String::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:312:5 + --> tests/ui/arithmetic_side_effects.rs:310:5 | LL | _n += 1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:314:5 + --> tests/ui/arithmetic_side_effects.rs:312:5 | LL | _n += &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:316:5 + --> tests/ui/arithmetic_side_effects.rs:314:5 | LL | _n -= 1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:318:5 + --> tests/ui/arithmetic_side_effects.rs:316:5 | LL | _n -= &1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:320:5 + --> tests/ui/arithmetic_side_effects.rs:318:5 | LL | _n /= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:322:5 + --> tests/ui/arithmetic_side_effects.rs:320:5 | LL | _n /= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:324:5 + --> tests/ui/arithmetic_side_effects.rs:322:5 | LL | _n %= 0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:326:5 + --> tests/ui/arithmetic_side_effects.rs:324:5 | LL | _n %= &0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:328:5 + --> tests/ui/arithmetic_side_effects.rs:326:5 | LL | _n *= 2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:330:5 + --> tests/ui/arithmetic_side_effects.rs:328:5 | LL | _n *= &2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:332:5 + --> tests/ui/arithmetic_side_effects.rs:330:5 | LL | _n += -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:334:5 + --> tests/ui/arithmetic_side_effects.rs:332:5 | LL | _n += &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:336:5 + --> tests/ui/arithmetic_side_effects.rs:334:5 | LL | _n -= -1; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:338:5 + --> tests/ui/arithmetic_side_effects.rs:336:5 | LL | _n -= &-1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:340:5 + --> tests/ui/arithmetic_side_effects.rs:338:5 | LL | _n /= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:342:5 + --> tests/ui/arithmetic_side_effects.rs:340:5 | LL | _n /= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:344:5 + --> tests/ui/arithmetic_side_effects.rs:342:5 | LL | _n %= -0; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:346:5 + --> tests/ui/arithmetic_side_effects.rs:344:5 | LL | _n %= &-0; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:348:5 + --> tests/ui/arithmetic_side_effects.rs:346:5 | LL | _n *= -2; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:350:5 + --> tests/ui/arithmetic_side_effects.rs:348:5 | LL | _n *= &-2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:352:5 + --> tests/ui/arithmetic_side_effects.rs:350:5 | LL | _custom += Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:354:5 + --> tests/ui/arithmetic_side_effects.rs:352:5 | LL | _custom += &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:356:5 + --> tests/ui/arithmetic_side_effects.rs:354:5 | LL | _custom -= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:358:5 + --> tests/ui/arithmetic_side_effects.rs:356:5 | LL | _custom -= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:360:5 + --> tests/ui/arithmetic_side_effects.rs:358:5 | LL | _custom /= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:362:5 + --> tests/ui/arithmetic_side_effects.rs:360:5 | LL | _custom /= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:364:5 + --> tests/ui/arithmetic_side_effects.rs:362:5 | LL | _custom %= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:366:5 + --> tests/ui/arithmetic_side_effects.rs:364:5 | LL | _custom %= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:368:5 + --> tests/ui/arithmetic_side_effects.rs:366:5 | LL | _custom *= Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:370:5 + --> tests/ui/arithmetic_side_effects.rs:368:5 | LL | _custom *= &Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:372:5 + --> tests/ui/arithmetic_side_effects.rs:370:5 | LL | _custom >>= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:374:5 + --> tests/ui/arithmetic_side_effects.rs:372:5 | LL | _custom >>= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:376:5 + --> tests/ui/arithmetic_side_effects.rs:374:5 | LL | _custom <<= Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:378:5 + --> tests/ui/arithmetic_side_effects.rs:376:5 | LL | _custom <<= &Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:380:5 + --> tests/ui/arithmetic_side_effects.rs:378:5 | LL | _custom += -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:382:5 + --> tests/ui/arithmetic_side_effects.rs:380:5 | LL | _custom += &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:384:5 + --> tests/ui/arithmetic_side_effects.rs:382:5 | LL | _custom -= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:386:5 + --> tests/ui/arithmetic_side_effects.rs:384:5 | LL | _custom -= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:388:5 + --> tests/ui/arithmetic_side_effects.rs:386:5 | LL | _custom /= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:390:5 + --> tests/ui/arithmetic_side_effects.rs:388:5 | LL | _custom /= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:392:5 + --> tests/ui/arithmetic_side_effects.rs:390:5 | LL | _custom %= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:394:5 + --> tests/ui/arithmetic_side_effects.rs:392:5 | LL | _custom %= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:396:5 + --> tests/ui/arithmetic_side_effects.rs:394:5 | LL | _custom *= -Custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:398:5 + --> tests/ui/arithmetic_side_effects.rs:396:5 | LL | _custom *= &-Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:400:5 + --> tests/ui/arithmetic_side_effects.rs:398:5 | LL | _custom >>= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:402:5 + --> tests/ui/arithmetic_side_effects.rs:400:5 | LL | _custom >>= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:404:5 + --> tests/ui/arithmetic_side_effects.rs:402:5 | LL | _custom <<= -Custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:406:5 + --> tests/ui/arithmetic_side_effects.rs:404:5 | LL | _custom <<= &-Custom; | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:410:10 + --> tests/ui/arithmetic_side_effects.rs:408:10 | LL | _n = _n + 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:412:10 + --> tests/ui/arithmetic_side_effects.rs:410:10 | LL | _n = _n + &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:414:10 + --> tests/ui/arithmetic_side_effects.rs:412:10 | LL | _n = 1 + _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:416:10 + --> tests/ui/arithmetic_side_effects.rs:414:10 | LL | _n = &1 + _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:418:10 + --> tests/ui/arithmetic_side_effects.rs:416:10 | LL | _n = _n - 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:420:10 + --> tests/ui/arithmetic_side_effects.rs:418:10 | LL | _n = _n - &1; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:422:10 + --> tests/ui/arithmetic_side_effects.rs:420:10 | LL | _n = 1 - _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:424:10 + --> tests/ui/arithmetic_side_effects.rs:422:10 | LL | _n = &1 - _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:426:10 + --> tests/ui/arithmetic_side_effects.rs:424:10 | LL | _n = _n / 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:428:10 + --> tests/ui/arithmetic_side_effects.rs:426:10 | LL | _n = _n / &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:430:10 + --> tests/ui/arithmetic_side_effects.rs:428:10 | LL | _n = _n % 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:432:10 + --> tests/ui/arithmetic_side_effects.rs:430:10 | LL | _n = _n % &0; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:434:10 + --> tests/ui/arithmetic_side_effects.rs:432:10 | LL | _n = _n * 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:436:10 + --> tests/ui/arithmetic_side_effects.rs:434:10 | LL | _n = _n * &2; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:438:10 + --> tests/ui/arithmetic_side_effects.rs:436:10 | LL | _n = 2 * _n; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:440:10 + --> tests/ui/arithmetic_side_effects.rs:438:10 | LL | _n = &2 * _n; | ^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:442:10 + --> tests/ui/arithmetic_side_effects.rs:440:10 | LL | _n = 23 + &85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:444:10 + --> tests/ui/arithmetic_side_effects.rs:442:10 | LL | _n = &23 + 85; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:446:10 + --> tests/ui/arithmetic_side_effects.rs:444:10 | LL | _n = &23 + &85; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:448:15 + --> tests/ui/arithmetic_side_effects.rs:446:15 | LL | _custom = _custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:450:15 + --> tests/ui/arithmetic_side_effects.rs:448:15 | LL | _custom = _custom + &_custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:452:15 + --> tests/ui/arithmetic_side_effects.rs:450:15 | LL | _custom = Custom + _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:454:15 + --> tests/ui/arithmetic_side_effects.rs:452:15 | LL | _custom = &Custom + _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:456:15 + --> tests/ui/arithmetic_side_effects.rs:454:15 | LL | _custom = _custom - Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:458:15 + --> tests/ui/arithmetic_side_effects.rs:456:15 | LL | _custom = _custom - &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:460:15 + --> tests/ui/arithmetic_side_effects.rs:458:15 | LL | _custom = Custom - _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:462:15 + --> tests/ui/arithmetic_side_effects.rs:460:15 | LL | _custom = &Custom - _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:464:15 + --> tests/ui/arithmetic_side_effects.rs:462:15 | LL | _custom = _custom / Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:466:15 + --> tests/ui/arithmetic_side_effects.rs:464:15 | LL | _custom = _custom / &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:468:15 + --> tests/ui/arithmetic_side_effects.rs:466:15 | LL | _custom = _custom % Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:470:15 + --> tests/ui/arithmetic_side_effects.rs:468:15 | LL | _custom = _custom % &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:472:15 + --> tests/ui/arithmetic_side_effects.rs:470:15 | LL | _custom = _custom * Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:474:15 + --> tests/ui/arithmetic_side_effects.rs:472:15 | LL | _custom = _custom * &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:476:15 + --> tests/ui/arithmetic_side_effects.rs:474:15 | LL | _custom = Custom * _custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:478:15 + --> tests/ui/arithmetic_side_effects.rs:476:15 | LL | _custom = &Custom * _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:480:15 + --> tests/ui/arithmetic_side_effects.rs:478:15 | LL | _custom = Custom + &Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:482:15 + --> tests/ui/arithmetic_side_effects.rs:480:15 | LL | _custom = &Custom + Custom; | ^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:484:15 + --> tests/ui/arithmetic_side_effects.rs:482:15 | LL | _custom = &Custom + &Custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:486:15 + --> tests/ui/arithmetic_side_effects.rs:484:15 | LL | _custom = _custom >> _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:488:15 + --> tests/ui/arithmetic_side_effects.rs:486:15 | LL | _custom = _custom >> &_custom; | ^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:490:15 + --> tests/ui/arithmetic_side_effects.rs:488:15 | LL | _custom = Custom << _custom; | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:492:15 + --> tests/ui/arithmetic_side_effects.rs:490:15 | LL | _custom = &Custom << _custom; | ^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:496:23 + --> tests/ui/arithmetic_side_effects.rs:494:23 | LL | _n.saturating_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:498:21 + --> tests/ui/arithmetic_side_effects.rs:496:21 | LL | _n.wrapping_div(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:500:21 + --> tests/ui/arithmetic_side_effects.rs:498:21 | LL | _n.wrapping_rem(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:502:28 + --> tests/ui/arithmetic_side_effects.rs:500:28 | LL | _n.wrapping_rem_euclid(0); | ^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:505:23 + --> tests/ui/arithmetic_side_effects.rs:503:23 | LL | _n.saturating_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:507:21 + --> tests/ui/arithmetic_side_effects.rs:505:21 | LL | _n.wrapping_div(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:509:21 + --> tests/ui/arithmetic_side_effects.rs:507:21 | LL | _n.wrapping_rem(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:511:28 + --> tests/ui/arithmetic_side_effects.rs:509:28 | LL | _n.wrapping_rem_euclid(_n); | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:514:23 + --> tests/ui/arithmetic_side_effects.rs:512:23 | LL | _n.saturating_div(*Box::new(_n)); | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:518:10 + --> tests/ui/arithmetic_side_effects.rs:516:10 | LL | _n = -_n; | ^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:520:10 + --> tests/ui/arithmetic_side_effects.rs:518:10 | LL | _n = -&_n; | ^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:522:15 + --> tests/ui/arithmetic_side_effects.rs:520:15 | LL | _custom = -_custom; | ^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:524:15 + --> tests/ui/arithmetic_side_effects.rs:522:15 | LL | _custom = -&_custom; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:526:9 + --> tests/ui/arithmetic_side_effects.rs:524:9 | LL | _ = -*Box::new(_n); | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:536:5 + --> tests/ui/arithmetic_side_effects.rs:534:5 | LL | 1 + i; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:538:5 + --> tests/ui/arithmetic_side_effects.rs:536:5 | LL | i * 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:540:5 + --> tests/ui/arithmetic_side_effects.rs:538:5 | LL | 1 % i / 2; | ^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:542:5 + --> tests/ui/arithmetic_side_effects.rs:540:5 | LL | i - 2 + 2 - i; | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:544:5 + --> tests/ui/arithmetic_side_effects.rs:542:5 | LL | -i; | ^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:556:5 + --> tests/ui/arithmetic_side_effects.rs:554:5 | LL | i += 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:558:5 + --> tests/ui/arithmetic_side_effects.rs:556:5 | LL | i -= 1; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:560:5 + --> tests/ui/arithmetic_side_effects.rs:558:5 | LL | i *= 2; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:563:5 + --> tests/ui/arithmetic_side_effects.rs:561:5 | LL | i /= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:566:5 + --> tests/ui/arithmetic_side_effects.rs:564:5 | LL | i /= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:568:5 + --> tests/ui/arithmetic_side_effects.rs:566:5 | LL | i /= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:571:5 + --> tests/ui/arithmetic_side_effects.rs:569:5 | LL | i %= 0; | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:574:5 + --> tests/ui/arithmetic_side_effects.rs:572:5 | LL | i %= var1; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:576:5 + --> tests/ui/arithmetic_side_effects.rs:574:5 | LL | i %= var2; | ^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:587:5 + --> tests/ui/arithmetic_side_effects.rs:585:5 | LL | 10 / a | ^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:642:9 + --> tests/ui/arithmetic_side_effects.rs:640:9 | LL | x / maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:647:9 + --> tests/ui/arithmetic_side_effects.rs:645:9 | LL | x % maybe_zero | ^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:659:5 + --> tests/ui/arithmetic_side_effects.rs:657:5 | LL | one.add_assign(1); | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:664:5 + --> tests/ui/arithmetic_side_effects.rs:662:5 | LL | one.sub_assign(1); | ^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:685:5 + --> tests/ui/arithmetic_side_effects.rs:683:5 | LL | one.add(&one); | ^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:687:5 + --> tests/ui/arithmetic_side_effects.rs:685:5 | LL | Box::new(one).add(one); | ^^^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:696:13 + --> tests/ui/arithmetic_side_effects.rs:694:13 | LL | let _ = u128::MAX + u128::from(1u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:713:13 + --> tests/ui/arithmetic_side_effects.rs:711:13 | LL | let _ = u128::MAX * u128::from(1u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:736:33 + --> tests/ui/arithmetic_side_effects.rs:734:33 | LL | let _ = Duration::from_secs(86400 * Foo::from(1)); | ^^^^^^^^^^^^^^^^^^^^ error: arithmetic operation that can potentially result in unexpected side-effects - --> tests/ui/arithmetic_side_effects.rs:742:33 + --> tests/ui/arithmetic_side_effects.rs:740:33 | LL | let _ = Duration::from_secs(86400 * shift(1)); | ^^^^^^^^^^^^^^^^ -error: aborting due to 132 previous errors +error: aborting due to 130 previous errors diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index ce0ffd8a2192..9e1e34804ca0 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -1,5 +1,5 @@ -// FIXME(f16_f128): const casting is not yet supported for these types. Add when available. - +#![feature(f128)] +#![feature(f16)] #![warn(clippy::float_cmp)] #![allow( unused, @@ -71,6 +71,10 @@ fn main() { twice(ONE) != ONE; ONE as f64 != 2.0; //~^ float_cmp + ONE as f16 != 2.0; + //~^ float_cmp + ONE as f128 != 2.0; + //~^ float_cmp ONE as f64 != 0.0; // no error, comparison with zero is ok diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index e573c0baeac2..fc294e00c1f4 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -1,4 +1,4 @@ -error: strict comparison of `f32` or `f64` +error: strict comparison of floating point values --> tests/ui/float_cmp.rs:72:5 | LL | ONE as f64 != 2.0; @@ -7,35 +7,47 @@ LL | ONE as f64 != 2.0; = note: `-D clippy::float-cmp` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::float_cmp)]` -error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:79:5 +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:74:5 + | +LL | ONE as f16 != 2.0; + | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f16 - 2.0).abs() > error_margin` + +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:76:5 + | +LL | ONE as f128 != 2.0; + | ^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f128 - 2.0).abs() > error_margin` + +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:83:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` -error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:84:5 +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:88:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` -error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:105:5 +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:109:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` -error: strict comparison of `f32` or `f64` arrays - --> tests/ui/float_cmp.rs:111:5 +error: strict comparison of floating point arrays + --> tests/ui/float_cmp.rs:115:5 | LL | a1 == a2; | ^^^^^^^^ -error: strict comparison of `f32` or `f64` - --> tests/ui/float_cmp.rs:114:5 +error: strict comparison of floating point values + --> tests/ui/float_cmp.rs:118:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 3af53f2e84a2..b31372db3d0e 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -1,4 +1,6 @@ //@no-rustfix: suggestions have an error margin placeholder +#![feature(f128)] +#![feature(f16)] #![warn(clippy::float_cmp_const)] #![allow(clippy::float_cmp)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] @@ -67,4 +69,14 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; //~^ float_cmp_const + + const F16_NON_ZERO_ARRAY: [f16; 3] = [0.0, 0.1, 0.2]; + const F16_NON_ZERO_ARRAY2: [f16; 3] = [0.2, 0.1, 0.0]; + F16_NON_ZERO_ARRAY == F16_NON_ZERO_ARRAY2; + //~^ float_cmp_const + + const F128_NON_ZERO_ARRAY: [f128; 3] = [0.0, 0.1, 0.2]; + const F128_NON_ZERO_ARRAY2: [f128; 3] = [0.2, 0.1, 0.0]; + F128_NON_ZERO_ARRAY == F128_NON_ZERO_ARRAY2; + //~^ float_cmp_const } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 482a55a54be6..770a5daaa5a0 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -1,5 +1,5 @@ -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:15:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:17:5 | LL | 1f32 == ONE; | ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin` @@ -7,47 +7,59 @@ LL | 1f32 == ONE; = note: `-D clippy::float-cmp-const` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:18:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:20:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:21:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:23:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:24:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:26:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:28:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:30:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:32:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:34:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` -error: strict comparison of `f32` or `f64` constant - --> tests/ui/float_cmp_const.rs:35:5 +error: strict comparison of floating point constant + --> tests/ui/float_cmp_const.rs:37:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` -error: strict comparison of `f32` or `f64` constant arrays - --> tests/ui/float_cmp_const.rs:68:5 +error: strict comparison of floating point constant arrays + --> tests/ui/float_cmp_const.rs:70:5 | LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: strict comparison of floating point constant arrays + --> tests/ui/float_cmp_const.rs:75:5 + | +LL | F16_NON_ZERO_ARRAY == F16_NON_ZERO_ARRAY2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: strict comparison of floating point constant arrays + --> tests/ui/float_cmp_const.rs:80:5 + | +LL | F128_NON_ZERO_ARRAY == F128_NON_ZERO_ARRAY2; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 10 previous errors diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed index 925a1465cc30..02b33a7037d9 100644 --- a/tests/ui/lossy_float_literal.fixed +++ b/tests/ui/lossy_float_literal.fixed @@ -5,11 +5,16 @@ fn main() { // Lossy whole-number float literals - let _: f16 = 4_097.0; - let _: f16 = 4_097.; - let _: f16 = 4_097.000; - let _ = 4_097f16; - let _: f16 = -4_097.0; + let _: f16 = 4_096.0; + //~^ lossy_float_literal + let _: f16 = 4_096.0; + //~^ lossy_float_literal + let _: f16 = 4_096.0; + //~^ lossy_float_literal + let _ = 4_096_f16; + //~^ lossy_float_literal + let _: f16 = -4_096.0; + //~^ lossy_float_literal let _: f32 = 16_777_216.0; //~^ lossy_float_literal diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs index 7341388d4816..31f9499c293a 100644 --- a/tests/ui/lossy_float_literal.rs +++ b/tests/ui/lossy_float_literal.rs @@ -6,10 +6,15 @@ fn main() { // Lossy whole-number float literals let _: f16 = 4_097.0; + //~^ lossy_float_literal let _: f16 = 4_097.; + //~^ lossy_float_literal let _: f16 = 4_097.000; + //~^ lossy_float_literal let _ = 4_097f16; + //~^ lossy_float_literal let _: f16 = -4_097.0; + //~^ lossy_float_literal let _: f32 = 16_777_217.0; //~^ lossy_float_literal diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index 33b650b19c8a..3b966b001a32 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -1,19 +1,79 @@ error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:14:18 + --> tests/ui/lossy_float_literal.rs:8:18 | -LL | let _: f32 = 16_777_217.0; - | ^^^^^^^^^^^^ +LL | let _: f16 = 4_097.0; + | ^^^^^^^ | = note: `-D clippy::lossy-float-literal` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` help: consider changing the type or replacing it with | +LL - let _: f16 = 4_097.0; +LL + let _: f16 = 4_096.0; + | + +error: literal cannot be represented as the underlying type without loss of precision + --> tests/ui/lossy_float_literal.rs:10:18 + | +LL | let _: f16 = 4_097.; + | ^^^^^^ + | +help: consider changing the type or replacing it with + | +LL - let _: f16 = 4_097.; +LL + let _: f16 = 4_096.0; + | + +error: literal cannot be represented as the underlying type without loss of precision + --> tests/ui/lossy_float_literal.rs:12:18 + | +LL | let _: f16 = 4_097.000; + | ^^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL - let _: f16 = 4_097.000; +LL + let _: f16 = 4_096.0; + | + +error: literal cannot be represented as the underlying type without loss of precision + --> tests/ui/lossy_float_literal.rs:14:13 + | +LL | let _ = 4_097f16; + | ^^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL - let _ = 4_097f16; +LL + let _ = 4_096_f16; + | + +error: literal cannot be represented as the underlying type without loss of precision + --> tests/ui/lossy_float_literal.rs:16:19 + | +LL | let _: f16 = -4_097.0; + | ^^^^^^^ + | +help: consider changing the type or replacing it with + | +LL - let _: f16 = -4_097.0; +LL + let _: f16 = -4_096.0; + | + +error: literal cannot be represented as the underlying type without loss of precision + --> tests/ui/lossy_float_literal.rs:19:18 + | +LL | let _: f32 = 16_777_217.0; + | ^^^^^^^^^^^^ + | +help: consider changing the type or replacing it with + | LL - let _: f32 = 16_777_217.0; LL + let _: f32 = 16_777_216.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:16:18 + --> tests/ui/lossy_float_literal.rs:21:18 | LL | let _: f32 = 16_777_219.0; | ^^^^^^^^^^^^ @@ -25,7 +85,7 @@ LL + let _: f32 = 16_777_220.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:18:18 + --> tests/ui/lossy_float_literal.rs:23:18 | LL | let _: f32 = 16_777_219.; | ^^^^^^^^^^^ @@ -37,7 +97,7 @@ LL + let _: f32 = 16_777_220.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:20:18 + --> tests/ui/lossy_float_literal.rs:25:18 | LL | let _: f32 = 16_777_219.000; | ^^^^^^^^^^^^^^ @@ -49,7 +109,7 @@ LL + let _: f32 = 16_777_220.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:22:13 + --> tests/ui/lossy_float_literal.rs:27:13 | LL | let _ = 16_777_219f32; | ^^^^^^^^^^^^^ @@ -61,7 +121,7 @@ LL + let _ = 16_777_220_f32; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:24:19 + --> tests/ui/lossy_float_literal.rs:29:19 | LL | let _: f32 = -16_777_219.0; | ^^^^^^^^^^^^ @@ -73,7 +133,7 @@ LL + let _: f32 = -16_777_220.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:27:18 + --> tests/ui/lossy_float_literal.rs:32:18 | LL | let _: f64 = 9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +145,7 @@ LL + let _: f64 = 9_007_199_254_740_992.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:29:18 + --> tests/ui/lossy_float_literal.rs:34:18 | LL | let _: f64 = 9_007_199_254_740_993.; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +157,7 @@ LL + let _: f64 = 9_007_199_254_740_992.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:31:18 + --> tests/ui/lossy_float_literal.rs:36:18 | LL | let _: f64 = 9_007_199_254_740_993.00; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +169,7 @@ LL + let _: f64 = 9_007_199_254_740_992.0; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:33:13 + --> tests/ui/lossy_float_literal.rs:38:13 | LL | let _ = 9_007_199_254_740_993f64; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +181,7 @@ LL + let _ = 9_007_199_254_740_992_f64; | error: literal cannot be represented as the underlying type without loss of precision - --> tests/ui/lossy_float_literal.rs:35:19 + --> tests/ui/lossy_float_literal.rs:40:19 | LL | let _: f64 = -9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,5 +192,5 @@ LL - let _: f64 = -9_007_199_254_740_993.0; LL + let _: f64 = -9_007_199_254_740_992.0; | -error: aborting due to 11 previous errors +error: aborting due to 16 previous errors diff --git a/tests/ui/neg_multiply.fixed b/tests/ui/neg_multiply.fixed index 32d466e88fc8..5658856e0146 100644 --- a/tests/ui/neg_multiply.fixed +++ b/tests/ui/neg_multiply.fixed @@ -1,3 +1,5 @@ +#![feature(f128)] +#![feature(f16)] #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] @@ -80,6 +82,12 @@ fn float() { -(3.0_f32 as f64); //~^ neg_multiply + -3.0_f16; + //~^ neg_multiply + + -3.0_f128; + //~^ neg_multiply + -1.0 * -1.0; // should be ok } diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 241a72c6d990..058c9b18dc2a 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -1,3 +1,5 @@ +#![feature(f128)] +#![feature(f16)] #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] @@ -80,6 +82,12 @@ fn float() { (3.0_f32 as f64) * -1.0; //~^ neg_multiply + 3.0_f16 * -1.0; + //~^ neg_multiply + + 3.0_f128 * -1.0; + //~^ neg_multiply + -1.0 * -1.0; // should be ok } diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index f4fb6d3ce541..eaaffed6728f 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -1,5 +1,5 @@ error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:28:5 + --> tests/ui/neg_multiply.rs:30:5 | LL | x * -1; | ^^^^^^ help: consider using: `-x` @@ -8,100 +8,112 @@ LL | x * -1; = help: to override `-D warnings` add `#[allow(clippy::neg_multiply)]` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:31:5 + --> tests/ui/neg_multiply.rs:33:5 | LL | -1 * x; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:34:11 + --> tests/ui/neg_multiply.rs:36:11 | LL | 100 + x * -1; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:37:5 + --> tests/ui/neg_multiply.rs:39:5 | LL | (100 + x) * -1; | ^^^^^^^^^^^^^^ help: consider using: `-(100 + x)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:40:5 + --> tests/ui/neg_multiply.rs:42:5 | LL | -1 * 17; | ^^^^^^^ help: consider using: `-17` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:43:14 + --> tests/ui/neg_multiply.rs:45:14 | LL | 0xcafe | 0xff00 * -1; | ^^^^^^^^^^^ help: consider using: `-0xff00` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:46:5 + --> tests/ui/neg_multiply.rs:48:5 | LL | 3_usize as i32 * -1; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:48:5 + --> tests/ui/neg_multiply.rs:50:5 | LL | (3_usize as i32) * -1; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:60:5 + --> tests/ui/neg_multiply.rs:62:5 | LL | x * -1.0; | ^^^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:63:5 + --> tests/ui/neg_multiply.rs:65:5 | LL | -1.0 * x; | ^^^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:66:13 + --> tests/ui/neg_multiply.rs:68:13 | LL | 100.0 + x * -1.0; | ^^^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:69:5 + --> tests/ui/neg_multiply.rs:71:5 | LL | (100.0 + x) * -1.0; | ^^^^^^^^^^^^^^^^^^ help: consider using: `-(100.0 + x)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:72:5 + --> tests/ui/neg_multiply.rs:74:5 | LL | -1.0 * 17.0; | ^^^^^^^^^^^ help: consider using: `-17.0` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:75:11 + --> tests/ui/neg_multiply.rs:77:11 | LL | 0.0 + 0.0 * -1.0; | ^^^^^^^^^^ help: consider using: `-0.0` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:78:5 + --> tests/ui/neg_multiply.rs:80:5 | LL | 3.0_f32 as f64 * -1.0; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3.0_f32 as f64)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:80:5 + --> tests/ui/neg_multiply.rs:82:5 | LL | (3.0_f32 as f64) * -1.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3.0_f32 as f64)` error: this multiplication by -1 can be written more succinctly - --> tests/ui/neg_multiply.rs:93:13 + --> tests/ui/neg_multiply.rs:85:5 + | +LL | 3.0_f16 * -1.0; + | ^^^^^^^^^^^^^^ help: consider using: `-3.0_f16` + +error: this multiplication by -1 can be written more succinctly + --> tests/ui/neg_multiply.rs:88:5 + | +LL | 3.0_f128 * -1.0; + | ^^^^^^^^^^^^^^^ help: consider using: `-3.0_f128` + +error: this multiplication by -1 can be written more succinctly + --> tests/ui/neg_multiply.rs:101:13 | LL | let _ = ((a.delta - 0.5).abs() * -1.0).total_cmp(&1.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-(a.delta - 0.5).abs())` -error: aborting due to 17 previous errors +error: aborting due to 19 previous errors