on_unimplemented: add method-name checks and use them in Try

This commit is contained in:
Ariel Ben-Yehuda 2017-08-31 21:46:03 +03:00
parent 6dec953c5a
commit efa09ea554
5 changed files with 69 additions and 12 deletions

View file

@ -13,9 +13,21 @@
use std::ops::Try;
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
()?;
// an unrelated use of `Try`
try_trait_generic::<()>();
}
fn try_trait_generic<T: Try>() {}
fn try_trait_generic<T: Try>() -> T {
// and a non-`Try` object on a `Try` fn.
()?;
loop {}
}

View file

@ -1,7 +1,7 @@
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
--> $DIR/try-operator-on-main.rs:16:5
--> $DIR/try-operator-on-main.rs:17:5
|
16 | std::fs::File::open("foo")?;
17 | std::fs::File::open("foo")?;
| ---------------------------
| |
| cannot use the `?` operator in a function that returns `()`
@ -11,12 +11,34 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu
= note: required by `std::ops::Try::from_error`
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
--> $DIR/try-operator-on-main.rs:18:5
--> $DIR/try-operator-on-main.rs:20:5
|
18 | try_trait_generic::<()>();
20 | ()?;
| ---
| |
| the trait `std::ops::Try` is not implemented for `()`
| in this macro invocation
|
= note: required by `std::ops::Try::into_result`
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
--> $DIR/try-operator-on-main.rs:23:5
|
23 | try_trait_generic::<()>();
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Try` is not implemented for `()`
|
= note: required by `try_trait_generic`
error: aborting due to 2 previous errors
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
--> $DIR/try-operator-on-main.rs:30:5
|
30 | ()?;
| ---
| |
| the trait `std::ops::Try` is not implemented for `()`
| in this macro invocation
|
= note: required by `std::ops::Try::into_result`
error: aborting due to 4 previous errors