Skip to content

Commit e733667

Browse files
authored
Rollup merge of #37664 - est31:master, r=nrc
Document the question mark operator in reference and the book's syntax index The question mark operator will be stabilized for the Rust 1.13 release (unfortunately). Even though I don't like the operator, it still should be documented in the syntax index in the book and in the reference. Maybe there are people who also want to change the book's chapters on error handling, depending on their views of what idiomatic error handling is, now that the operator is stable, but I don't want to and I'd prefer to keep this PR focused on the reference and syntax index only. Please also apply this PR to the beta branch of rust.
2 parents 8cc6be1 + 1e9aad7 commit e733667

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/doc/book/syntax-index.md

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
* `|=` (`var |= expr`): bitwise or & assignment. Overloadable (`BitOrAssign`).
9595
* `||` (`expr || expr`): logical or.
9696
* `_`: "ignored" pattern binding (see [Patterns (Ignoring bindings)]). Also used to make integer-literals readable (see [Reference (Integer literals)]).
97+
* `?` (`expr?`): Error propagation. Returns early when `Err(_)` is encountered, unwraps otherwise. Similar to the [`try!` macro].
9798

9899
## Other Syntax
99100

@@ -210,6 +211,7 @@
210211
[Functions]: functions.html
211212
[Generics]: generics.html
212213
[Iterators]: iterators.html
214+
[`try!` macro]: error-handling.html#the-try-macro
213215
[Lifetimes]: lifetimes.html
214216
[Loops (`for`)]: loops.html#for
215217
[Loops (`loop`)]: loops.html#loop

src/doc/reference.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -2863,8 +2863,8 @@ assert_eq!(x, y);
28632863

28642864
### Unary operator expressions
28652865

2866-
Rust defines the following unary operators. They are all written as prefix operators,
2867-
before the expression they apply to.
2866+
Rust defines the following unary operators. With the exception of `?`, they are
2867+
all written as prefix operators, before the expression they apply to.
28682868

28692869
* `-`
28702870
: Negation. Signed integer types and floating-point types support negation. It
@@ -2893,6 +2893,10 @@ before the expression they apply to.
28932893
If the `&` or `&mut` operators are applied to an rvalue, a
28942894
temporary value is created; the lifetime of this temporary value
28952895
is defined by [syntactic rules](#temporary-lifetimes).
2896+
* `?`
2897+
: Propagating errors if applied to `Err(_)` and unwrapping if
2898+
applied to `Ok(_)`. Only works on the `Result<T, E>` type,
2899+
and written in postfix notation.
28962900

28972901
### Binary operator expressions
28982902

0 commit comments

Comments
 (0)