about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2016-01-07 14:09:20 -0500
committerSteve Klabnik <steve@steveklabnik.com>2016-01-07 14:09:20 -0500
commitce49e3225e19ade67cfc6dfcb1b27db621823fcf (patch)
tree33e7c553ac7c85b172878e6b2950be4ac2861176
parent03f49502391a45e4b021c332dc9f38a05087b84a (diff)
downloadrust-ce49e3225e19ade67cfc6dfcb1b27db621823fcf.tar.gz
rust-ce49e3225e19ade67cfc6dfcb1b27db621823fcf.zip
Expand EO308 to mention try!
Fixes #28953
-rw-r--r--src/librustc/diagnostics.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 178d8a87214..3aabe4b4931 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -1822,6 +1822,30 @@ let x: i32 = "I am not a number!";
 //      |
 //    type `i32` assigned to variable `x`
 ```
+
+Another situation in which this occurs is when you attempt to use the `try!`
+macro inside a function that does not return a `Result<T, E>`:
+
+```
+use std::fs::File;
+
+fn main() {
+    let mut f = try!(File::create("foo.txt"));
+}
+```
+
+This code gives an error like this:
+
+```text
+<std macros>:5:8: 6:42 error: mismatched types:
+ expected `()`,
+     found `core::result::Result<_, _>`
+ (expected (),
+     found enum `core::result::Result`) [E0308]
+```
+
+`try!` returns a `Result<T, E>`, and so the function must. But `main()` has
+`()` as its return type, hence the error.
 "##,
 
 E0309: r##"