diff --git a/tests/ui/lint/unused/must_use-result-unit-uninhabited.rs b/tests/ui/lint/unused/must_use-result-unit-uninhabited.rs index 1a7facb91a9a..340e4abe0cdf 100644 --- a/tests/ui/lint/unused/must_use-result-unit-uninhabited.rs +++ b/tests/ui/lint/unused/must_use-result-unit-uninhabited.rs @@ -44,6 +44,25 @@ fn f6(_: 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 } diff --git a/tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr b/tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr index 0ee06b0504ad..8e1f300f6e7f 100644 --- a/tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr +++ b/tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr @@ -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