Skip to content

Commit d9d6c49

Browse files
committed
unused_must_use: Add test for a method using an associated error type
1 parent 78582a1 commit d9d6c49

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ fn f6<AT: AssocType>(_: AT) -> Result<(), AT::Error> {
4444
Ok(())
4545
}
4646

47+
trait UsesAssocType {
48+
type Error;
49+
fn method(&self) -> Result<(), Self::Error>;
50+
}
51+
52+
impl UsesAssocType for S1 {
53+
type Error = !;
54+
fn method(&self) -> Result<(), Self::Error> {
55+
Ok(())
56+
}
57+
}
58+
59+
impl UsesAssocType for S2 {
60+
type Error = ();
61+
fn method(&self) -> Result<(), Self::Error> {
62+
Err(())
63+
}
64+
}
65+
4766
fn main() {
4867
f1(); //~ ERROR: unused `Result` that must be used
4968
f2();
@@ -52,4 +71,6 @@ fn main() {
5271
f5(); //~ ERROR: unused `Result` that must be used
5372
f6(S1);
5473
f6(S2); //~ ERROR: unused `Result` that must be used
74+
S1.method();
75+
S2.method(); //~ ERROR: unused `Result` that must be used
5576
}

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

Lines changed: 16 additions & 4 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:48:5
2+
--> $DIR/must_use-result-unit-uninhabited.rs:67:5
33
|
44
LL | f1();
55
| ^^^^
@@ -16,7 +16,7 @@ LL | let _ = f1();
1616
| +++++++
1717

1818
error: unused `Result` that must be used
19-
--> $DIR/must_use-result-unit-uninhabited.rs:52:5
19+
--> $DIR/must_use-result-unit-uninhabited.rs:71:5
2020
|
2121
LL | f5();
2222
| ^^^^
@@ -28,7 +28,7 @@ LL | let _ = f5();
2828
| +++++++
2929

3030
error: unused `Result` that must be used
31-
--> $DIR/must_use-result-unit-uninhabited.rs:54:5
31+
--> $DIR/must_use-result-unit-uninhabited.rs:73:5
3232
|
3333
LL | f6(S2);
3434
| ^^^^^^
@@ -39,5 +39,17 @@ help: use `let _ = ...` to ignore the resulting value
3939
LL | let _ = f6(S2);
4040
| +++++++
4141

42-
error: aborting due to 3 previous errors
42+
error: unused `Result` that must be used
43+
--> $DIR/must_use-result-unit-uninhabited.rs:75:5
44+
|
45+
LL | S2.method();
46+
| ^^^^^^^^^^^
47+
|
48+
= note: this `Result` may be an `Err` variant, which should be handled
49+
help: use `let _ = ...` to ignore the resulting value
50+
|
51+
LL | let _ = S2.method();
52+
| +++++++
53+
54+
error: aborting due to 4 previous errors
4355

0 commit comments

Comments
 (0)