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/auxiliary/must-use-foreign.rs12
-rw-r--r--tests/ui/lint/unused/must-use-box-from-raw.stderr4
-rw-r--r--tests/ui/lint/unused/must-use-foreign.rs15
-rw-r--r--tests/ui/lint/unused/must_use-unit.stderr9
-rw-r--r--tests/ui/lint/unused/trait-alias-supertrait.rs15
-rw-r--r--tests/ui/lint/unused/unused-allocation.rs7
-rw-r--r--tests/ui/lint/unused/unused-allocation.stderr20
-rw-r--r--tests/ui/lint/unused/unused-async.rs2
-rw-r--r--tests/ui/lint/unused/unused-async.stderr21
-rw-r--r--tests/ui/lint/unused/unused-result.stderr17
-rw-r--r--tests/ui/lint/unused/unused_attributes-must_use.stderr34
11 files changed, 149 insertions, 7 deletions
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<Output = ()>) {
+ (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<T> = Sized where T: Iterator;
+
+fn test<T: Iterator>() -> impl Foo<T> {}
+
+fn main() {
+ test::<std::iter::Once<()>>();
+}
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::<MustUse>();
+ | +++++++
error: unused `MustUseMsg` that must be used
--> $DIR/unused-result.rs:22:5
@@ -17,6 +21,10 @@ LL | foo::<MustUseMsg>();
| ^^^^^^^^^^^^^^^^^^^
|
= note: some message
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = foo::<MustUseMsg>();
+ | +++++++
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::<MustUse>();
| ^^^^^^^^^^^^^^^^
+ |
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = foo::<MustUse>();
+ | +++++++
error: unused `MustUseMsg` that must be used
--> $DIR/unused-result.rs:36:5
@@ -43,6 +56,10 @@ LL | foo::<MustUseMsg>();
| ^^^^^^^^^^^^^^^^^^^
|
= note: some message
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = foo::<MustUseMsg>();
+ | +++++++
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