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

Inaccuracy in the documentation for Option::unwrap_or_default #100054

Closed
moenie99 opened this issue Aug 2, 2022 · 4 comments · Fixed by #102283
Closed

Inaccuracy in the documentation for Option::unwrap_or_default #100054

moenie99 opened this issue Aug 2, 2022 · 4 comments · Fixed by #102283
Assignees
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@moenie99
Copy link

moenie99 commented Aug 2, 2022

Location

https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or_default

Summary

It appears that the example was wrongly adapted from Result::unwrap_or_default, however the example does not work here because parse will never return None, its returns a Result. It appears that ideally a more fitting example should be written.

@moenie99 moenie99 added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Aug 2, 2022
@gimbling-away
Copy link
Contributor

The documentation seems alright? Yes, parse returns a Result -- The example is calling Result::ok to convert Result<T> to Option<T> and then using Option::unwrap_or_default.

@ArtifyCZ
Copy link

ArtifyCZ commented Aug 5, 2022

I think there could be for people like this (no offensive) type annotations.

@GuillaumeGomez
Copy link
Member

The example could be simplified indeed.

@gimbling-away
Copy link
Contributor

@rustbot claim

fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Sep 25, 2022
Type-annotate and simplify documentation of Option::unwrap_or_default

Part of rust-lang#100054
notriddle added a commit to notriddle/rust that referenced this issue Sep 26, 2022
…-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`
notriddle added a commit to notriddle/rust that referenced this issue Sep 26, 2022
…-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``
@bors bors closed this as completed in f3a6fbf Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants