Skip to content

Commit 732e329

Browse files
authored
Remove obsolete comment and simplify code (#14264)
The `IoBufRead` diagnostic has been added during the latest rustup. changelog: none
2 parents 238edf2 + acfbbc6 commit 732e329

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

clippy_lints/src/methods/unbuffered_bytes.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,19 @@ use rustc_lint::LateContext;
77
use rustc_span::sym;
88

99
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
10-
let ty = cx.typeck_results().expr_ty_adjusted(recv);
11-
12-
// If the .bytes() call is a call from the Read trait
13-
if is_trait_method(cx, expr, sym::IoRead) {
14-
// Retrieve the DefId of the BufRead trait
15-
// FIXME: add a diagnostic item for `BufRead`
16-
let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead) else {
17-
return;
18-
};
19-
// And the implementor of the trait is not buffered
20-
if !implements_trait(cx, ty, buf_read, &[]) {
21-
span_lint_and_help(
22-
cx,
23-
UNBUFFERED_BYTES,
24-
expr.span,
25-
"calling .bytes() is very inefficient when data is not in memory",
26-
None,
27-
"consider using `BufReader`",
28-
);
29-
}
10+
// Lint if the `.bytes()` call is from the `Read` trait and the implementor is not buffered.
11+
if is_trait_method(cx, expr, sym::IoRead)
12+
&& let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead)
13+
&& let ty = cx.typeck_results().expr_ty_adjusted(recv)
14+
&& !implements_trait(cx, ty, buf_read, &[])
15+
{
16+
span_lint_and_help(
17+
cx,
18+
UNBUFFERED_BYTES,
19+
expr.span,
20+
"calling .bytes() is very inefficient when data is not in memory",
21+
None,
22+
"consider using `BufReader`",
23+
);
3024
}
3125
}

0 commit comments

Comments
 (0)