Skip to content

Commit 5e0663e

Browse files
committed
Auto merge of rust-lang#9469 - Alexendoo:expr-field-visitor, r=giraffate
Fix FormatArgsExpn parsing of FormatSpec positions Woops, forgot visitors don't walk themselves Fixes rust-lang#9468 r? `@giraffate` changelog: none
2 parents 018b54b + bd9d375 commit 5e0663e

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

clippy_utils/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::visitors::expr_visitor_no_bodies;
77
use arrayvec::ArrayVec;
88
use itertools::{izip, Either, Itertools};
99
use rustc_ast::ast::LitKind;
10-
use rustc_hir::intravisit::Visitor;
10+
use rustc_hir::intravisit::{walk_expr, Visitor};
1111
use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, Node, QPath};
1212
use rustc_lexer::unescape::unescape_literal;
1313
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
@@ -515,7 +515,7 @@ impl<'tcx> Visitor<'tcx> for ParamPosition {
515515
sym::width => {
516516
self.width = parse_count(field.expr);
517517
},
518-
_ => {},
518+
_ => walk_expr(self, field.expr),
519519
}
520520
}
521521
}

tests/ui/explicit_write.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ fn main() {
3636
eprintln!("with {} {}", 2, value);
3737
eprintln!("with {value}");
3838
eprintln!("macro arg {}", one!());
39+
let width = 2;
40+
eprintln!("{:w$}", value, w = width);
3941
}
4042
// these should not warn, different destination
4143
{

tests/ui/explicit_write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ fn main() {
3636
writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
3737
writeln!(std::io::stderr(), "with {value}").unwrap();
3838
writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
39+
let width = 2;
40+
writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
3941
}
4042
// these should not warn, different destination
4143
{

tests/ui/explicit_write.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,11 @@ error: use of `writeln!(stderr(), ...).unwrap()`
7272
LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())`
7474

75-
error: aborting due to 12 previous errors
75+
error: use of `writeln!(stderr(), ...).unwrap()`
76+
--> $DIR/explicit_write.rs:40:9
77+
|
78+
LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("{:w$}", value, w = width)`
80+
81+
error: aborting due to 13 previous errors
7682

0 commit comments

Comments
 (0)