summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed')
-rw-r--r--src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs123
-rw-r--r--src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr58
-rw-r--r--src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml12
3 files changed, 173 insertions, 20 deletions
diff --git a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
index e8a023ab1..fb5b1b193 100644
--- a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
+++ b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
@@ -2,32 +2,117 @@
use core::ops::{Add, Neg};
-#[derive(Clone, Copy)]
-struct Point {
- x: i32,
- y: i32,
+macro_rules! create {
+ ($name:ident) => {
+ #[allow(clippy::arithmetic_side_effects)]
+ #[derive(Clone, Copy)]
+ struct $name;
+
+ impl Add<$name> for $name {
+ type Output = $name;
+ fn add(self, other: $name) -> Self::Output {
+ todo!()
+ }
+ }
+
+ impl Add<i32> for $name {
+ type Output = $name;
+ fn add(self, other: i32) -> Self::Output {
+ todo!()
+ }
+ }
+
+ impl Add<$name> for i32 {
+ type Output = $name;
+ fn add(self, other: $name) -> Self::Output {
+ todo!()
+ }
+ }
+
+ impl Add<i64> for $name {
+ type Output = $name;
+ fn add(self, other: i64) -> Self::Output {
+ todo!()
+ }
+ }
+
+ impl Add<$name> for i64 {
+ type Output = $name;
+ fn add(self, other: $name) -> Self::Output {
+ todo!()
+ }
+ }
+
+ impl Neg for $name {
+ type Output = $name;
+ fn neg(self) -> Self::Output {
+ todo!()
+ }
+ }
+ };
}
-impl Add for Point {
- type Output = Self;
+create!(Foo);
+create!(Bar);
+create!(Baz);
+create!(OutOfNames);
- fn add(self, other: Self) -> Self {
- todo!()
- }
+fn lhs_and_rhs_are_equal() {
+ // is explicitly on the list
+ let _ = OutOfNames + OutOfNames;
+ // is explicitly on the list
+ let _ = Foo + Foo;
+ // is implicitly on the list
+ let _ = Bar + Bar;
+ // not on the list
+ let _ = Baz + Baz;
}
-impl Neg for Point {
- type Output = Self;
+fn lhs_is_different() {
+ // is explicitly on the list
+ let _ = 1i32 + OutOfNames;
+ // is explicitly on the list
+ let _ = 1i32 + Foo;
+ // is implicitly on the list
+ let _ = 1i32 + Bar;
+ // not on the list
+ let _ = 1i32 + Baz;
- fn neg(self) -> Self::Output {
- todo!()
- }
+ // not on the list
+ let _ = 1i64 + Foo;
+ // is implicitly on the list
+ let _ = 1i64 + Bar;
+ // not on the list
+ let _ = 1i64 + Baz;
}
-fn main() {
- let _ = Point { x: 1, y: 0 } + Point { x: 2, y: 3 };
+fn rhs_is_different() {
+ // is explicitly on the list
+ let _ = OutOfNames + 1i32;
+ // is explicitly on the list
+ let _ = Foo + 1i32;
+ // is implicitly on the list
+ let _ = Bar + 1i32;
+ // not on the list
+ let _ = Baz + 1i32;
+
+ // not on the list
+ let _ = Foo + 1i64;
+ // is implicitly on the list
+ let _ = Bar + 1i64;
+ // not on the list
+ let _ = Baz + 1i64;
+}
- let point: Point = Point { x: 1, y: 0 };
- let _ = point + point;
- let _ = -point;
+fn unary() {
+ // is explicitly on the list
+ let _ = -OutOfNames;
+ // is explicitly on the list
+ let _ = -Foo;
+ // not on the list
+ let _ = -Bar;
+ // not on the list
+ let _ = -Baz;
}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr
new file mode 100644
index 000000000..ad89534aa
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr
@@ -0,0 +1,58 @@
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:68:13
+ |
+LL | let _ = Baz + Baz;
+ | ^^^^^^^^^
+ |
+ = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:79:13
+ |
+LL | let _ = 1i32 + Baz;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:82:13
+ |
+LL | let _ = 1i64 + Foo;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:86:13
+ |
+LL | let _ = 1i64 + Baz;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:97:13
+ |
+LL | let _ = Baz + 1i32;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:100:13
+ |
+LL | let _ = Foo + 1i64;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:104:13
+ |
+LL | let _ = Baz + 1i64;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:113:13
+ |
+LL | let _ = -Bar;
+ | ^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects_allowed.rs:115:13
+ |
+LL | let _ = -Baz;
+ | ^^^^
+
+error: aborting due to 9 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml
index e736256f2..89cbea7ec 100644
--- a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml
+++ b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/clippy.toml
@@ -1 +1,11 @@
-arithmetic-side-effects-allowed = ["Point"]
+arithmetic-side-effects-allowed = [
+ "OutOfNames"
+]
+arithmetic-side-effects-allowed-binary = [
+ ["Foo", "Foo"],
+ ["Foo", "i32"],
+ ["i32", "Foo"],
+ ["Bar", "*"],
+ ["*", "Bar"],
+]
+arithmetic-side-effects-allowed-unary = ["Foo"]