add error message for the other case too

This commit is contained in:
Ariel Ben-Yehuda 2017-08-31 22:52:49 +03:00
parent efa09ea554
commit 291b4eddce
3 changed files with 13 additions and 6 deletions

View file

@ -27,7 +27,12 @@
message="the `?` operator can only be used in a \
function that returns `Result` \
(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="?"),
message="the `?` operator can only be applied to values \
that implement `{Try}`",
label="the `?` operator cannot be applied to type `{Self}`")
))]
pub trait Try {
/// The type of this value when viewed as successful.
#[unstable(feature = "try_trait", issue = "42327")]

View file

@ -16,7 +16,7 @@ fn main() {
// error for a `Try` type on a non-`Try` fn
std::fs::File::open("foo")?;
// a non-`Try` type on a `Try` fn
// a non-`Try` type on a non-`Try` fn
()?;
// an unrelated use of `Try`

View file

@ -10,15 +10,16 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::from_error`
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> $DIR/try-operator-on-main.rs:20:5
|
20 | ()?;
| ---
| |
| the trait `std::ops::Try` is not implemented for `()`
| the `?` operator cannot be applied to type `()`
| in this macro invocation
|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::into_result`
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
@ -29,15 +30,16 @@ error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
|
= note: required by `try_trait_generic`
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> $DIR/try-operator-on-main.rs:30:5
|
30 | ()?;
| ---
| |
| the trait `std::ops::Try` is not implemented for `()`
| the `?` operator cannot be applied to type `()`
| in this macro invocation
|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::into_result`
error: aborting due to 4 previous errors