-
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
use top level fs
functions where appropriate
#56258
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/bootstrap/compile.rs
Outdated
let stamp_contents = match fs::read(stamp) { | ||
Ok(contents) => contents, | ||
Err(ref err) if err.kind() == ErrorKind::InvalidData => { | ||
panic!("could not read contents of stamp"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would InvalidData come up? I could maybe see it if we were reading to string, but with just a Vec return value I don't quite see it -- and this does appear to be new code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to keep the behavior that errors opening the file are ignored but errors reading the file panic. You're right that InvalidData won't come up when we're reading bytes -- it's probably best to just do something like let contents = fs::read(stamp).ok();
?
EDIT: Pushed a commit fixing this.
|
||
let mut f = try_err!(File::open(&entry), &entry); | ||
try_err!(f.read_to_end(&mut content), &entry); | ||
let content = try_err!(fs::read(&entry), &entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically I think this might be a change in performance so cc @rust-lang/rustdoc but I think the new behavior is better, not worse, since we'll allocate correctly versus just guessing.
3bb2545
to
9bc4349
Compare
If you could squash the commits here into one that'd be great; r=me modulo that |
9bc4349
to
be89dff
Compare
Squashed. |
@bors r=Mark-Simulacrum |
📌 Commit be89dff has been approved by |
…crum use top level `fs` functions where appropriate This commit replaces many usages of `File::open` and reading or writing with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code complexity, and will improve performance for most reads, since the functions allocate the buffer to be the size of the file. I believe that this commit will not impact behavior in any way, so some matches will check the error kind in case the file was not valid UTF-8. Some of these cases may not actually care about the error.
☔ The latest upstream changes (presumably #56381) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
Ping @Mark-Simulacrum |
@bors r+ |
📌 Commit d809d21 has been approved by |
…crum use top level `fs` functions where appropriate This commit replaces many usages of `File::open` and reading or writing with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code complexity, and will improve performance for most reads, since the functions allocate the buffer to be the size of the file. I believe that this commit will not impact behavior in any way, so some matches will check the error kind in case the file was not valid UTF-8. Some of these cases may not actually care about the error.
☔ The latest upstream changes (presumably #54517) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased again. Notably in the merge I tweaked the logic a bit to avoid a |
☔ The latest upstream changes (presumably #56566) made this pull request unmergeable. Please resolve the merge conflicts. |
This commit replaces many usages of `File::open` and reading or writing with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code complexity, and will improve performance for most reads, since the functions allocate the buffer to be the size of the file. I believe that this commit will not impact behavior in any way, so some matches will check the error kind in case the file was not valid UTF-8. Some of these cases may not actually care about the error.
@bors delegate+ You should be able to re-approve from here once you've rebased. |
✌️ @euclio can now approve this pull request |
Travis passed. @bors r+ |
📌 Commit 2f62265 has been approved by |
use top level `fs` functions where appropriate This commit replaces many usages of `File::open` and reading or writing with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code complexity, and will improve performance for most reads, since the functions allocate the buffer to be the size of the file. I believe that this commit will not impact behavior in any way, so some matches will check the error kind in case the file was not valid UTF-8. Some of these cases may not actually care about the error.
☀️ Test successful - status-appveyor, status-travis |
Accidentally broken in rust-lang#56258!
Fix build of the `build-manifest` tool Accidentally broken in #56258!
This commit replaces many usages of
File::open
and reading or writingwith
fs::read_to_string
,fs::read
andfs::write
. This reduces codecomplexity, and will improve performance for most reads, since the
functions allocate the buffer to be the size of the file.
I believe that this commit will not impact behavior in any way, so some
matches will check the error kind in case the file was not valid UTF-8.
Some of these cases may not actually care about the error.