Skip to content

Documentation for ? operator and Option does not mention that ? can be used with Option #1679

Closed

Description

@arienmalec

See the discussion in the following Reddit thread:

https://www.reddit.com/r/rust/comments/a4za5j/where_is_for_option_in_the_rfc_process/

Based on discussion, there is behavior released in Edition 2018 that is not documented in the Edition 2018 book, as well as behavior that is incorrectly documented:

  1. The Try trait and corresponding ? operator work with Option as well as with Result and the ? operator can return None to the surrounding function (if the return from that function is declared as Option<T> as well as Err (if the return is declared as Result).
  2. Section 9.3 incorrectly states : "The ? operator can only be used in functions that have a return type of Result, because it is defined to work in the same way as the match expression we defined in Listing 9-6."
  3. Section 6.3 should either document ? in an Option context or forward reference 9.3 (or a subsequent section) that documents ? in an Option context.

Activity

  1. arienmalec commented on Dec 20, 2018

    @arienmalec
    Author

    One more point:

    Documentation for ? chaining in an Option context should mention that as_ref can/should be used to avoid ? consuming the input.

    As an example:

    https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d6e33cb4a0b807ccb529cfa5d9c14a53

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions