From 0b48a451dd61ac0b6bd4c1078a301b5e19e92275 Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Sun, 17 May 2026 21:22:16 +0300 Subject: [PATCH 1/7] new lint: bufreader_stdin --- clippy_lints/src/bufreader_stdin.rs | 82 +++++++++++++++++++++++++++++ clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/lib.rs | 1 + tests/ui/bufreader_stdin.fixed | 12 +++++ tests/ui/bufreader_stdin.rs | 12 +++++ tests/ui/bufreader_stdin.stderr | 22 ++++++++ 6 files changed, 130 insertions(+) create mode 100644 clippy_lints/src/bufreader_stdin.rs create mode 100644 tests/ui/bufreader_stdin.fixed create mode 100644 tests/ui/bufreader_stdin.rs create mode 100644 tests/ui/bufreader_stdin.stderr diff --git a/clippy_lints/src/bufreader_stdin.rs b/clippy_lints/src/bufreader_stdin.rs new file mode 100644 index 000000000000..4fed4f13d2cd --- /dev/null +++ b/clippy_lints/src/bufreader_stdin.rs @@ -0,0 +1,82 @@ +use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet}; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind, QPath, TyKind}; +use rustc_lint::{LateContext, LateLintPass}; +use clippy_utils::{sym}; +use rustc_session::impl_lint_pass; + +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `BufReader::new` with `Stdin` or `StdinLock`. + /// + /// ### Why is this bad? + /// `Stdin` is already buffered. Re-buffering it only increase the memcpy calls. + /// + /// ### Example + /// + /// ```ignore + /// let reader = std::io::BufReader::new(std::io::stdin()); + /// ``` + /// Use instead: + /// ```ignore + /// let stdin = std::io::stdin(); + /// let reader = stdin.lock(); + /// ``` + + #[clippy::version = "1.97.0"] + pub BUFREADER_STDIN, + perf, + "using `BufReader::new` with `Stdin` or `StdinLock` is unnecessary and less efficient" +} + +impl_lint_pass!(BufreaderStdin => [BUFREADER_STDIN]); + +pub struct BufreaderStdin { +} + +impl BufreaderStdin { + pub fn new() -> Self { + Self {} + } +} + +impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { + if expr.span.from_expansion(){ + return; + } + + if let ExprKind::Call(func, [arg]) = expr.kind + && let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind + && segment.ident.name == sym::new + && let TyKind::Path(ref qpath) = ty.kind + && let Some(did) = cx.qpath_res(qpath, ty.hir_id).opt_def_id() + && cx.tcx.def_path_str(did).ends_with("std::io::BufReader") + && let arg_ty = cx.typeck_results().expr_ty(arg) + && let Some(arg_did) = arg_ty.ty_adt_def().map(rustc_middle::ty::AdtDef::did) + { + if cx.tcx.is_diagnostic_item(sym::Stdin, arg_did) { + span_lint_and_sugg( + cx, + BUFREADER_STDIN, + expr.span, + "using `BufReader::new` with `Stdin`", + "instead of wrapping `Stdin` in `BufReader`, use the `lock` method directly", + format!("{}.lock()", snippet(cx, arg.span, "..")), + Applicability::MachineApplicable, + ); + } + else if cx.tcx.def_path_str(arg_did).ends_with("std::io::StdinLock"){ + span_lint_and_sugg( + cx, + BUFREADER_STDIN, + expr.span, + "using `BufReader::new` with `StdinLock`", + "instead of wrapping `StdinLock` in `BufReader`, use it directly", + snippet(cx, arg.span, "..").to_string(), + Applicability::MachineApplicable, + ); + } + } + } +} \ No newline at end of file diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index b14ee7f3de90..c58f69b1d7f6 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -44,6 +44,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::booleans::OVERLY_COMPLEX_BOOL_EXPR_INFO, crate::borrow_deref_ref::BORROW_DEREF_REF_INFO, crate::box_default::BOX_DEFAULT_INFO, + crate::bufreader_stdin::BUFREADER_STDIN_INFO, crate::byte_char_slices::BYTE_CHAR_SLICES_INFO, crate::cargo::CARGO_COMMON_METADATA_INFO, crate::cargo::LINT_GROUPS_PRIORITY_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 7a233e09e800..f1c2c2ae93b5 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -84,6 +84,7 @@ mod bool_to_int_with_if; mod booleans; mod borrow_deref_ref; mod box_default; +mod bufreader_stdin; mod byte_char_slices; mod cargo; mod casts; diff --git a/tests/ui/bufreader_stdin.fixed b/tests/ui/bufreader_stdin.fixed new file mode 100644 index 000000000000..8b61d51509af --- /dev/null +++ b/tests/ui/bufreader_stdin.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::bufreader_stdin)] + +use std::io::{self, BufReader}; + +fn main() { + let a = io::stdin(); + let reader = a.lock(); + //~^ bufreader_stdin + let b = io::stdin().lock(); + let reader = b; + //~^ bufreader_stdin +} \ No newline at end of file diff --git a/tests/ui/bufreader_stdin.rs b/tests/ui/bufreader_stdin.rs new file mode 100644 index 000000000000..badfb31e5a3f --- /dev/null +++ b/tests/ui/bufreader_stdin.rs @@ -0,0 +1,12 @@ +#![warn(clippy::bufreader_stdin)] + +use std::io::{self, BufReader}; + +fn main() { + let a = io::stdin(); + let reader = BufReader::new(a); + //~^ bufreader_stdin + let b = io::stdin().lock(); + let reader = BufReader::new(b); + //~^ bufreader_stdin +} \ No newline at end of file diff --git a/tests/ui/bufreader_stdin.stderr b/tests/ui/bufreader_stdin.stderr new file mode 100644 index 000000000000..6190cd892453 --- /dev/null +++ b/tests/ui/bufreader_stdin.stderr @@ -0,0 +1,22 @@ +error: using `BufReader::new` with `Stdin` + --> tests/ui/bufreader_stdin.rs:7:18 + | +LL | let reader = BufReader::new(a); + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::bufreader-stdin` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bufreader_stdin)]` +help: instead of wrapping `Stdin` in `BufReader`, use the `lock` method directly + | +LL - let reader = BufReader::new(a); +LL + let reader = a.lock(); + | + +error: using `BufReader::new` with `StdinLock` + --> tests/ui/bufreader_stdin.rs:10:18 + | +LL | let reader = BufReader::new(b); + | ^^^^^^^^^^^^^^^^^ help: instead of wrapping `StdinLock` in `BufReader`, use it directly: `b` + +error: aborting due to 2 previous errors + From 6ff18aade12c19c5a289e5e9d2779d5c7fbf8349 Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Sun, 17 May 2026 21:29:31 +0300 Subject: [PATCH 2/7] fixed change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc308285319f..6a697f1e2fcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6778,6 +6778,7 @@ Released 2018-09-13 [`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec [`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local [`branches_sharing_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code +[`bufreader_stdin`]: https://rust-lang.github.io/rust-clippy/master/index.html#bufreader_stdin [`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow [`by_ref_peekable_peek`]: https://rust-lang.github.io/rust-clippy/master/index.html#by_ref_peekable_peek [`byte_char_slices`]: https://rust-lang.github.io/rust-clippy/master/index.html#byte_char_slices From fc21fd796914d3305f72b1ae46fbeaabea8e3556 Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Sun, 17 May 2026 21:30:55 +0300 Subject: [PATCH 3/7] ran `cargo dev fmt` --- clippy_lints/src/bufreader_stdin.rs | 31 ++++++++++++++--------------- tests/ui/bufreader_stdin.rs | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/bufreader_stdin.rs b/clippy_lints/src/bufreader_stdin.rs index 4fed4f13d2cd..c26ca737b293 100644 --- a/clippy_lints/src/bufreader_stdin.rs +++ b/clippy_lints/src/bufreader_stdin.rs @@ -1,8 +1,9 @@ -use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet}; +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::snippet; +use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass}; -use clippy_utils::{sym}; use rustc_session::impl_lint_pass; declare_clippy_lint! { @@ -31,10 +32,9 @@ declare_clippy_lint! { impl_lint_pass!(BufreaderStdin => [BUFREADER_STDIN]); -pub struct BufreaderStdin { -} +pub struct BufreaderStdin {} -impl BufreaderStdin { +impl BufreaderStdin { pub fn new() -> Self { Self {} } @@ -42,18 +42,18 @@ impl BufreaderStdin { impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion(){ + if expr.span.from_expansion() { return; } if let ExprKind::Call(func, [arg]) = expr.kind - && let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind - && segment.ident.name == sym::new - && let TyKind::Path(ref qpath) = ty.kind - && let Some(did) = cx.qpath_res(qpath, ty.hir_id).opt_def_id() - && cx.tcx.def_path_str(did).ends_with("std::io::BufReader") - && let arg_ty = cx.typeck_results().expr_ty(arg) - && let Some(arg_did) = arg_ty.ty_adt_def().map(rustc_middle::ty::AdtDef::did) + && let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind + && segment.ident.name == sym::new + && let TyKind::Path(ref qpath) = ty.kind + && let Some(did) = cx.qpath_res(qpath, ty.hir_id).opt_def_id() + && cx.tcx.def_path_str(did).ends_with("std::io::BufReader") + && let arg_ty = cx.typeck_results().expr_ty(arg) + && let Some(arg_did) = arg_ty.ty_adt_def().map(rustc_middle::ty::AdtDef::did) { if cx.tcx.is_diagnostic_item(sym::Stdin, arg_did) { span_lint_and_sugg( @@ -65,8 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { format!("{}.lock()", snippet(cx, arg.span, "..")), Applicability::MachineApplicable, ); - } - else if cx.tcx.def_path_str(arg_did).ends_with("std::io::StdinLock"){ + } else if cx.tcx.def_path_str(arg_did).ends_with("std::io::StdinLock") { span_lint_and_sugg( cx, BUFREADER_STDIN, @@ -79,4 +78,4 @@ impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { } } } -} \ No newline at end of file +} diff --git a/tests/ui/bufreader_stdin.rs b/tests/ui/bufreader_stdin.rs index badfb31e5a3f..41d6cbd564cd 100644 --- a/tests/ui/bufreader_stdin.rs +++ b/tests/ui/bufreader_stdin.rs @@ -9,4 +9,4 @@ fn main() { let b = io::stdin().lock(); let reader = BufReader::new(b); //~^ bufreader_stdin -} \ No newline at end of file +} From 75d8e79676803137a37c437c9fadb52ee46e220b Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Sun, 17 May 2026 21:38:15 +0300 Subject: [PATCH 4/7] removed extra space in test --- tests/ui/bufreader_stdin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/bufreader_stdin.rs b/tests/ui/bufreader_stdin.rs index 41d6cbd564cd..badfb31e5a3f 100644 --- a/tests/ui/bufreader_stdin.rs +++ b/tests/ui/bufreader_stdin.rs @@ -9,4 +9,4 @@ fn main() { let b = io::stdin().lock(); let reader = BufReader::new(b); //~^ bufreader_stdin -} +} \ No newline at end of file From 346b56ac4ba3816fd5edc905cc4749bc4a2cb058 Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Sun, 17 May 2026 21:42:50 +0300 Subject: [PATCH 5/7] made sure test and output match --- tests/ui/bufreader_stdin.fixed | 2 +- tests/ui/bufreader_stdin.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/bufreader_stdin.fixed b/tests/ui/bufreader_stdin.fixed index 8b61d51509af..2984af523388 100644 --- a/tests/ui/bufreader_stdin.fixed +++ b/tests/ui/bufreader_stdin.fixed @@ -9,4 +9,4 @@ fn main() { let b = io::stdin().lock(); let reader = b; //~^ bufreader_stdin -} \ No newline at end of file +} diff --git a/tests/ui/bufreader_stdin.rs b/tests/ui/bufreader_stdin.rs index badfb31e5a3f..41d6cbd564cd 100644 --- a/tests/ui/bufreader_stdin.rs +++ b/tests/ui/bufreader_stdin.rs @@ -9,4 +9,4 @@ fn main() { let b = io::stdin().lock(); let reader = BufReader::new(b); //~^ bufreader_stdin -} \ No newline at end of file +} From e0e52523d29534163943f2e927bf2f9f5651051b Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Wed, 22 Jul 2026 02:15:46 +0300 Subject: [PATCH 6/7] addressed PR comments --- clippy_lints/src/bufreader_stdin.rs | 64 ++++++++++++++++------------- clippy_lints/src/lib.rs | 1 + tests/ui/bufreader_stdin.fixed | 7 ++++ tests/ui/bufreader_stdin.rs | 7 ++++ tests/ui/bufreader_stdin.stderr | 8 ++-- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/bufreader_stdin.rs b/clippy_lints/src/bufreader_stdin.rs index c26ca737b293..f95fa0cdfaa4 100644 --- a/clippy_lints/src/bufreader_stdin.rs +++ b/clippy_lints/src/bufreader_stdin.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::snippet; use clippy_utils::sym; use rustc_errors::Applicability; @@ -11,14 +11,16 @@ declare_clippy_lint! { /// Checks for usage of `BufReader::new` with `Stdin` or `StdinLock`. /// /// ### Why is this bad? - /// `Stdin` is already buffered. Re-buffering it only increase the memcpy calls. + /// `Stdin` is already buffered. Re-buffering it only increases the memcpy calls. /// /// ### Example /// /// ```ignore /// let reader = std::io::BufReader::new(std::io::stdin()); /// ``` + /// /// Use instead: + /// /// ```ignore /// let stdin = std::io::stdin(); /// let reader = stdin.lock(); @@ -26,7 +28,7 @@ declare_clippy_lint! { #[clippy::version = "1.97.0"] pub BUFREADER_STDIN, - perf, + pedantic, "using `BufReader::new` with `Stdin` or `StdinLock` is unnecessary and less efficient" } @@ -42,39 +44,45 @@ impl BufreaderStdin { impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if expr.span.from_expansion() { - return; - } - if let ExprKind::Call(func, [arg]) = expr.kind && let ExprKind::Path(QPath::TypeRelative(ty, segment)) = func.kind && segment.ident.name == sym::new && let TyKind::Path(ref qpath) = ty.kind && let Some(did) = cx.qpath_res(qpath, ty.hir_id).opt_def_id() - && cx.tcx.def_path_str(did).ends_with("std::io::BufReader") - && let arg_ty = cx.typeck_results().expr_ty(arg) - && let Some(arg_did) = arg_ty.ty_adt_def().map(rustc_middle::ty::AdtDef::did) + && cx.tcx.is_diagnostic_item(sym::IoBufReader, did) + && let Some(arg_did) = cx + .typeck_results() + .expr_ty(arg) + .ty_adt_def() + .map(rustc_middle::ty::AdtDef::did) { - if cx.tcx.is_diagnostic_item(sym::Stdin, arg_did) { - span_lint_and_sugg( - cx, - BUFREADER_STDIN, - expr.span, - "using `BufReader::new` with `Stdin`", + let snip = snippet(cx, arg.span, ".."); + let applicability = if snip == ".." { + Applicability::HasPlaceholders + } else { + Applicability::MaybeIncorrect + }; + + let (msg, help, sugg) = if cx.tcx.is_diagnostic_item(sym::Stdin, arg_did) { + ( + "wrapping already buffered `Stdin` into a `BufReader`", "instead of wrapping `Stdin` in `BufReader`, use the `lock` method directly", - format!("{}.lock()", snippet(cx, arg.span, "..")), - Applicability::MachineApplicable, - ); - } else if cx.tcx.def_path_str(arg_did).ends_with("std::io::StdinLock") { - span_lint_and_sugg( - cx, - BUFREADER_STDIN, - expr.span, - "using `BufReader::new` with `StdinLock`", + format!("{snip}.lock()"), + ) + } else if cx.tcx.is_diagnostic_item(sym::StdinLock, arg_did) { + ( + "wrapping already buffered `StdinLock` into a `BufReader`", "instead of wrapping `StdinLock` in `BufReader`, use it directly", - snippet(cx, arg.span, "..").to_string(), - Applicability::MachineApplicable, - ); + snip.to_string(), + ) + } else { + return; + }; + + if arg.span.from_expansion() { + span_lint(cx, BUFREADER_STDIN, expr.span, msg); + } else { + span_lint_and_sugg(cx, BUFREADER_STDIN, expr.span, msg, help, sugg, applicability); } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f1c2c2ae93b5..66b3fa9014cd 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -869,6 +869,7 @@ rustc_lint::late_lint_methods!( RedundantElse: redundant_else::RedundantElse = redundant_else::RedundantElse, RestWhenDestructuringStruct: rest_when_destructuring_struct::RestWhenDestructuringStruct = rest_when_destructuring_struct::RestWhenDestructuringStruct, BlockScrutinee: block_scrutinee::BlockScrutinee = block_scrutinee::BlockScrutinee, + BufreaderStdin: bufreader_stdin::BufreaderStdin = bufreader_stdin::BufreaderStdin::new(), // add late passes here, used by `cargo dev new_lint` ]] ); diff --git a/tests/ui/bufreader_stdin.fixed b/tests/ui/bufreader_stdin.fixed index 2984af523388..ebf94ec9187d 100644 --- a/tests/ui/bufreader_stdin.fixed +++ b/tests/ui/bufreader_stdin.fixed @@ -2,10 +2,17 @@ use std::io::{self, BufReader}; +macro_rules! stdin_macro { + () => { + io::stdin() + }; +} + fn main() { let a = io::stdin(); let reader = a.lock(); //~^ bufreader_stdin + let b = io::stdin().lock(); let reader = b; //~^ bufreader_stdin diff --git a/tests/ui/bufreader_stdin.rs b/tests/ui/bufreader_stdin.rs index 41d6cbd564cd..1f16b4a3b7ef 100644 --- a/tests/ui/bufreader_stdin.rs +++ b/tests/ui/bufreader_stdin.rs @@ -2,10 +2,17 @@ use std::io::{self, BufReader}; +macro_rules! stdin_macro { + () => { + io::stdin() + }; +} + fn main() { let a = io::stdin(); let reader = BufReader::new(a); //~^ bufreader_stdin + let b = io::stdin().lock(); let reader = BufReader::new(b); //~^ bufreader_stdin diff --git a/tests/ui/bufreader_stdin.stderr b/tests/ui/bufreader_stdin.stderr index 6190cd892453..cde280ae7182 100644 --- a/tests/ui/bufreader_stdin.stderr +++ b/tests/ui/bufreader_stdin.stderr @@ -1,5 +1,5 @@ -error: using `BufReader::new` with `Stdin` - --> tests/ui/bufreader_stdin.rs:7:18 +error: wrapping already buffered `Stdin` into a `BufReader` + --> tests/ui/bufreader_stdin.rs:13:18 | LL | let reader = BufReader::new(a); | ^^^^^^^^^^^^^^^^^ @@ -12,8 +12,8 @@ LL - let reader = BufReader::new(a); LL + let reader = a.lock(); | -error: using `BufReader::new` with `StdinLock` - --> tests/ui/bufreader_stdin.rs:10:18 +error: wrapping already buffered `StdinLock` into a `BufReader` + --> tests/ui/bufreader_stdin.rs:17:18 | LL | let reader = BufReader::new(b); | ^^^^^^^^^^^^^^^^^ help: instead of wrapping `StdinLock` in `BufReader`, use it directly: `b` From 0a8061712dccb1c482791501c19eecbb51562d80 Mon Sep 17 00:00:00 2001 From: JafarTano <81587305+JaafarTanoukhi@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:54:14 +0300 Subject: [PATCH 7/7] optimized get_diagnostic_item usage --- clippy_lints/src/bufreader_stdin.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/bufreader_stdin.rs b/clippy_lints/src/bufreader_stdin.rs index f95fa0cdfaa4..090e41fe6e01 100644 --- a/clippy_lints/src/bufreader_stdin.rs +++ b/clippy_lints/src/bufreader_stdin.rs @@ -63,20 +63,19 @@ impl<'tcx> LateLintPass<'tcx> for BufreaderStdin { Applicability::MaybeIncorrect }; - let (msg, help, sugg) = if cx.tcx.is_diagnostic_item(sym::Stdin, arg_did) { - ( + let arg_did_name = cx.tcx.get_diagnostic_name(arg_did); + let (msg, help, sugg) = match arg_did_name { + Some(sym::Stdin) => ( "wrapping already buffered `Stdin` into a `BufReader`", "instead of wrapping `Stdin` in `BufReader`, use the `lock` method directly", format!("{snip}.lock()"), - ) - } else if cx.tcx.is_diagnostic_item(sym::StdinLock, arg_did) { - ( + ), + Some(sym::StdinLock) => ( "wrapping already buffered `StdinLock` into a `BufReader`", "instead of wrapping `StdinLock` in `BufReader`, use it directly", snip.to_string(), - ) - } else { - return; + ), + _ => return, }; if arg.span.from_expansion() {