summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch09-error-handling/listing-09-10
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch09-error-handling/listing-09-10')
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-10/output.txt15
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-10/src/main.rs5
4 files changed, 32 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.lock b/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.lock
new file mode 100644
index 000000000..1fa96b797
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "error-handling"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.toml b/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.toml
new file mode 100644
index 000000000..c496db783
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-10/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "error-handling"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-10/output.txt b/src/doc/book/listings/ch09-error-handling/listing-09-10/output.txt
new file mode 100644
index 000000000..26e4ff8cc
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-10/output.txt
@@ -0,0 +1,15 @@
+$ 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`)
+ --> src/main.rs:4:48
+ |
+3 | / fn main() {
+4 | | let greeting_file = File::open("hello.txt")?;
+ | | ^ cannot use the `?` operator in a function that returns `()`
+5 | | }
+ | |_- this function should return `Result` or `Option` to accept `?`
+ |
+ = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
+
+For more information about this error, try `rustc --explain E0277`.
+error: could not compile `error-handling` due to previous error
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-10/src/main.rs b/src/doc/book/listings/ch09-error-handling/listing-09-10/src/main.rs
new file mode 100644
index 000000000..38b005480
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-10/src/main.rs
@@ -0,0 +1,5 @@
+use std::fs::File;
+
+fn main() {
+ let greeting_file = File::open("hello.txt")?;
+}