Skip to content

Inaccuracy in the documentation for Option::unwrap_or_default #100054

Closed
@moenie99

Description

@moenie99

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.

Activity

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Aug 2, 2022
ghost

ghost commented on Aug 2, 2022

@ghost

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

ArtifyCZ commented on Aug 5, 2022

@ArtifyCZ

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

GuillaumeGomez

GuillaumeGomez commented on Sep 25, 2022

@GuillaumeGomez
Member

The example could be simplified indeed.

ghost

ghost commented on Sep 25, 2022

@ghost

@rustbot claim

added a commit that references this issue on Sep 25, 2022

Rollup merge of rust-lang#102259 - gimbles:patch-1, r=joshtriplett

c50303c
added 2 commits that reference this issue on Sep 26, 2022

Rollup merge of rust-lang#102283 - GuillaumeGomez:option-code-example…

e096298

Rollup merge of rust-lang#102283 - GuillaumeGomez:option-code-example…

2668a68
added a commit that references this issue on Sep 26, 2022

Auto merge of rust-lang#102283 - GuillaumeGomez:option-code-example-u…

f3a6fbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @GuillaumeGomez@ArtifyCZ@moenie99

      Issue actions

        Inaccuracy in the documentation for Option::unwrap_or_default · Issue #100054 · rust-lang/rust