-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Consider Result<T, Uninhabited> and ControlFlow<Uninhabited, T> to be equivalent to T for must use lint
#148214
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
base: main
Are you sure you want to change the base?
Conversation
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl LGTM
|
So, the lang team discussed this in the triage meeting today. Overall sentiment was positive that this is probably something we want to do at some point, but there was one concern: people may rely on this today to ensure that people "observe" the state of the fn foo<E>() -> Result<u32, E>; // people may expect that you will check the value of the `u32`I suggested that we could actually just get some real word data on this using crater. My thought was, we could do an experiment were we error on any function that (after monomorphization) returns I do expect that this will result in a non-small amount of cases, but I think it might be a small enough set that we could browse through and get a sense of if this type of thing is relied upon. Would you be interested in doing that experiment @WaffleLapkin? If not, I'm happy to help out and try that myself (or I can help if you do want to be involved). |
|
@jackh726 I'd be happy to do the experiment. I might reach out for some help though ^^' |
|
Sounds good! Let me know, happy to help if you run into issues. |
17a892b to
69a5724
Compare
This comment has been minimized.
This comment has been minimized.
|
Copying this from #148577 (comment) So, what's very clear is that this pattern comes in a lot of places. Definitely more than I would have expected coming into this. With this being said, I've gone through and opened a few crater results to see if I could spot any examples of @joshtriplett's concern, which was basically like "People may be relying on that So, going into this, I'm looking for types where the That being said, given that this comes up so much, I think this decision is likely not as "light" as the lang team originally expected. Though, it's completely backwards- and forwards- compatible to make this change and undo later. Here a couple of examples of code I saw, though far from exhaustive.
|
…use lint (or more accurately `Result<T, Uninhabited>`/`ControlFlow<Uninhabited, T>`). This generalizes a previous change where we only did this for `T = ()`.
|
Going to renominate for lang, since we got some crater results and worth discussing. |
|
@rfcbot fcp merge lang I think we should merge this, for a few reasons.
We talked about this in the lang call and some people brought up that returning For code that already returns @scottmcm noticed that today, clippy lints on the case where you do this: #[must_use]
fn foo() -> Result<i32, Uninhabited> { Ok(42) }However, that lint is only if the While I think we should tweak this clippy lint so it no longer fires on |
|
Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
I think we should merge this as well. I also think we need to decide on a transition plan. That transition plan could be anything from "loud release notes" to "new lint", though the latter would need some thought on how to mark functions you don't want to add Not filing this as a concern at this time, though. |
|
However, one thing I will go ahead and file a concern on: today, if you try to add @rfcbot concern need-to-stop-warning-on-explicit-must_use-on-function-returning-Result-with-uninhabited |
|
@joshtriplett currently clippy re-implements the Footnotes
|
Don't we have many examples of violating this? One that comes to mind right away is making |
We generally try to make it so there's a 1-release transition window. We don't need to worry about years-old versions, but we generally don't want to say that people have to update immediately because both things happen at once. So for example, here we'd give people one release to add the function-level (Like how we stopped unneeded_unsafe warning on unsafe blocks in unsafe fn at least one release before insisting on them.) |
|
cc @rust-lang/clippy @rust-lang/clippy-contributors |
69a5724 to
426b4e8
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This is an extension to #147382.
With this PR
Result<T, Uninhabited>andControlFlow<Uninhabited, T>considered as must use iifTmust be used.For such cases the lint will mention that
Tis wrapped in aResult/ControlFlowwith an uninhabited error/break.The reasoning here is that
Result<T, Uninhabited>is equivalent toTin which values can be represented and thus the must-used-ness should also be equivalent.