-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: arithmetic: split into integer_arithmetic and float_arithmetic…
… files.
- Loading branch information
1 parent
f041dcd
commit ec1dcde
Showing
5 changed files
with
266 additions
and
255 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.