unused_must_use: Add test for a method using an associated error type

This commit is contained in:
Josh Triplett
2025-10-05 10:45:16 -07:00
parent 6f89cecf37
commit efd76c910e
2 changed files with 37 additions and 4 deletions
@@ -44,6 +44,25 @@ fn f6<AT: AssocType>(_: AT) -> Result<(), AT::Error> {
Ok(())
}
trait UsesAssocType {
type Error;
fn method(&self) -> Result<(), Self::Error>;
}
impl UsesAssocType for S1 {
type Error = !;
fn method(&self) -> Result<(), Self::Error> {
Ok(())
}
}
impl UsesAssocType for S2 {
type Error = ();
fn method(&self) -> Result<(), Self::Error> {
Err(())
}
}
fn main() {
f1(); //~ ERROR: unused `Result` that must be used
f2();
@@ -52,4 +71,6 @@ fn main() {
f5(); //~ ERROR: unused `Result` that must be used
f6(S1);
f6(S2); //~ ERROR: unused `Result` that must be used
S1.method();
S2.method(); //~ ERROR: unused `Result` that must be used
}
@@ -1,5 +1,5 @@
error: unused `Result` that must be used
--> $DIR/must_use-result-unit-uninhabited.rs:48:5
--> $DIR/must_use-result-unit-uninhabited.rs:67:5
|
LL | f1();
| ^^^^
@@ -16,7 +16,7 @@ LL | let _ = f1();
| +++++++
error: unused `Result` that must be used
--> $DIR/must_use-result-unit-uninhabited.rs:52:5
--> $DIR/must_use-result-unit-uninhabited.rs:71:5
|
LL | f5();
| ^^^^
@@ -28,7 +28,7 @@ LL | let _ = f5();
| +++++++
error: unused `Result` that must be used
--> $DIR/must_use-result-unit-uninhabited.rs:54:5
--> $DIR/must_use-result-unit-uninhabited.rs:73:5
|
LL | f6(S2);
| ^^^^^^
@@ -39,5 +39,17 @@ help: use `let _ = ...` to ignore the resulting value
LL | let _ = f6(S2);
| +++++++
error: aborting due to 3 previous errors
error: unused `Result` that must be used
--> $DIR/must_use-result-unit-uninhabited.rs:75:5
|
LL | S2.method();
| ^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
help: use `let _ = ...` to ignore the resulting value
|
LL | let _ = S2.method();
| +++++++
error: aborting due to 4 previous errors