Closed
Description
This can be confusing for people new to rust and perhaps trying to copy some example code from https://doc.rust-lang.org/std/fs/struct.File.html:
use std::fs::File;
fn main() {
let mut f = try!(File::create("foo.txt"));
}
https://play.rust-lang.org/?gist=2201429be6f0833e2161&version=stable
At the moment this produces
<std macros>:5:8: 6:42 error: mismatched types:
expected `()`,
found `core::result::Result<_, _>`
(expected (),
found enum `core::result::Result`) [E0308]
<std macros>:5 return $ crate:: result:: Result:: Err (
<std macros>:6 $ crate:: convert:: From:: from ( err ) ) } } )
<std macros>:1:1: 6:48 note: in expansion of try!
<anon>:4:17: 4:46 note: expansion site
<std macros>:5:8: 6:42 help: see the detailed explanation for E0308
error: aborting due to previous error
playpen: application terminated with error code 101
https://doc.rust-lang.org/error-index.html#E0308 is OK but may be hard to see how it applies.
Perhaps the friendliest thing would be to suggest using unwrap()
rather than try!
, though perhaps that is too specialized.
I think there was another bug about main
returning a Result?
Metadata
Metadata
Assignees
Labels
No labels