diff options
author | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2023-06-11 23:44:28 +0800 |
---|---|---|
committer | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2023-06-15 17:59:13 +0800 |
commit | 72b3b58efc6ed4bab93ba98586b62750abbdda79 (patch) | |
tree | e69ee17e3d202a7a150e4e95c16c9bff6fe637bd /tests/ui/lint | |
parent | 314c39d2ea07d8b50649149358ebeb1a6bd09179 (diff) |
Extend `unused_must_use` to cover block exprs
Diffstat (limited to 'tests/ui/lint')
-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 |
3 files changed, 123 insertions, 0 deletions
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 00000000000..642012812bd --- /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 00000000000..e0a680aa07d --- /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 00000000000..d821beb1d92 --- /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 + |