From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/lint/unused/auxiliary/must-use-foreign.rs | 12 ++++++++ tests/ui/lint/unused/must-use-box-from-raw.stderr | 4 +++ tests/ui/lint/unused/must-use-foreign.rs | 15 ++++++++++ tests/ui/lint/unused/must_use-unit.stderr | 9 ++++++ tests/ui/lint/unused/trait-alias-supertrait.rs | 15 ++++++++++ tests/ui/lint/unused/unused-allocation.rs | 7 +++++ tests/ui/lint/unused/unused-allocation.stderr | 20 +++++++++++++ tests/ui/lint/unused/unused-async.rs | 2 +- tests/ui/lint/unused/unused-async.stderr | 21 +++++++++---- tests/ui/lint/unused/unused-result.stderr | 17 +++++++++++ .../lint/unused/unused_attributes-must_use.stderr | 34 ++++++++++++++++++++++ 11 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 tests/ui/lint/unused/auxiliary/must-use-foreign.rs create mode 100644 tests/ui/lint/unused/must-use-foreign.rs create mode 100644 tests/ui/lint/unused/trait-alias-supertrait.rs create mode 100644 tests/ui/lint/unused/unused-allocation.rs create mode 100644 tests/ui/lint/unused/unused-allocation.stderr (limited to 'tests/ui/lint/unused') diff --git a/tests/ui/lint/unused/auxiliary/must-use-foreign.rs b/tests/ui/lint/unused/auxiliary/must-use-foreign.rs new file mode 100644 index 000000000..f773f09c3 --- /dev/null +++ b/tests/ui/lint/unused/auxiliary/must-use-foreign.rs @@ -0,0 +1,12 @@ +// edition:2021 + +use std::future::Future; + +pub struct Manager; + +impl Manager { + #[must_use] + pub async fn new() -> (Self, impl Future) { + (Manager, async {}) + } +} diff --git a/tests/ui/lint/unused/must-use-box-from-raw.stderr b/tests/ui/lint/unused/must-use-box-from-raw.stderr index 47ab613be..4898db7fe 100644 --- a/tests/ui/lint/unused/must-use-box-from-raw.stderr +++ b/tests/ui/lint/unused/must-use-box-from-raw.stderr @@ -10,6 +10,10 @@ note: the lint level is defined here | LL | #![warn(unused_must_use)] | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = Box::from_raw(ptr); + | +++++++ warning: 1 warning emitted diff --git a/tests/ui/lint/unused/must-use-foreign.rs b/tests/ui/lint/unused/must-use-foreign.rs new file mode 100644 index 000000000..21a110585 --- /dev/null +++ b/tests/ui/lint/unused/must-use-foreign.rs @@ -0,0 +1,15 @@ +// edition:2021 +// aux-build:must-use-foreign.rs +// check-pass + +extern crate must_use_foreign; + +use must_use_foreign::Manager; + +async fn async_main() { + Manager::new().await.1.await; +} + +fn main() { + let _ = async_main(); +} diff --git a/tests/ui/lint/unused/must_use-unit.stderr b/tests/ui/lint/unused/must_use-unit.stderr index 9fcbc5074..993a19e5f 100644 --- a/tests/ui/lint/unused/must_use-unit.stderr +++ b/tests/ui/lint/unused/must_use-unit.stderr @@ -9,12 +9,21 @@ note: the lint level is defined here | LL | #![deny(unused_must_use)] | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo(); + | +++++++ error: unused return value of `bar` that must be used --> $DIR/must_use-unit.rs:15:5 | LL | bar(); | ^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = bar(); + | +++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/lint/unused/trait-alias-supertrait.rs b/tests/ui/lint/unused/trait-alias-supertrait.rs new file mode 100644 index 000000000..46f00c06b --- /dev/null +++ b/tests/ui/lint/unused/trait-alias-supertrait.rs @@ -0,0 +1,15 @@ +// check-pass + +// Make sure that we only consider *Self* supertrait predicates +// in the `unused_must_use` lint. + +#![feature(trait_alias)] +#![deny(unused_must_use)] + +trait Foo = Sized where T: Iterator; + +fn test() -> impl Foo {} + +fn main() { + test::>(); +} diff --git a/tests/ui/lint/unused/unused-allocation.rs b/tests/ui/lint/unused/unused-allocation.rs new file mode 100644 index 000000000..c1a6f5cea --- /dev/null +++ b/tests/ui/lint/unused/unused-allocation.rs @@ -0,0 +1,7 @@ +#![feature(rustc_attrs, stmt_expr_attributes)] +#![deny(unused_allocation)] + +fn main() { + _ = (#[rustc_box] Box::new([1])).len(); //~ error: unnecessary allocation, use `&` instead + _ = Box::new([1]).len(); //~ error: unnecessary allocation, use `&` instead +} diff --git a/tests/ui/lint/unused/unused-allocation.stderr b/tests/ui/lint/unused/unused-allocation.stderr new file mode 100644 index 000000000..c9ccfbd30 --- /dev/null +++ b/tests/ui/lint/unused/unused-allocation.stderr @@ -0,0 +1,20 @@ +error: unnecessary allocation, use `&` instead + --> $DIR/unused-allocation.rs:5:9 + | +LL | _ = (#[rustc_box] Box::new([1])).len(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-allocation.rs:2:9 + | +LL | #![deny(unused_allocation)] + | ^^^^^^^^^^^^^^^^^ + +error: unnecessary allocation, use `&` instead + --> $DIR/unused-allocation.rs:6:9 + | +LL | _ = Box::new([1]).len(); + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lint/unused/unused-async.rs b/tests/ui/lint/unused/unused-async.rs index 4be93aa15..6355f47f0 100644 --- a/tests/ui/lint/unused/unused-async.rs +++ b/tests/ui/lint/unused/unused-async.rs @@ -33,7 +33,7 @@ async fn test() { foo().await; //~ ERROR unused output of future returned by `foo` that must be used bar(); //~ ERROR unused return value of `bar` that must be used //~^ ERROR unused implementer of `Future` that must be used - bar().await; //~ ERROR unused output of future returned by `bar` that must be used + bar().await; // ok, it's not an async fn baz(); //~ ERROR unused implementer of `Future` that must be used baz().await; // ok } diff --git a/tests/ui/lint/unused/unused-async.stderr b/tests/ui/lint/unused/unused-async.stderr index 4bcb26dc1..e93a40658 100644 --- a/tests/ui/lint/unused/unused-async.stderr +++ b/tests/ui/lint/unused/unused-async.stderr @@ -16,12 +16,22 @@ error: unused return value of `foo` that must be used | LL | foo(); | ^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo(); + | +++++++ error: unused output of future returned by `foo` that must be used --> $DIR/unused-async.rs:33:5 | LL | foo().await; | ^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo().await; + | +++++++ error: unused implementer of `Future` that must be used --> $DIR/unused-async.rs:34:5 @@ -36,12 +46,11 @@ error: unused return value of `bar` that must be used | LL | bar(); | ^^^^^ - -error: unused output of future returned by `bar` that must be used - --> $DIR/unused-async.rs:36:5 | -LL | bar().await; - | ^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = bar(); + | +++++++ error: unused implementer of `Future` that must be used --> $DIR/unused-async.rs:37:5 @@ -51,5 +60,5 @@ LL | baz(); | = note: futures do nothing unless you `.await` or poll them -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/lint/unused/unused-result.stderr b/tests/ui/lint/unused/unused-result.stderr index 4e1ba1fd9..f42995a65 100644 --- a/tests/ui/lint/unused/unused-result.stderr +++ b/tests/ui/lint/unused/unused-result.stderr @@ -9,6 +9,10 @@ note: the lint level is defined here | LL | #![deny(unused_results, unused_must_use)] | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo::(); + | +++++++ error: unused `MustUseMsg` that must be used --> $DIR/unused-result.rs:22:5 @@ -17,6 +21,10 @@ LL | foo::(); | ^^^^^^^^^^^^^^^^^^^ | = note: some message +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo::(); + | +++++++ error: unused result of type `isize` --> $DIR/unused-result.rs:34:5 @@ -35,6 +43,11 @@ error: unused `MustUse` that must be used | LL | foo::(); | ^^^^^^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo::(); + | +++++++ error: unused `MustUseMsg` that must be used --> $DIR/unused-result.rs:36:5 @@ -43,6 +56,10 @@ LL | foo::(); | ^^^^^^^^^^^^^^^^^^^ | = note: some message +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo::(); + | +++++++ error: aborting due to 5 previous errors diff --git a/tests/ui/lint/unused/unused_attributes-must_use.stderr b/tests/ui/lint/unused/unused_attributes-must_use.stderr index 0f699429e..9633767c4 100644 --- a/tests/ui/lint/unused/unused_attributes-must_use.stderr +++ b/tests/ui/lint/unused/unused_attributes-must_use.stderr @@ -146,42 +146,76 @@ note: the lint level is defined here | LL | #![deny(unused_attributes, unused_must_use)] | ^^^^^^^^^^^^^^^ +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = X; + | +++++++ error: unused `Y` that must be used --> $DIR/unused_attributes-must_use.rs:104:5 | LL | Y::Z; | ^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = Y::Z; + | +++++++ error: unused `U` that must be used --> $DIR/unused_attributes-must_use.rs:105:5 | LL | U { unit: () }; | ^^^^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = U { unit: () }; + | +++++++ error: unused return value of `U::method` that must be used --> $DIR/unused_attributes-must_use.rs:106:5 | LL | U::method(); | ^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = U::method(); + | +++++++ error: unused return value of `foo` that must be used --> $DIR/unused_attributes-must_use.rs:107:5 | LL | foo(); | ^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foo(); + | +++++++ error: unused return value of `foreign_foo` that must be used --> $DIR/unused_attributes-must_use.rs:110:9 | LL | foreign_foo(); | ^^^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = foreign_foo(); + | +++++++ error: unused return value of `Use::get_four` that must be used --> $DIR/unused_attributes-must_use.rs:118:5 | LL | ().get_four(); | ^^^^^^^^^^^^^ + | +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = ().get_four(); + | +++++++ error: aborting due to 28 previous errors -- cgit v1.2.3