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
This commit is contained in:
bors 2022-09-12 13:58:53 +00:00
commit 5e0663e25c
4 changed files with 13 additions and 3 deletions

View File

@ -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),
}
}
}

View File

@ -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
{

View File

@ -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
{

View File

@ -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