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

add lint on File::read_to_string and File::read_to_end #5272

Merged
merged 2 commits into from
Mar 10, 2020

Conversation

jmeyers35
Copy link
Contributor

Adds lint verbose_file_reads which checks for use of File::read_to_end and File::read_to_string.

Closes #4916

changelog: add lint on File::{read_to_end, read_to_string}

@bors
Copy link
Collaborator

bors commented Mar 5, 2020

☔ The latest upstream changes (presumably #5230) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Collaborator

bors commented Mar 5, 2020

☔ The latest upstream changes (presumably #5276) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

LGTM overall

clippy_lints/src/verbose_file_reads.rs Show resolved Hide resolved
clippy_lints/src/verbose_file_reads.rs Outdated Show resolved Hide resolved
clippy_lints/src/verbose_file_reads.rs Outdated Show resolved Hide resolved
clippy_lints/src/verbose_file_reads.rs Outdated Show resolved Hide resolved
tests/ui/verbose_file_reads.rs Outdated Show resolved Hide resolved
clippy_lints/src/verbose_file_reads.rs Outdated Show resolved Hide resolved
clippy_lints/src/verbose_file_reads.rs Outdated Show resolved Hide resolved
@flip1995 flip1995 added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Mar 9, 2020
@jmeyers35
Copy link
Contributor Author

I'm guessing something like

    /// # use std::io::Read;
    /// # use std::fs::File;
    /// # fn main() -> std::io::Result<()> { 
    /// let mut f = File::open("foo.txt")?;
    /// let mut bytes = Vec::new();
    /// f.read_to_end(&mut bytes)?;
    /// # Ok(())
    /// # }

would make the doctest happy? (though wouldn't it then fail on /// let mut f = File::open("foo.txt")?; )?

///
/// ```rust
/// # use std::fs::File;
/// let mut f = File::open("foo.txt")?;
Copy link
Member

Choose a reason for hiding this comment

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

Just use .unwrap() here, instead of ?.

@jmeyers35 jmeyers35 force-pushed the file_read_lint branch 2 times, most recently from be94542 to 371886a Compare March 10, 2020 19:28
@flip1995
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 10, 2020

📌 Commit a4ba102 has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Mar 10, 2020

⌛ Testing commit a4ba102 with merge fdce47b...

@bors
Copy link
Collaborator

bors commented Mar 10, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing fdce47b to master...

@bors bors merged commit fdce47b into rust-lang:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: suggest using fs::{read,read_to_string} over File counterparts
3 participants