Skip to content
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

Rustc suggests creating a Box<Box<Box<(...)File>>> when std::io::Write isn't imported #84792

Closed
C34A opened this issue May 1, 2021 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@C34A
Copy link

C34A commented May 1, 2021

Given the following code:
play.rust-lang.org: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=320bd0fa60b7736e04ac82df5a77c760
It isn't able to run in the online thing, but the rest of the code is at https://github.com/C34A/vm1/blob/files/src/main.rs

let mut output_file = fs::File::create(newfilename).expect("failed to create output file");
output_file.write_all(&binary).expect("failed to write to output file!");

The current output is:

error[E0599]: no method named `write_all` found for struct `File` in the current scope
    --> src/main.rs:76:41
     |
76   | ...                   output_file.write_all(&binary).expect("failed to write to output file!");
     |                                   ^^^^^^^^^ method not found in `File`
     | 
    ::: /home/theo/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:1438:8
     |
1438 |     fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
     |        ---------
     |        |
     |        the method is available for `Box<File>` here
     |        the method is available for `Box<&mut File>` here
     |        the method is available for `Box<&File>` here
     |
help: consider wrapping the receiver expression with the appropriate type
     |
76   |                             Box::new(output_file).write_all(&binary).expect("failed to write to output file!");
     |                             ^^^^^^^^^           ^
help: consider wrapping the receiver expression with the appropriate type
     |
76   |                             Box::new(&mut output_file).write_all(&binary).expect("failed to write to output file!");
     |                             ^^^^^^^^^^^^^            ^
help: consider wrapping the receiver expression with the appropriate type
     |
76   |                             Box::new(&output_file).write_all(&binary).expect("failed to write to output file!");

Boxing output_file results in:

1438 |     fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
     |        ---------
     |        |
     |        the method is available for `Box<Box<File>>` here
     |        the method is available for `Box<&mut Box<File>>` here

... and so on.

The issue is that I don't have std::io::Write imported. I'm not sure exactly what the best output would be.

I am using a recent 1.53 nightly build:

rustc 1.53.0-nightly (42816d61e 2021-04-24)
binary: rustc
commit-hash: 42816d61ead7e46d462df997958ccfd514f8c21c
commit-date: 2021-04-24
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0
@C34A C34A added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 1, 2021
@5225225
Copy link
Contributor

5225225 commented May 1, 2021

This might be the same issue as #84272 which was fixed a few days after that nightly.

Try removing rustfmt to allow rustup to upgrade past that and see if it works correctly after that.

@C34A
Copy link
Author

C34A commented May 1, 2021

Yep, I think you're right. With the nightly from 2021-04-30 this seems to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants