未验证 提交 d06abdbf 编写于 作者: K kennytm 提交者: GitHub

Rollup merge of #49446 - frewsxcv:frewsxcv-mention-optiono, r=GuillaumeGomez

Explicitly mention `Option` in `?` error message.

Save users the time/effort of having to lookup what types implement
the `Try` trait.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
any(from_method="from_error", from_method="from_ok"), any(from_method="from_error", from_method="from_ok"),
from_desugaring="?"), from_desugaring="?"),
message="the `?` operator can only be used in a \ message="the `?` operator can only be used in a \
function that returns `Result` \ function that returns `Result` or `Option` \
(or another type that implements `{Try}`)", (or another type that implements `{Try}`)",
label="cannot use the `?` operator in a function that returns `{Self}`"), label="cannot use the `?` operator in a function that returns `{Self}`"),
on(all(from_method="into_result", from_desugaring="?"), on(all(from_method="into_result", from_desugaring="?"),
......
...@@ -6,7 +6,7 @@ LL | x?; //~ the trait bound ...@@ -6,7 +6,7 @@ LL | x?; //~ the trait bound
| |
= note: required by `std::convert::From::from` = note: required by `std::convert::From::from`
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`) error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> $DIR/try-on-option.rs:23:5 --> $DIR/try-on-option.rs:23:5
| |
LL | x?; //~ the `?` operator LL | x?; //~ the `?` operator
......
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`) error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> $DIR/try-operator-on-main.rs:19:5 --> $DIR/try-operator-on-main.rs:19:5
| |
LL | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only LL | std::fs::File::open("foo")?; //~ ERROR the `?` operator can only
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册