diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/lint/unused | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+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/lint-unused-extern-crate.rs | 2 | ||||
-rw-r--r-- | tests/ui/lint/unused/lint-unused-imports.rs | 2 | ||||
-rw-r--r-- | tests/ui/lint/unused/lint-unused-variables.rs | 4 | ||||
-rw-r--r-- | tests/ui/lint/unused/must-use-block-expr.fixed | 36 | ||||
-rw-r--r-- | tests/ui/lint/unused/must-use-block-expr.rs | 36 | ||||
-rw-r--r-- | tests/ui/lint/unused/must-use-block-expr.stderr | 51 |
6 files changed, 127 insertions, 4 deletions
diff --git a/tests/ui/lint/unused/lint-unused-extern-crate.rs b/tests/ui/lint/unused/lint-unused-extern-crate.rs index d5e4da526..79df58b70 100644 --- a/tests/ui/lint/unused/lint-unused-extern-crate.rs +++ b/tests/ui/lint/unused/lint-unused-extern-crate.rs @@ -31,5 +31,5 @@ mod foo { fn main() { lint_unused_extern_crate3::foo(); - let y = foo(); + foo(); } diff --git a/tests/ui/lint/unused/lint-unused-imports.rs b/tests/ui/lint/unused/lint-unused-imports.rs index 4754d8880..953992ecf 100644 --- a/tests/ui/lint/unused/lint-unused-imports.rs +++ b/tests/ui/lint/unused/lint-unused-imports.rs @@ -86,5 +86,5 @@ fn main() { let mut b = 4; swap(&mut a, &mut b); test::C.b(); - let _a = foo(); + foo(); } diff --git a/tests/ui/lint/unused/lint-unused-variables.rs b/tests/ui/lint/unused/lint-unused-variables.rs index 6850e9992..621c6ef84 100644 --- a/tests/ui/lint/unused/lint-unused-variables.rs +++ b/tests/ui/lint/unused/lint-unused-variables.rs @@ -74,6 +74,6 @@ fn main() { b: i32, //~^ ERROR unused variable: `b` | {}; - let _ = a(1, 2); - let _ = b(1, 2); + a(1, 2); + b(1, 2); } diff --git a/tests/ui/lint/unused/must-use-block-expr.fixed b/tests/ui/lint/unused/must-use-block-expr.fixed new file mode 100644 index 000000000..642012812 --- /dev/null +++ b/tests/ui/lint/unused/must-use-block-expr.fixed @@ -0,0 +1,36 @@ +// run-rustfix +// check-pass + +#![warn(unused_must_use)] + +#[must_use] +fn foo() -> i32 { + 42 +} + +fn bar() { + { + let _ = foo(); + //~^ WARN unused return value + } +} + +fn baz() { + { + let _ = foo(); + //~^ WARN unused return value + }; +} + +fn main() { + bar(); + baz(); + { + let _ = 1 + 2; + //~^ WARN unused arithmetic operation + } + { + let _ = 1 + 2; + //~^ WARN unused arithmetic operation + }; +} diff --git a/tests/ui/lint/unused/must-use-block-expr.rs b/tests/ui/lint/unused/must-use-block-expr.rs new file mode 100644 index 000000000..e0a680aa0 --- /dev/null +++ b/tests/ui/lint/unused/must-use-block-expr.rs @@ -0,0 +1,36 @@ +// run-rustfix +// check-pass + +#![warn(unused_must_use)] + +#[must_use] +fn foo() -> i32 { + 42 +} + +fn bar() { + { + foo(); + //~^ WARN unused return value + } +} + +fn baz() { + { + foo() + //~^ WARN unused return value + }; +} + +fn main() { + bar(); + baz(); + { + 1 + 2; + //~^ WARN unused arithmetic operation + } + { + 1 + 2 + //~^ WARN unused arithmetic operation + }; +} diff --git a/tests/ui/lint/unused/must-use-block-expr.stderr b/tests/ui/lint/unused/must-use-block-expr.stderr new file mode 100644 index 000000000..d821beb1d --- /dev/null +++ b/tests/ui/lint/unused/must-use-block-expr.stderr @@ -0,0 +1,51 @@ +warning: unused return value of `foo` that must be used + --> $DIR/must-use-block-expr.rs:13:9 + | +LL | foo(); + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/must-use-block-expr.rs:4:9 + | +LL | #![warn(unused_must_use)] + | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo(); + | +++++++ + +warning: unused return value of `foo` that must be used + --> $DIR/must-use-block-expr.rs:20:9 + | +LL | foo() + | ^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo(); + | +++++++ + + +warning: unused arithmetic operation that must be used + --> $DIR/must-use-block-expr.rs:29:9 + | +LL | 1 + 2; + | ^^^^^ the arithmetic operation produces a value + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = 1 + 2; + | +++++++ + +warning: unused arithmetic operation that must be used + --> $DIR/must-use-block-expr.rs:33:9 + | +LL | 1 + 2 + | ^^^^^ the arithmetic operation produces a value + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = 1 + 2; + | +++++++ + + +warning: 4 warnings emitted + |