summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/unused
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/lint/unused')
-rw-r--r--tests/ui/lint/unused/issue-103320-must-use-ops.rs27
-rw-r--r--tests/ui/lint/unused/issue-103320-must-use-ops.stderr67
-rw-r--r--tests/ui/lint/unused/issue-96606.rs8
-rw-r--r--tests/ui/lint/unused/issue-96606.stderr33
4 files changed, 135 insertions, 0 deletions
diff --git a/tests/ui/lint/unused/issue-103320-must-use-ops.rs b/tests/ui/lint/unused/issue-103320-must-use-ops.rs
new file mode 100644
index 000000000..597d312fa
--- /dev/null
+++ b/tests/ui/lint/unused/issue-103320-must-use-ops.rs
@@ -0,0 +1,27 @@
+// check-pass
+
+#![warn(unused_must_use)]
+#![feature(never_type)]
+
+use std::ops::Add;
+use std::ops::Sub;
+use std::ops::Mul;
+use std::ops::Div;
+use std::ops::Rem;
+
+fn main() {
+ let x = 2_u32;
+ (x.add(4), x.sub(4), x.mul(4), x.div(4), x.rem(4));
+
+ x.add(4); //~ WARN unused return value of `add` that must be used
+
+ x.sub(4); //~ WARN unused return value of `sub` that must be used
+
+ x.mul(4); //~ WARN unused return value of `mul` that must be used
+
+ x.div(4); //~ WARN unused return value of `div` that must be used
+
+ x.rem(4); //~ WARN unused return value of `rem` that must be used
+
+ println!("{}", x);
+}
diff --git a/tests/ui/lint/unused/issue-103320-must-use-ops.stderr b/tests/ui/lint/unused/issue-103320-must-use-ops.stderr
new file mode 100644
index 000000000..57439ec6a
--- /dev/null
+++ b/tests/ui/lint/unused/issue-103320-must-use-ops.stderr
@@ -0,0 +1,67 @@
+warning: unused return value of `add` that must be used
+ --> $DIR/issue-103320-must-use-ops.rs:16:5
+ |
+LL | x.add(4);
+ | ^^^^^^^^
+ |
+ = note: this returns the result of the operation, without modifying the original
+note: the lint level is defined here
+ --> $DIR/issue-103320-must-use-ops.rs:3:9
+ |
+LL | #![warn(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = x.add(4);
+ | +++++++
+
+warning: unused return value of `sub` that must be used
+ --> $DIR/issue-103320-must-use-ops.rs:18:5
+ |
+LL | x.sub(4);
+ | ^^^^^^^^
+ |
+ = note: this returns the result of the operation, without modifying the original
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = x.sub(4);
+ | +++++++
+
+warning: unused return value of `mul` that must be used
+ --> $DIR/issue-103320-must-use-ops.rs:20:5
+ |
+LL | x.mul(4);
+ | ^^^^^^^^
+ |
+ = note: this returns the result of the operation, without modifying the original
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = x.mul(4);
+ | +++++++
+
+warning: unused return value of `div` that must be used
+ --> $DIR/issue-103320-must-use-ops.rs:22:5
+ |
+LL | x.div(4);
+ | ^^^^^^^^
+ |
+ = note: this returns the result of the operation, without modifying the original
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = x.div(4);
+ | +++++++
+
+warning: unused return value of `rem` that must be used
+ --> $DIR/issue-103320-must-use-ops.rs:24:5
+ |
+LL | x.rem(4);
+ | ^^^^^^^^
+ |
+ = note: this returns the result of the operation, without modifying the original
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = x.rem(4);
+ | +++++++
+
+warning: 5 warnings emitted
+
diff --git a/tests/ui/lint/unused/issue-96606.rs b/tests/ui/lint/unused/issue-96606.rs
new file mode 100644
index 000000000..4e7c290fa
--- /dev/null
+++ b/tests/ui/lint/unused/issue-96606.rs
@@ -0,0 +1,8 @@
+#[deny(unused)]
+fn main() {
+ let arr = [0; 10];
+ let _ = arr[(0)]; //~ ERROR unnecessary parentheses around index expression
+ let _ = arr[{0}]; //~ ERROR unnecessary braces around index expression
+ let _ = arr[1 + (0)];
+ let _ = arr[{ let x = 0; x }];
+}
diff --git a/tests/ui/lint/unused/issue-96606.stderr b/tests/ui/lint/unused/issue-96606.stderr
new file mode 100644
index 000000000..e36277181
--- /dev/null
+++ b/tests/ui/lint/unused/issue-96606.stderr
@@ -0,0 +1,33 @@
+error: unnecessary parentheses around index expression
+ --> $DIR/issue-96606.rs:4:17
+ |
+LL | let _ = arr[(0)];
+ | ^ ^
+ |
+note: the lint level is defined here
+ --> $DIR/issue-96606.rs:1:8
+ |
+LL | #[deny(unused)]
+ | ^^^^^^
+ = note: `#[deny(unused_parens)]` implied by `#[deny(unused)]`
+help: remove these parentheses
+ |
+LL - let _ = arr[(0)];
+LL + let _ = arr[0];
+ |
+
+error: unnecessary braces around index expression
+ --> $DIR/issue-96606.rs:5:17
+ |
+LL | let _ = arr[{0}];
+ | ^ ^
+ |
+ = note: `#[deny(unused_braces)]` implied by `#[deny(unused)]`
+help: remove these braces
+ |
+LL - let _ = arr[{0}];
+LL + let _ = arr[0];
+ |
+
+error: aborting due to 2 previous errors
+