about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-12 13:58:53 +0000
committerbors <bors@rust-lang.org>2022-09-12 13:58:53 +0000
commit5e0663e25ca956380002c0703c59e8e7323add2d (patch)
tree23e2a0b1e317312260cce36c4f97a45fe6de8232
parent018b54b33beaeaecfeb5bdb775f9ce6410daa3ef (diff)
parentbd9d375c6b935bb536502d2c47410db319d5e0a8 (diff)
downloadrust-5e0663e25ca956380002c0703c59e8e7323add2d.tar.gz
rust-5e0663e25ca956380002c0703c59e8e7323add2d.zip
Auto merge of #9469 - Alexendoo:expr-field-visitor, r=giraffate
Fix FormatArgsExpn parsing of FormatSpec positions

Woops, forgot visitors don't walk themselves

Fixes #9468

r? `@giraffate`

changelog: none
-rw-r--r--clippy_utils/src/macros.rs4
-rw-r--r--tests/ui/explicit_write.fixed2
-rw-r--r--tests/ui/explicit_write.rs2
-rw-r--r--tests/ui/explicit_write.stderr8
4 files changed, 13 insertions, 3 deletions
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