about summary refs log tree commit diff
path: root/clippy_lints/src/methods
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-02-20 17:54:49 +0100
committerSamuel Tardieu <sam@rfc1149.net>2025-02-20 18:03:40 +0100
commitacfbbc65b54600a4e3b16d6c63258e51907336fe (patch)
tree4abd6a60d10fe4f7ebc64d4b954d73e09b447438 /clippy_lints/src/methods
parent238edf273d195c8e472851ebd60571f77f978ac8 (diff)
downloadrust-acfbbc65b54600a4e3b16d6c63258e51907336fe.tar.gz
rust-acfbbc65b54600a4e3b16d6c63258e51907336fe.zip
Remove obsolete comment and simplify code
The `IoBufRead` diagnostic has been added during the latest rustup.
Diffstat (limited to 'clippy_lints/src/methods')
-rw-r--r--clippy_lints/src/methods/unbuffered_bytes.rs34
1 files changed, 14 insertions, 20 deletions
diff --git a/clippy_lints/src/methods/unbuffered_bytes.rs b/clippy_lints/src/methods/unbuffered_bytes.rs
index c4d2515a7bc..dd5566f8c8b 100644
--- a/clippy_lints/src/methods/unbuffered_bytes.rs
+++ b/clippy_lints/src/methods/unbuffered_bytes.rs
@@ -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`",
+        );
     }
 }