Skip to content

Commit 3161b2c

Browse files
committed
add must_use tests for Result<MustUse/Struct, !>
1 parent d78b71c commit 3161b2c

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

tests/ui/lint/unused/must_use-result-unit-uninhabited.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use core::ops::{ControlFlow, ControlFlow::Continue};
88
use dep::{MyUninhabited, MyUninhabitedNonexhaustive};
99

10+
#[must_use]
11+
struct MustUse;
12+
13+
struct Struct;
14+
1015
fn result_unit_unit() -> Result<(), ()> {
1116
Ok(())
1217
}
@@ -19,6 +24,14 @@ fn result_unit_never() -> Result<(), !> {
1924
Ok(())
2025
}
2126

27+
fn result_struct_never() -> Result<Struct, !> {
28+
Ok(Struct)
29+
}
30+
31+
fn result_must_use_never() -> Result<MustUse, !> {
32+
Ok(MustUse)
33+
}
34+
2235
fn result_unit_myuninhabited() -> Result<(), MyUninhabited> {
2336
Ok(())
2437
}
@@ -80,6 +93,8 @@ fn main() {
8093
result_unit_unit(); //~ ERROR: unused `Result` that must be used
8194
result_unit_infallible();
8295
result_unit_never();
96+
result_must_use_never(); //~ ERROR: unused `Result` that must be used
97+
result_struct_never(); //~ ERROR: unused `Result` that must be used
8398
result_unit_myuninhabited();
8499
result_unit_myuninhabited_nonexhaustive(); //~ ERROR: unused `Result` that must be used
85100
result_unit_assoctype(S1);

tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unused `Result` that must be used
2-
--> $DIR/must_use-result-unit-uninhabited.rs:80:5
2+
--> $DIR/must_use-result-unit-uninhabited.rs:93:5
33
|
44
LL | result_unit_unit();
55
| ^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,31 @@ LL | let _ = result_unit_unit();
1616
| +++++++
1717

1818
error: unused `Result` that must be used
19-
--> $DIR/must_use-result-unit-uninhabited.rs:84:5
19+
--> $DIR/must_use-result-unit-uninhabited.rs:96:5
20+
|
21+
LL | result_must_use_never();
22+
| ^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= note: this `Result` may be an `Err` variant, which should be handled
25+
help: use `let _ = ...` to ignore the resulting value
26+
|
27+
LL | let _ = result_must_use_never();
28+
| +++++++
29+
30+
error: unused `Result` that must be used
31+
--> $DIR/must_use-result-unit-uninhabited.rs:97:5
32+
|
33+
LL | result_struct_never();
34+
| ^^^^^^^^^^^^^^^^^^^^^
35+
|
36+
= note: this `Result` may be an `Err` variant, which should be handled
37+
help: use `let _ = ...` to ignore the resulting value
38+
|
39+
LL | let _ = result_struct_never();
40+
| +++++++
41+
42+
error: unused `Result` that must be used
43+
--> $DIR/must_use-result-unit-uninhabited.rs:99:5
2044
|
2145
LL | result_unit_myuninhabited_nonexhaustive();
2246
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,7 +52,7 @@ LL | let _ = result_unit_myuninhabited_nonexhaustive();
2852
| +++++++
2953

3054
error: unused `Result` that must be used
31-
--> $DIR/must_use-result-unit-uninhabited.rs:86:5
55+
--> $DIR/must_use-result-unit-uninhabited.rs:101:5
3256
|
3357
LL | result_unit_assoctype(S2);
3458
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +64,7 @@ LL | let _ = result_unit_assoctype(S2);
4064
| +++++++
4165

4266
error: unused `Result` that must be used
43-
--> $DIR/must_use-result-unit-uninhabited.rs:88:5
67+
--> $DIR/must_use-result-unit-uninhabited.rs:103:5
4468
|
4569
LL | S2.method_use_assoc_type();
4670
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -52,7 +76,7 @@ LL | let _ = S2.method_use_assoc_type();
5276
| +++++++
5377

5478
error: unused `ControlFlow` that must be used
55-
--> $DIR/must_use-result-unit-uninhabited.rs:90:5
79+
--> $DIR/must_use-result-unit-uninhabited.rs:105:5
5680
|
5781
LL | controlflow_unit();
5882
| ^^^^^^^^^^^^^^^^^^
@@ -63,7 +87,7 @@ LL | let _ = controlflow_unit();
6387
| +++++++
6488

6589
error: unused `Result` that must be used
66-
--> $DIR/must_use-result-unit-uninhabited.rs:99:9
90+
--> $DIR/must_use-result-unit-uninhabited.rs:114:9
6791
|
6892
LL | self.generate();
6993
| ^^^^^^^^^^^^^^^
@@ -74,5 +98,5 @@ help: use `let _ = ...` to ignore the resulting value
7498
LL | let _ = self.generate();
7599
| +++++++
76100

77-
error: aborting due to 6 previous errors
101+
error: aborting due to 8 previous errors
78102

0 commit comments

Comments
 (0)