Skip to content

Commit

Permalink
add error message for the other case too
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed Sep 3, 2017
1 parent efa09ea commit 291b4ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/libcore/ops/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/try-operator-on-main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/suggestions/try-operator-on-main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 291b4ed

Please sign in to comment.