about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpro-grammer1 <1df0d0d3-eed4-45fc-bc60-43a85079f3f9@anonaddy.me>2020-12-01 09:44:43 +0000
committerpro-grammer1 <1df0d0d3-eed4-45fc-bc60-43a85079f3f9@anonaddy.me>2020-12-01 09:44:43 +0000
commit415394c3fc0e008026b3f2a37fbd57a58449b4d3 (patch)
tree626c30cde21110cda9b5a8db051f9d828115fb68
parent68cf94f6a66e47234e3adefc6dfbe806cd6ad164 (diff)
downloadrust-415394c3fc0e008026b3f2a37fbd57a58449b4d3.tar.gz
rust-415394c3fc0e008026b3f2a37fbd57a58449b4d3.zip
Fix false positive in write_literal and print_literal due to numeric literals
-rw-r--r--clippy_lints/src/write.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs
index ff414f748ef..78d23e1e0ef 100644
--- a/clippy_lints/src/write.rs
+++ b/clippy_lints/src/write.rs
@@ -2,7 +2,8 @@ use std::borrow::Cow;
 use std::ops::Range;
 
 use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then};
-use rustc_ast::ast::{Expr, ExprKind, Item, ItemKind, MacCall, StrLit, StrStyle};
+use if_chain::if_chain;
+use rustc_ast::ast::{Expr, ExprKind, Item, ItemKind, LitKind, MacCall, StrLit, StrStyle};
 use rustc_ast::token;
 use rustc_ast::tokenstream::TokenStream;
 use rustc_errors::Applicability;
@@ -442,7 +443,12 @@ impl Write {
                 return (Some(fmtstr), None);
             };
             match &token_expr.kind {
-                ExprKind::Lit(_) => {
+                ExprKind::Lit(lit)
+                    if match lit.kind {
+                        LitKind::Int(_, _) | LitKind::Float(_, _) => false,
+                        _ => true,
+                    } =>
+                {
                     let mut all_simple = true;
                     let mut seen = false;
                     for arg in &args {
@@ -460,10 +466,16 @@ impl Write {
                         span_lint(cx, lint, token_expr.span, "literal with an empty format string");
                     }
                     idx += 1;
-                },
+                }
                 ExprKind::Assign(lhs, rhs, _) => {
-                    if let ExprKind::Lit(_) = rhs.kind {
-                        if let ExprKind::Path(_, p) = &lhs.kind {
+                    if_chain! {
+                        if let ExprKind::Lit(ref lit) = rhs.kind;
+                        if match lit.kind {
+                            LitKind::Int(_, _) | LitKind::Float(_, _) => false,
+                            _ => true,
+                        };
+                        if let ExprKind::Path(_, p) = &lhs.kind;
+                        then {
                             let mut all_simple = true;
                             let mut seen = false;
                             for arg in &args {