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

Rename fs::read_string to read_to_string and stabilize #49522

Merged
merged 1 commit into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ fn get_resident() -> Option<usize> {
use std::fs;

let field = 1;
let contents = fs::read_string("/proc/self/statm").ok()?;
let contents = fs::read("/proc/self/statm").ok()?;
let contents = String::from_utf8(contents).ok()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Other than this r=me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the new read_to_string function here would break bootstrapping from the previous release, where that name didn't exist. This seemed simpler than doing some sort of conditional import based on cfg(stage0).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, sounds good.

let s = contents.split_whitespace().nth(field)?;
let npages = s.parse::<usize>().ok()?;
Some(npages * 4096)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ impl<'a> SourceCollector<'a> {
return Ok(());
}

let contents = fs::read_string(&p)?;
let contents = fs::read_to_string(&p)?;

// Remove the utf-8 BOM if any
let contents = if contents.starts_with("\u{feff}") {
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
/// use std::net::SocketAddr;
///
/// fn main() -> Result<(), Box<std::error::Error + 'static>> {
/// let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;
/// let foo: SocketAddr = fs::read_to_string("address.txt")?.parse()?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "fs_read_write", issue = "46588")]
pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
#[stable(feature = "fs_read_write", since = "1.26.0")]
pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut file = File::open(path)?;
let mut string = String::with_capacity(initial_buffer_size(&file));
file.read_to_string(&mut string)?;
Expand Down Expand Up @@ -3122,12 +3122,12 @@ mod tests {
assert!(v == &bytes[..]);

check!(fs::write(&tmpdir.join("not-utf8"), &[0xFF]));
error_contains!(fs::read_string(&tmpdir.join("not-utf8")),
error_contains!(fs::read_to_string(&tmpdir.join("not-utf8")),
"stream did not contain valid UTF-8");

let s = "𐁁𐀓𐀠𐀴𐀍";
check!(fs::write(&tmpdir.join("utf8"), s.as_bytes()));
let string = check!(fs::read_string(&tmpdir.join("utf8")));
let string = check!(fs::read_to_string(&tmpdir.join("utf8")));
assert_eq!(string, s);
}

Expand Down