-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add docs for question mark operator for Option #103644
Conversation
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. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Hi! Any updates on this PR? Is there something I need to do? |
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.
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
//! 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. |
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.
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.
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.
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.
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.
Yes indeed!
fa0a3d9
to
e0fd37d
Compare
Excellent! Thank you! @bors r+ |
…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
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.