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

Add docs for question mark operator for Option #103644

Merged
merged 2 commits into from
Dec 14, 2022

Conversation

catlee
Copy link
Contributor

@catlee catlee commented Oct 27, 2022

As a beginner learning rust, it took me a while to figure out what ? was doing with Options. I think the documentation of this could be improved.

I've used the question mark documentation from the Result type as a template here, and tried to come up with a simple example as well.

@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2022

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 27, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 27, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@catlee
Copy link
Contributor Author

catlee commented Nov 26, 2022

Hi!

Any updates on this PR? Is there something I need to do?

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks like an improvement overall! But there's some possible sharp edges to be mindful of in the wording.

library/core/src/option.rs Outdated Show resolved Hide resolved
Comment on lines 109 to 111
//! Ending the expression with [`?`] will result in the unwrapped
//! success ([`Some`]) value, unless the result is [`None`], in which case
//! [`None`] is returned early from the enclosing function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems slightly confusingly worded: it either evaluates to the inner value of Some(inner), or to return None;. I could easily see reading this and thinking it evaluates to Option::Some(inner), without unwrapping. In fact I thought that was what this meant at first glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this any better now?

//! Ending the expression with [`?`] will result in the [`Some`]'s unwrapped value, unless the
//! result is [`None`], in which case [`None`] is returned early from the enclosing function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed!

@workingjubilee
Copy link
Member

r? @workingjubilee

@catlee catlee force-pushed the catlee/option-question-mark-docs branch from fa0a3d9 to e0fd37d Compare December 13, 2022 19:49
@workingjubilee
Copy link
Member

Excellent! Thank you!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 14, 2022

📌 Commit e0fd37d has been approved by workingjubilee

It is now in the queue for this repository.

@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 Dec 14, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 14, 2022
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#103644 (Add docs for question mark operator for Option)
 - rust-lang#105161 (Refine when invalid prefix case error arises)
 - rust-lang#105491 (Illegal sized bounds: only suggest mutability change if needed)
 - rust-lang#105502 (Suggest impl in the scenario of typo with fn)
 - rust-lang#105523 (Suggest `collect`ing into `Vec<_>`)
 - rust-lang#105595 (Suggest dereferencing receiver arguments properly)
 - rust-lang#105611 (fold instead of obliterating args)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a270aee into rust-lang:master Dec 14, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants