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

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

Open
arienmalec opened this Issue Dec 11, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@arienmalec

arienmalec commented Dec 11, 2018

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.
@arienmalec

This comment has been minimized.

arienmalec commented Dec 20, 2018

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