Skip to content

Commit

Permalink
Auto merge of rust-lang#9469 - Alexendoo:expr-field-visitor, r=giraffate
Browse files Browse the repository at this point in the history
Fix FormatArgsExpn parsing of FormatSpec positions

Woops, forgot visitors don't walk themselves

Fixes rust-lang#9468

r? `@giraffate`

changelog: none
  • Loading branch information
bors committed Sep 12, 2022
2 parents 018b54b + bd9d375 commit 5e0663e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clippy_utils/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -515,7 +515,7 @@ impl<'tcx> Visitor<'tcx> for ParamPosition {
sym::width => {
self.width = parse_count(field.expr);
},
_ => {},
_ => walk_expr(self, field.expr),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/explicit_write.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/explicit_write.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e0663e

Please sign in to comment.