about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-07-03 10:39:53 -0700
committerGitHub <noreply@github.com>2016-07-03 10:39:53 -0700
commiteebfcb8bf48351f13b19c2faf0b9aa2f152234e4 (patch)
treece9f6b81228e7d9ada8a27a57758fb30b741938a
parent5e858f34df6ac9ae9d2fbc40c84db9d4bcd29eff (diff)
parent8f3e4989a5253f3baac79b8ee27a47aec53c0159 (diff)
Auto merge of #34540 - jupp0r:patch-1, r=steveklabnik
Improve code example for try!

This change improves the code example for try!,
avoiding to use try! in the example code that shows
what code constructs try! can replace.
-rw-r--r--src/libcore/result.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 4d9f042fdde..94c6c636ce8 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -175,8 +175,11 @@
 //! }
 //!
 //! fn write_info(info: &Info) -> io::Result<()> {
-//!     let mut file = try!(File::create("my_best_friends.txt"));
 //!     // Early return on error
+//!     let mut file = match File::create("my_best_friends.txt") {
+//!            Err(e) => return Err(e),
+//!            Ok(f) => f,
+//!     };
 //!     if let Err(e) = file.write_all(format!("name: {}\n", info.name).as_bytes()) {
 //!         return Err(e)
 //!     }