Skip to content
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

Mark Option::insert as must_use #87196

Merged
merged 1 commit into from
Jul 19, 2021
Merged

Conversation

oxalica
Copy link
Contributor

@oxalica oxalica commented Jul 16, 2021

Some people seems misled by the function name and use it in case where a simple assignment just works.
If the return value is not used, option = Some(value); should be preferred instead of option.insert(value);

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 16, 2021
@the8472
Copy link
Member

the8472 commented Jul 16, 2021

must_use seems to be used (hah) somewhat inconsistently. Most methods annotated with it indicate an outright programming error, e.g. ignoring results which likely indicate error states, lazy iterators or integer methods where the original isn't modified.

This on the other hand is merely a style thing where a method that expresses the intent better is available. But it isn't without precedent, e.g. mem::replace is annotated like that too.

But if this is added, then should Option::take (as = None) and Option::replace (similar to insert) be annotated too?

@camsteffen
Copy link
Contributor

Seems like a highly subjective style preference to me.

@joshtriplett
Copy link
Member

@the8472 Yes, both of those should be annotated as well.

@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 18, 2021

📌 Commit 774a79e has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 18, 2021
@bors
Copy link
Contributor

bors commented Jul 19, 2021

⌛ Testing commit 774a79e with merge 83f0822...

@bors
Copy link
Contributor

bors commented Jul 19, 2021

☀️ Test successful - checks-actions
Approved by: joshtriplett
Pushing 83f0822 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 19, 2021
@bors bors merged commit 83f0822 into rust-lang:master Jul 19, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 19, 2021
@oxalica oxalica deleted the option-insert-must-use branch July 19, 2021 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants