diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 058a15590ab..2f371fe19b9 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -7,7 +7,7 @@ use crate::visitors::expr_visitor_no_bodies; use arrayvec::ArrayVec; use itertools::{izip, Either, Itertools}; use rustc_ast::ast::LitKind; -use rustc_hir::intravisit::Visitor; +use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, Node, QPath}; use rustc_lexer::unescape::unescape_literal; use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind}; @@ -515,7 +515,7 @@ impl<'tcx> Visitor<'tcx> for ParamPosition { sym::width => { self.width = parse_count(field.expr); }, - _ => {}, + _ => walk_expr(self, field.expr), } } } diff --git a/tests/ui/explicit_write.fixed b/tests/ui/explicit_write.fixed index 74d0e529028..35283725619 100644 --- a/tests/ui/explicit_write.fixed +++ b/tests/ui/explicit_write.fixed @@ -36,6 +36,8 @@ fn main() { eprintln!("with {} {}", 2, value); eprintln!("with {value}"); eprintln!("macro arg {}", one!()); + let width = 2; + eprintln!("{:w$}", value, w = width); } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs index e7a698d3e01..be864a55b66 100644 --- a/tests/ui/explicit_write.rs +++ b/tests/ui/explicit_write.rs @@ -36,6 +36,8 @@ fn main() { writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); writeln!(std::io::stderr(), "with {value}").unwrap(); writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); + let width = 2; + writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); } // these should not warn, different destination { diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index 29ae0cdece2..ff05f4343d7 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -72,5 +72,11 @@ error: use of `writeln!(stderr(), ...).unwrap()` LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())` -error: aborting due to 12 previous errors +error: use of `writeln!(stderr(), ...).unwrap()` + --> $DIR/explicit_write.rs:40:9 + | +LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("{:w$}", value, w = width)` + +error: aborting due to 13 previous errors