Skip to content

Commit

Permalink
tests: arithmetic: split into integer_arithmetic and float_arithmetic…
Browse files Browse the repository at this point in the history
… files.
  • Loading branch information
matthiaskrgr committed Mar 18, 2020
1 parent f041dcd commit ec1dcde
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 255 deletions.
211 changes: 0 additions & 211 deletions tests/ui/arithmetic.stderr

This file was deleted.

53 changes: 53 additions & 0 deletions tests/ui/float_arithmetic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
#![allow(
unused,
clippy::shadow_reuse,
clippy::shadow_unrelated,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::trivially_copy_pass_by_ref
)]

#[rustfmt::skip]
fn main() {
let mut f = 1.0f32;

f * 2.0;

1.0 + f;
f * 2.0;
f / 2.0;
f - 2.0 * 4.2;
-f;

f += 1.0;
f -= 1.0;
f *= 2.0;
f /= 2.0;
}

// also warn about floating point arith with references involved

pub fn float_arith_ref() {
3.1_f32 + &1.2_f32;
&3.4_f32 + 1.5_f32;
&3.5_f32 + &1.3_f32;
}

pub fn float_foo(f: &f32) -> f32 {
let a = 5.1;
a + f
}

pub fn float_bar(f1: &f32, f2: &f32) -> f32 {
f1 + f2
}

pub fn float_baz(f1: f32, f2: &f32) -> f32 {
f1 + f2
}

pub fn float_qux(f1: f32, f2: f32) -> f32 {
(&f1 + &f2)
}
106 changes: 106 additions & 0 deletions tests/ui/float_arithmetic.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:16:5
|
LL | f * 2.0;
| ^^^^^^^
|
= note: `-D clippy::float-arithmetic` implied by `-D warnings`

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:18:5
|
LL | 1.0 + f;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:19:5
|
LL | f * 2.0;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:20:5
|
LL | f / 2.0;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:21:5
|
LL | f - 2.0 * 4.2;
| ^^^^^^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:22:5
|
LL | -f;
| ^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:24:5
|
LL | f += 1.0;
| ^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:25:5
|
LL | f -= 1.0;
| ^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:26:5
|
LL | f *= 2.0;
| ^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:27:5
|
LL | f /= 2.0;
| ^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:33:5
|
LL | 3.1_f32 + &1.2_f32;
| ^^^^^^^^^^^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:34:5
|
LL | &3.4_f32 + 1.5_f32;
| ^^^^^^^^^^^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:35:5
|
LL | &3.5_f32 + &1.3_f32;
| ^^^^^^^^^^^^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:40:5
|
LL | a + f
| ^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:44:5
|
LL | f1 + f2
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:48:5
|
LL | f1 + f2
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:52:5
|
LL | (&f1 + &f2)
| ^^^^^^^^^^^

error: aborting due to 17 previous errors

Loading

0 comments on commit ec1dcde

Please sign in to comment.