2021-04-17 18:56:07 +00:00
|
|
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
|
|
--> $DIR/try-operator-on-main.rs:7:31
|
2017-08-30 21:12:34 +00:00
|
|
|
|
|
2022-09-01 19:52:39 +00:00
|
|
|
LL | fn main() {
|
|
|
|
| --------- this function should return `Result` or `Option` to accept `?`
|
|
|
|
LL | // error for a `Try` type on a non-`Try` fn
|
|
|
|
LL | std::fs::File::open("foo")?;
|
|
|
|
| ^ cannot use the `?` operator in a function that returns `()`
|
2017-07-01 00:11:12 +00:00
|
|
|
|
|
2021-04-17 18:56:07 +00:00
|
|
|
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
|
2024-06-09 09:20:25 +00:00
|
|
|
help: consider adding return type
|
|
|
|
|
|
|
|
|
LL ~ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
LL | // error for a `Try` type on a non-`Try` fn
|
2024-06-20 04:25:17 +00:00
|
|
|
...
|
2024-06-09 09:20:25 +00:00
|
|
|
LL | try_trait_generic::<()>();
|
|
|
|
LL + Ok(())
|
|
|
|
|
|
2017-07-01 00:11:12 +00:00
|
|
|
|
2020-09-02 07:40:56 +00:00
|
|
|
error[E0277]: the `?` operator can only be applied to values that implement `Try`
|
2020-10-27 13:10:31 +00:00
|
|
|
--> $DIR/try-operator-on-main.rs:10:5
|
2017-08-30 21:12:34 +00:00
|
|
|
|
|
2019-03-09 12:03:44 +00:00
|
|
|
LL | ()?;
|
2018-01-26 19:34:12 +00:00
|
|
|
| ^^^ the `?` operator cannot be applied to type `()`
|
2017-08-31 18:46:03 +00:00
|
|
|
|
|
2020-09-02 07:40:56 +00:00
|
|
|
= help: the trait `Try` is not implemented for `()`
|
2021-04-17 18:56:07 +00:00
|
|
|
|
|
|
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
|
|
--> $DIR/try-operator-on-main.rs:10:7
|
|
|
|
|
|
2022-09-01 19:52:39 +00:00
|
|
|
LL | fn main() {
|
|
|
|
| --------- this function should return `Result` or `Option` to accept `?`
|
|
|
|
...
|
|
|
|
LL | ()?;
|
|
|
|
| ^ cannot use the `?` operator in a function that returns `()`
|
2021-04-17 18:56:07 +00:00
|
|
|
|
|
|
|
|
= help: the trait `FromResidual<_>` is not implemented for `()`
|
2017-08-31 18:46:03 +00:00
|
|
|
|
2020-09-02 07:40:56 +00:00
|
|
|
error[E0277]: the trait bound `(): Try` is not satisfied
|
2021-04-17 18:56:07 +00:00
|
|
|
--> $DIR/try-operator-on-main.rs:14:25
|
2017-08-31 18:46:03 +00:00
|
|
|
|
|
2019-03-09 12:03:44 +00:00
|
|
|
LL | try_trait_generic::<()>();
|
2020-09-02 07:40:56 +00:00
|
|
|
| ^^ the trait `Try` is not implemented for `()`
|
2021-07-31 16:26:55 +00:00
|
|
|
|
|
|
|
|
note: required by a bound in `try_trait_generic`
|
|
|
|
--> $DIR/try-operator-on-main.rs:17:25
|
|
|
|
|
|
2018-02-23 00:42:32 +00:00
|
|
|
LL | fn try_trait_generic<T: Try>() -> T {
|
2021-07-31 16:26:55 +00:00
|
|
|
| ^^^ required by this bound in `try_trait_generic`
|
2017-08-30 21:12:34 +00:00
|
|
|
|
2020-09-02 07:40:56 +00:00
|
|
|
error[E0277]: the `?` operator can only be applied to values that implement `Try`
|
2021-04-17 18:56:07 +00:00
|
|
|
--> $DIR/try-operator-on-main.rs:19:5
|
2017-08-31 18:46:03 +00:00
|
|
|
|
|
2019-03-09 12:03:44 +00:00
|
|
|
LL | ()?;
|
2018-01-26 19:34:12 +00:00
|
|
|
| ^^^ the `?` operator cannot be applied to type `()`
|
2017-08-31 18:46:03 +00:00
|
|
|
|
|
2020-09-02 07:40:56 +00:00
|
|
|
= help: the trait `Try` is not implemented for `()`
|
2017-08-31 18:46:03 +00:00
|
|
|
|
2021-04-17 18:56:07 +00:00
|
|
|
error: aborting due to 5 previous errors
|
2017-07-01 00:11:12 +00:00
|
|
|
|
2018-03-03 14:59:40 +00:00
|
|
|
For more information about this error, try `rustc --explain E0277`.
|