diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /tests/ui/lint/unused | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/lint/unused')
-rw-r--r-- | tests/ui/lint/unused/issue-103320-must-use-ops.rs | 27 | ||||
-rw-r--r-- | tests/ui/lint/unused/issue-103320-must-use-ops.stderr | 67 | ||||
-rw-r--r-- | tests/ui/lint/unused/issue-96606.rs | 8 | ||||
-rw-r--r-- | tests/ui/lint/unused/issue-96606.stderr | 33 |
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 + |