Skip to content

Commit

Permalink
add CR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeyers35 committed Mar 10, 2020
1 parent 0f7f307 commit a4ba102
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
25 changes: 13 additions & 12 deletions clippy_lints/src/verbose_file_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ declare_clippy_lint! {
/// **What it does:** Checks for use of File::read_to_end and File::read_to_string.
///
/// **Why is this bad?** `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values.
///
/// See also: [fs::read docs](https://doc.rust-lang.org/std/fs/fn.read.html), [fs::read_to_string docs](https://doc.rust-lang.org/std/fs/fn.read_to_string.html)
/// **Known problems:** None.
///
/// **Example:**
///
/// ```rust, ignore
/// let mut f = File::open("foo.txt")?;
/// ```rust,no_run
/// # use std::io::Read;
/// # use std::fs::File;
/// let mut f = File::open("foo.txt").unwrap();
/// let mut bytes = Vec::new();
/// f.read_to_end(&mut bytes)?;
/// f.read_to_end(&mut bytes).unwrap();
/// ```
/// Can be written more concisely as
/// ```rust, ignore
/// let mut bytes = fs::read("foo.txt")?;
/// ```rust,no_run
/// # use std::fs;
/// let mut bytes = fs::read("foo.txt").unwrap();
/// ```
pub VERBOSE_FILE_READS,
complexity,
Expand All @@ -36,19 +39,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads {
cx,
VERBOSE_FILE_READS,
expr.span,
"use of File::read_to_end",
"consider using fs::read instead",
"use of `File::read_to_end`",
"consider using `fs::read` instead",
);
} else if is_file_read_to_string(cx, expr) {
span_lint_and_help(
cx,
VERBOSE_FILE_READS,
expr.span,
"use of File::read_to_string",
"consider using fs::read_to_string instead",
"use of `File::read_to_string`",
"consider using `fs::read_to_string` instead",
)
} else {
// Don't care
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/verbose_file_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ impl Struct {
}

fn main() -> std::io::Result<()> {
let mut path = temp_dir();
path.push("test.txt");
let file = File::create(&path)?;
let path = "foo.txt";
// Lint shouldn't catch this
let s = Struct;
s.read_to_end();
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/verbose_file_reads.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: use of File::read_to_end
--> $DIR/verbose_file_reads.rs:25:5
error: use of `File::read_to_end`
--> $DIR/verbose_file_reads.rs:23:5
|
LL | f.read_to_end(&mut buffer)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::verbose-file-reads` implied by `-D warnings`
= help: consider using fs::read instead
= help: consider using `fs::read` instead

error: use of File::read_to_string
--> $DIR/verbose_file_reads.rs:28:5
error: use of `File::read_to_string`
--> $DIR/verbose_file_reads.rs:26:5
|
LL | f.read_to_string(&mut string_buffer)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using fs::read_to_string instead
= help: consider using `fs::read_to_string` instead

error: aborting due to 2 previous errors

0 comments on commit a4ba102

Please sign in to comment.