Skip to content

Commit 1f143bc

Browse files
committed
Explicitly mention Option in ? error message.
Save users the time/effort of having to lookup what types implement the `Try` trait.
1 parent e58df0d commit 1f143bc

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/libcore/ops/try.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
any(from_method="from_error", from_method="from_ok"),
2121
from_desugaring="?"),
2222
message="the `?` operator can only be used in a \
23-
function that returns `Result` \
23+
function that returns `Result` or `Option` \
2424
(or another type that implements `{Try}`)",
2525
label="cannot use the `?` operator in a function that returns `{Self}`"),
2626
on(all(from_method="into_result", from_desugaring="?"),

src/test/ui/suggestions/try-on-option.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | x?; //~ the trait bound
66
|
77
= note: required by `std::convert::From::from`
88

9-
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
9+
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
1010
--> $DIR/try-on-option.rs:23:5
1111
|
1212
LL | x?; //~ the `?` operator

src/test/ui/suggestions/try-operator-on-main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
1+
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
22
--> $DIR/try-operator-on-main.rs:19:5
33
|
44
LL | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only

0 commit comments

Comments
 (0)