trpl-zh-cn/listings/ch09-error-handling/listing-09-10/output.txt

23 lines
953 B
Plaintext
Raw Normal View History

2022-02-06 16:43:51 +08:00
$ cargo run
Compiling error-handling v0.1.0 (file:///projects/error-handling)
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
2023-01-16 17:34:52 +08:00
--> src/main.rs:4:48
2022-02-06 16:43:51 +08:00
|
2023-01-16 17:34:52 +08:00
3 | fn main() {
| --------- this function should return `Result` or `Option` to accept `?`
4 | let greeting_file = File::open("hello.txt")?;
| ^ cannot use the `?` operator in a function that returns `()`
2022-02-06 16:43:51 +08:00
|
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
2024-10-20 23:44:05 +08:00
help: consider adding return type
|
3 ~ fn main() -> Result<(), Box<dyn std::error::Error>> {
4 | let greeting_file = File::open("hello.txt")?;
5 +
6 + Ok(())
7 + }
|
2022-02-06 16:43:51 +08:00
For more information about this error, try `rustc --explain E0277`.
error: could not compile `error-handling` (bin "error-handling") due to 1 previous error