-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::fs::File functions panic on valid return type #49491
Comments
Notice the error message:
This restriction is changing soon, but in the mean time I'd suggest using a separate function: use std::fs::File;
use std::io::{self, prelude::*};
fn run() -> io::Result<File> {
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!")?;
Ok(file)
}
fn main() {
run().unwrap();
} |
Ah, ok. English can be so finicky — a single word changes everything. I certainly look forward to the issue you've linked to. Thanks! |
Yeah, I was confused when I read the error message too - and I've been speaking English for a while... |
Oh, I'm a native speaker. That's probably why I missed it. |
The following code taken directly from documentation will not compile.
The error message is as follows:
The documentation for
create()
indicates that the function does returnResult<File>
, but the compiler believes it returns()
.write_all()
indicates it returnsResult<()>
.Clearly, both functions implement
std::ops::Try
viaResult
, but an example as basic as this fails on that test.Version
Fails on both stable and nightly.
rustc --version
→
rustc 1.25.0 (84203cac6 2018-03-25)
→
rustc 1.26.0-nightly (e5277c145 2018-03-28)
The text was updated successfully, but these errors were encountered: