File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1822,6 +1822,30 @@ let x: i32 = "I am not a number!";
1822
1822
// |
1823
1823
// type `i32` assigned to variable `x`
1824
1824
```
1825
+
1826
+ Another situation in which this occurs is when you attempt to use the `try!`
1827
+ macro inside a function that does not return a `Result<T, E>`:
1828
+
1829
+ ```
1830
+ use std::fs::File;
1831
+
1832
+ fn main() {
1833
+ let mut f = try!(File::create("foo.txt"));
1834
+ }
1835
+ ```
1836
+
1837
+ This code gives an error like this:
1838
+
1839
+ ```text
1840
+ <std macros>:5:8: 6:42 error: mismatched types:
1841
+ expected `()`,
1842
+ found `core::result::Result<_, _>`
1843
+ (expected (),
1844
+ found enum `core::result::Result`) [E0308]
1845
+ ```
1846
+
1847
+ `try!` returns a `Result<T, E>`, and so the function must. But `main()` has
1848
+ `()` as its return type, hence the error.
1825
1849
"## ,
1826
1850
1827
1851
E0309 : r##"
You can’t perform that action at this time.
0 commit comments