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

Remove obsolete comment and simplify code #14264

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions clippy_lints/src/methods/unbuffered_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ use rustc_lint::LateContext;
use rustc_span::sym;

pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
let ty = cx.typeck_results().expr_ty_adjusted(recv);

// If the .bytes() call is a call from the Read trait
if is_trait_method(cx, expr, sym::IoRead) {
// Retrieve the DefId of the BufRead trait
// FIXME: add a diagnostic item for `BufRead`
let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead) else {
return;
};
// And the implementor of the trait is not buffered
if !implements_trait(cx, ty, buf_read, &[]) {
span_lint_and_help(
cx,
UNBUFFERED_BYTES,
expr.span,
"calling .bytes() is very inefficient when data is not in memory",
None,
"consider using `BufReader`",
);
}
// Lint if the `.bytes()` call is from the `Read` trait and the implementor is not buffered.
if is_trait_method(cx, expr, sym::IoRead)
&& let Some(buf_read) = cx.tcx.get_diagnostic_item(sym::IoBufRead)
&& let ty = cx.typeck_results().expr_ty_adjusted(recv)
&& !implements_trait(cx, ty, buf_read, &[])
{
span_lint_and_help(
cx,
UNBUFFERED_BYTES,
expr.span,
"calling .bytes() is very inefficient when data is not in memory",
None,
"consider using `BufReader`",
);
}
}
Loading