-
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
Type-annotate and simplify documentation of Option::unwrap_or_default #102259
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
This is certainly an improvement, and I'm going to go ahead and merge it as such: @bors r+ rollup However, this also doesn't seem like a very good documentation example, given that Perhaps a better example would use an array and |
Wouldn't it be better instead to not need type annotation? For example: let x: Option<u32> = None;
let y: Option<u32> = Some(12);
assert_eq!(x.unwrap_or_default(), 0);
assert_eq!(12.unwrap_or_default(), 12); I find the usage of EDIT: After a refresh I saw @joshtriplett's comment and I guess we both agree. 😆 |
…fee1-dead Rollup of 8 pull requests Successful merges: - rust-lang#98111 (Clarify `[T]::select_nth_unstable*` return values) - rust-lang#101431 (Look at move place's type when suggesting mutable reborrow) - rust-lang#101800 (Constify slice.split_at_mut(_unchecked)) - rust-lang#101997 (Remove support for legacy PM) - rust-lang#102194 (Note the type when unable to drop values in compile time) - rust-lang#102200 (Constify Default impl's for Arrays and Tuples.) - rust-lang#102245 (Constify cmp_min_max_by.) - rust-lang#102259 (Type-annotate and simplify documentation of Option::unwrap_or_default) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
We can always add a better example later on =) |
Well, we could have done it correctly directly but it doesn't matter much. I'll just send a PR once this one is merged. |
I mean, I can probably extend this PR, right now :y |
It's about to get merged so better not. :) |
@gimbles Do you want to send a PR with the code I suggested instead? |
I opened #102283 as a follow-up. |
…-unwrap-or-default, r=thomcc Improve code example for Option::unwrap_or_default Fixes rust-lang#100054. Follow-up of rust-lang#102259. r? `@thomcc`
…-unwrap-or-default, r=thomcc Improve code example for Option::unwrap_or_default Fixes rust-lang#100054. Follow-up of rust-lang#102259. r? ``@thomcc``
…nwrap-or-default, r=thomcc Improve code example for Option::unwrap_or_default Fixes rust-lang#100054. Follow-up of rust-lang#102259. r? `@thomcc`
Part of #100054