Skip to content

Commit ccfc8de

Browse files
committed
add CR feedback
1 parent 0f7f307 commit ccfc8de

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

clippy_lints/src/verbose_file_reads.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ declare_clippy_lint! {
88
/// **What it does:** Checks for use of File::read_to_end and File::read_to_string.
99
///
1010
/// **Why is this bad?** `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values.
11-
///
11+
/// 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)
1212
/// **Known problems:** None.
1313
///
1414
/// **Example:**
1515
///
16-
/// ```rust, ignore
16+
/// ```rust
17+
/// # use std::fs::File;
1718
/// let mut f = File::open("foo.txt")?;
1819
/// let mut bytes = Vec::new();
1920
/// f.read_to_end(&mut bytes)?;
2021
/// ```
2122
/// Can be written more concisely as
22-
/// ```rust, ignore
23+
/// ```rust
24+
/// # use std::fs;
2325
/// let mut bytes = fs::read("foo.txt")?;
2426
/// ```
2527
pub VERBOSE_FILE_READS,
@@ -36,19 +38,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads {
3638
cx,
3739
VERBOSE_FILE_READS,
3840
expr.span,
39-
"use of File::read_to_end",
40-
"consider using fs::read instead",
41+
"use of `File::read_to_end`",
42+
"consider using `fs::read` instead",
4143
);
4244
} else if is_file_read_to_string(cx, expr) {
4345
span_lint_and_help(
4446
cx,
4547
VERBOSE_FILE_READS,
4648
expr.span,
47-
"use of File::read_to_string",
48-
"consider using fs::read_to_string instead",
49+
"use of `File::read_to_string`",
50+
"consider using `fs::read_to_string` instead",
4951
)
50-
} else {
51-
// Don't care
5252
}
5353
}
5454
}

tests/ui/verbose_file_reads.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ impl Struct {
1212
}
1313

1414
fn main() -> std::io::Result<()> {
15-
let mut path = temp_dir();
16-
path.push("test.txt");
17-
let file = File::create(&path)?;
15+
let path = "foo.txt";
1816
// Lint shouldn't catch this
1917
let s = Struct;
2018
s.read_to_end();

tests/ui/verbose_file_reads.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
error: use of File::read_to_end
2-
--> $DIR/verbose_file_reads.rs:25:5
1+
error: use of `File::read_to_end`
2+
--> $DIR/verbose_file_reads.rs:23:5
33
|
44
LL | f.read_to_end(&mut buffer)?;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::verbose-file-reads` implied by `-D warnings`
8-
= help: consider using fs::read instead
8+
= help: consider using `fs::read` instead
99

10-
error: use of File::read_to_string
11-
--> $DIR/verbose_file_reads.rs:28:5
10+
error: use of `File::read_to_string`
11+
--> $DIR/verbose_file_reads.rs:26:5
1212
|
1313
LL | f.read_to_string(&mut string_buffer)?;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
16-
= help: consider using fs::read_to_string instead
16+
= help: consider using `fs::read_to_string` instead
1717

1818
error: aborting due to 2 previous errors
1919

0 commit comments

Comments
 (0)