diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-08-31 22:52:49 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-09-03 13:10:54 +0300 |
| commit | 291b4eddcefd1d6da1010f8a1f02f05338a44050 (patch) | |
| tree | ba9a44f1e16425d7984a1e32bade04a6f23c3323 | |
| parent | efa09ea554575cd0b4ce01ada44fce730c0f7ac4 (diff) | |
| download | rust-291b4eddcefd1d6da1010f8a1f02f05338a44050.tar.gz rust-291b4eddcefd1d6da1010f8a1f02f05338a44050.zip | |
add error message for the other case too
| -rw-r--r-- | src/libcore/ops/try.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/suggestions/try-operator-on-main.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/suggestions/try-operator-on-main.stderr | 10 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs index 28e84d2fba6..e788b66a1ec 100644 --- a/src/libcore/ops/try.rs +++ b/src/libcore/ops/try.rs @@ -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")] diff --git a/src/test/ui/suggestions/try-operator-on-main.rs b/src/test/ui/suggestions/try-operator-on-main.rs index 473efea54de..eadd12924df 100644 --- a/src/test/ui/suggestions/try-operator-on-main.rs +++ b/src/test/ui/suggestions/try-operator-on-main.rs @@ -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` diff --git a/src/test/ui/suggestions/try-operator-on-main.stderr b/src/test/ui/suggestions/try-operator-on-main.stderr index 5fc24e46fa7..e83bf2abc15 100644 --- a/src/test/ui/suggestions/try-operator-on-main.stderr +++ b/src/test/ui/suggestions/try-operator-on-main.stderr @@ -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 |
