Skip to content

Commit a4ba102

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

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

clippy_lints/src/verbose_file_reads.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ 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
17-
/// let mut f = File::open("foo.txt")?;
16+
/// ```rust,no_run
17+
/// # use std::io::Read;
18+
/// # use std::fs::File;
19+
/// let mut f = File::open("foo.txt").unwrap();
1820
/// let mut bytes = Vec::new();
19-
/// f.read_to_end(&mut bytes)?;
21+
/// f.read_to_end(&mut bytes).unwrap();
2022
/// ```
2123
/// Can be written more concisely as
22-
/// ```rust, ignore
23-
/// let mut bytes = fs::read("foo.txt")?;
24+
/// ```rust,no_run
25+
/// # use std::fs;
26+
/// let mut bytes = fs::read("foo.txt").unwrap();
2427
/// ```
2528
pub VERBOSE_FILE_READS,
2629
complexity,
@@ -36,19 +39,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VerboseFileReads {
3639
cx,
3740
VERBOSE_FILE_READS,
3841
expr.span,
39-
"use of File::read_to_end",
40-
"consider using fs::read instead",
42+
"use of `File::read_to_end`",
43+
"consider using `fs::read` instead",
4144
);
4245
} else if is_file_read_to_string(cx, expr) {
4346
span_lint_and_help(
4447
cx,
4548
VERBOSE_FILE_READS,
4649
expr.span,
47-
"use of File::read_to_string",
48-
"consider using fs::read_to_string instead",
50+
"use of `File::read_to_string`",
51+
"consider using `fs::read_to_string` instead",
4952
)
50-
} else {
51-
// Don't care
5253
}
5354
}
5455
}

tests/ui/verbose_file_reads.rs

+1-3
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

+6-6
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)