Add #[must_use] annotation to Result::ok#139138
Add #[must_use] annotation to Result::ok#139138yotamofek wants to merge 2 commits intorust-lang:masterfrom
#[must_use] annotation to Result::ok#139138Conversation
This comment has been minimized.
This comment has been minimized.
b2063bd to
948d606
Compare
|
It is a fairly common pattern to write |
|
If this is a hill you're willing to die on, it would probably make sense to nominate this for libs api team discussion on whether this should be done or not. |
|
I'm willing to climb the hill and quickly run back down if I find people are trying to kill me. 😬 |
948d606 to
ac11f8f
Compare
|
The Miri subtree was changed cc @rust-lang/miri |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
You can use |
|
An alternative would be a clippy lint, right? |
|
Personally I often use But I'll accept whatever t-libs-api says about the preferred style here, this is not a strong opinion. |
When reading code, I didn't understand that I think it doesn't make sense to use a relatively unrelated method on |
https://rust-lang.github.io/rust-clippy/rust-1.85.0/index.html#unused_result_ok |
|
After thinking about this a bit more, I'm reluctant to actually nominate this for libs team consideration. I think that even if 100% of people disliked the use of Also, the clippy lint is really a good enough solution for me personally. Closing this PR for now. (Edit: though I still prefer |
I've encountered a few instances of people (@ work) writing these types of snippets:
IMHO the idiomatic way to write this would be:
or, if you're just discarding the error and don't need to log it
I think using
.ok()for discarding an error is misleading and makes the code harder to read. I wouldn't propose adding#[must_use]toOptionitself (as opposed toResult) is wrong, but it makes a lot of sense to me that.ok()is missing its purpose if you're not using its return value!Let's see what people feel about this...
(Edit: fixes #66116 , which I missed before opening this)