-
Notifications
You must be signed in to change notification settings - Fork 13.8k
unused_must_use: Don't warn on Result<(), Uninhabited>
or ControlFlow<Uninhabited, ()>
#147382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshtriplett
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
joshtriplett:unused-must-use-ignore-result-unit-uninhabited
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−7
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2997070
unused_must_use: Factor out a variable for the parent module DefId
joshtriplett f0b40f5
unused_must_use: Don't warn on `Result<(), Uninhabited>`
joshtriplett 049b0ba
unused_must_use: Add test for a method using an associated error type
joshtriplett 23a0751
unused_must_use: Suppress warnings for `ControlFlow<Uninhabited, ()>`…
joshtriplett bb8657e
unused_must_use: Rename test functions to reflect what they test
joshtriplett f4ca5fb
unused_must_use: Add extra test for types that are still generic
niacdoial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/ui/lint/unused/auxiliary/must_use_result_unit_uninhabited_extern_crate.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub enum MyUninhabited {} | ||
|
||
#[non_exhaustive] | ||
pub enum MyUninhabitedNonexhaustive {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//@ edition: 2024 | ||
//@ aux-crate:dep=must_use_result_unit_uninhabited_extern_crate.rs | ||
|
||
#![deny(unused_must_use)] | ||
#![feature(never_type)] | ||
|
||
use core::ops::{ControlFlow, ControlFlow::Continue}; | ||
use dep::{MyUninhabited, MyUninhabitedNonexhaustive}; | ||
|
||
fn f1() -> Result<(), ()> { | ||
Ok(()) | ||
} | ||
|
||
fn f2() -> Result<(), core::convert::Infallible> { | ||
Ok(()) | ||
} | ||
|
||
fn f3() -> Result<(), !> { | ||
Ok(()) | ||
} | ||
|
||
fn f4() -> Result<(), MyUninhabited> { | ||
Ok(()) | ||
} | ||
|
||
fn f5() -> Result<(), MyUninhabitedNonexhaustive> { | ||
Ok(()) | ||
} | ||
|
||
trait AssocType { | ||
type Error; | ||
} | ||
|
||
struct S1; | ||
impl AssocType for S1 { | ||
type Error = !; | ||
} | ||
|
||
struct S2; | ||
impl AssocType for S2 { | ||
type Error = (); | ||
} | ||
|
||
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 c1() -> ControlFlow<()> { | ||
Continue(()) | ||
} | ||
|
||
fn c2() -> ControlFlow<core::convert::Infallible, ()> { | ||
Continue(()) | ||
} | ||
|
||
fn c3() -> ControlFlow<!> { | ||
Continue(()) | ||
} | ||
|
||
fn main() { | ||
f1(); //~ ERROR: unused `Result` that must be used | ||
f2(); | ||
f3(); | ||
f4(); | ||
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 | ||
|
||
c1(); //~ ERROR: unused `ControlFlow` that must be used | ||
c2(); | ||
c3(); | ||
} |
66 changes: 66 additions & 0 deletions
66
tests/ui/lint/unused/must_use-result-unit-uninhabited.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
error: unused `Result` that must be used | ||
--> $DIR/must_use-result-unit-uninhabited.rs:80:5 | ||
| | ||
LL | f1(); | ||
| ^^^^ | ||
| | ||
= note: this `Result` may be an `Err` variant, which should be handled | ||
note: the lint level is defined here | ||
--> $DIR/must_use-result-unit-uninhabited.rs:4:9 | ||
| | ||
LL | #![deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ | ||
help: use `let _ = ...` to ignore the resulting value | ||
| | ||
LL | let _ = f1(); | ||
| +++++++ | ||
|
||
error: unused `Result` that must be used | ||
--> $DIR/must_use-result-unit-uninhabited.rs:84:5 | ||
| | ||
LL | f5(); | ||
| ^^^^ | ||
| | ||
= note: this `Result` may be an `Err` variant, which should be handled | ||
help: use `let _ = ...` to ignore the resulting value | ||
| | ||
LL | let _ = f5(); | ||
| +++++++ | ||
|
||
error: unused `Result` that must be used | ||
--> $DIR/must_use-result-unit-uninhabited.rs:86:5 | ||
| | ||
LL | f6(S2); | ||
| ^^^^^^ | ||
| | ||
= note: this `Result` may be an `Err` variant, which should be handled | ||
help: use `let _ = ...` to ignore the resulting value | ||
| | ||
LL | let _ = f6(S2); | ||
| +++++++ | ||
|
||
error: unused `Result` that must be used | ||
--> $DIR/must_use-result-unit-uninhabited.rs:88: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: unused `ControlFlow` that must be used | ||
--> $DIR/must_use-result-unit-uninhabited.rs:90:5 | ||
| | ||
LL | c1(); | ||
| ^^^^ | ||
| | ||
help: use `let _ = ...` to ignore the resulting value | ||
| | ||
LL | let _ = c1(); | ||
| +++++++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.