mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Ignore format!
with precision in USELESS_FORMAT
This commit is contained in:
parent
d18c7b2722
commit
7eebd5b20c
2 changed files with 12 additions and 4 deletions
|
@ -47,7 +47,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
return;
|
||||
}
|
||||
match expr.node {
|
||||
|
||||
// `format!("{}", foo)` expansion
|
||||
ExprKind::Call(ref fun, ref args) => {
|
||||
if_chain! {
|
||||
|
@ -162,9 +161,12 @@ fn check_unformatted(expr: &Expr) -> bool {
|
|||
if let ExprKind::Struct(_, ref fields, _) = exprs[0].node;
|
||||
if let Some(format_field) = fields.iter().find(|f| f.ident.name == "format");
|
||||
if let ExprKind::Struct(_, ref fields, _) = format_field.expr.node;
|
||||
if let Some(align_field) = fields.iter().find(|f| f.ident.name == "width");
|
||||
if let ExprKind::Path(ref qpath) = align_field.expr.node;
|
||||
if last_path_segment(qpath).ident.name == "Implied";
|
||||
if let Some(width_field) = fields.iter().find(|f| f.ident.name == "width");
|
||||
if let ExprKind::Path(ref width_qpath) = width_field.expr.node;
|
||||
if last_path_segment(width_qpath).ident.name == "Implied";
|
||||
if let Some(precision_field) = fields.iter().find(|f| f.ident.name == "precision");
|
||||
if let ExprKind::Path(ref precision_path) = precision_field.expr.node;
|
||||
if last_path_segment(precision_path).ident.name == "Implied";
|
||||
then {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -46,4 +46,10 @@ fn main() {
|
|||
|
||||
// A format! inside a macro should not trigger a warning
|
||||
foo!("should not warn");
|
||||
|
||||
// precision on string means slicing without panicking on size:
|
||||
format!("{:.1}", "foo"); // could be "foo"[..1]
|
||||
format!("{:.10}", "foo"); // could not be "foo"[..10]
|
||||
format!("{:.prec$}", "foo", prec = 1);
|
||||
format!("{:.prec$}", "foo", prec = 10);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue