diff options
| author | bors <bors@rust-lang.org> | 2022-07-25 21:26:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-25 21:26:15 +0000 |
| commit | 8882578a67504bf0b4618cdb6c9ea8f2f10ef5b1 (patch) | |
| tree | de40a50a4d09c1b7cba97fd79b79cc07754343d2 /tests | |
| parent | c76db5c04e49f04a1923e1670f60b55d186e00aa (diff) | |
| parent | 31e5465f8a0e35b8f9e8e28d359e4098e9f44e4f (diff) | |
| download | rust-8882578a67504bf0b4618cdb6c9ea8f2f10ef5b1.tar.gz rust-8882578a67504bf0b4618cdb6c9ea8f2f10ef5b1.zip | |
Auto merge of #9130 - c410-f3r:arith, r=llogiq
Add `Arithmetic` lint Fixes https://github.com/rust-lang/rust-clippy/issues/8903 r? `@llogiq` changelog: Add `Arithmetic` lint
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs | 24 | ||||
| -rw-r--r-- | tests/ui-toml/arithmetic_allowed/clippy.toml | 1 | ||||
| -rw-r--r-- | tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr | 1 | ||||
| -rw-r--r-- | tests/ui/arithmetic.fixed | 27 | ||||
| -rw-r--r-- | tests/ui/arithmetic.rs | 27 |
5 files changed, 80 insertions, 0 deletions
diff --git a/tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs b/tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs new file mode 100644 index 00000000000..195fabdbf71 --- /dev/null +++ b/tests/ui-toml/arithmetic_allowed/arithmetic_allowed.rs @@ -0,0 +1,24 @@ +#![warn(clippy::arithmetic)] + +use core::ops::Add; + +#[derive(Clone, Copy)] +struct Point { + x: i32, + y: i32, +} + +impl Add for Point { + type Output = Self; + + fn add(self, other: Self) -> Self { + todo!() + } +} + +fn main() { + let _ = Point { x: 1, y: 0 } + Point { x: 2, y: 3 }; + + let point: Point = Point { x: 1, y: 0 }; + let _ = point + point; +} diff --git a/tests/ui-toml/arithmetic_allowed/clippy.toml b/tests/ui-toml/arithmetic_allowed/clippy.toml new file mode 100644 index 00000000000..cc40570b12a --- /dev/null +++ b/tests/ui-toml/arithmetic_allowed/clippy.toml @@ -0,0 +1 @@ +arithmetic-allowed = ["Point"] diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 1d87fd91a25..fe5139c4768 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -3,6 +3,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie allow-expect-in-tests allow-unwrap-in-tests allowed-scripts + arithmetic-allowed array-size-threshold avoid-breaking-exported-api await-holding-invalid-types diff --git a/tests/ui/arithmetic.fixed b/tests/ui/arithmetic.fixed new file mode 100644 index 00000000000..a2a1c4394c2 --- /dev/null +++ b/tests/ui/arithmetic.fixed @@ -0,0 +1,27 @@ +// run-rustfix + +#![allow(clippy::unnecessary_owned_empty_strings)] +#![feature(saturating_int_impl)] +#![warn(clippy::arithmetic)] + +use core::num::{Saturating, Wrapping}; + +pub fn hard_coded_allowed() { + let _ = Saturating(0u32) + Saturating(0u32); + let _ = String::new() + ""; + let _ = Wrapping(0u32) + Wrapping(0u32); + + let saturating: Saturating<u32> = Saturating(0u32); + let string: String = String::new(); + let wrapping: Wrapping<u32> = Wrapping(0u32); + + let inferred_saturating = saturating + saturating; + let inferred_string = string + ""; + let inferred_wrapping = wrapping + wrapping; + + let _ = inferred_saturating + inferred_saturating; + let _ = inferred_string + ""; + let _ = inferred_wrapping + inferred_wrapping; +} + +fn main() {} diff --git a/tests/ui/arithmetic.rs b/tests/ui/arithmetic.rs new file mode 100644 index 00000000000..a2a1c4394c2 --- /dev/null +++ b/tests/ui/arithmetic.rs @@ -0,0 +1,27 @@ +// run-rustfix + +#![allow(clippy::unnecessary_owned_empty_strings)] +#![feature(saturating_int_impl)] +#![warn(clippy::arithmetic)] + +use core::num::{Saturating, Wrapping}; + +pub fn hard_coded_allowed() { + let _ = Saturating(0u32) + Saturating(0u32); + let _ = String::new() + ""; + let _ = Wrapping(0u32) + Wrapping(0u32); + + let saturating: Saturating<u32> = Saturating(0u32); + let string: String = String::new(); + let wrapping: Wrapping<u32> = Wrapping(0u32); + + let inferred_saturating = saturating + saturating; + let inferred_string = string + ""; + let inferred_wrapping = wrapping + wrapping; + + let _ = inferred_saturating + inferred_saturating; + let _ = inferred_string + ""; + let _ = inferred_wrapping + inferred_wrapping; +} + +fn main() {} |
