]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/format.rs
Merge pull request #3465 from flip1995/rustfmt
[rust.git] / clippy_lints / src / format.rs
index bd9fa6f80be38d73fb639753af748d43759b5ed1..ac80580b14820c9dc1d0b51b9aa2deeb557c5d8e 100644 (file)
@@ -7,16 +7,18 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
 use crate::rustc::hir::*;
 use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use if_chain::if_chain;
 use crate::rustc::ty;
+use crate::rustc::{declare_tool_lint, lint_array};
+use crate::rustc_errors::Applicability;
 use crate::syntax::ast::LitKind;
 use crate::utils::paths;
-use crate::utils::{in_macro, is_expn_of, last_path_segment, match_def_path, match_type, opt_def_id, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty};
-use crate::rustc_errors::Applicability;
+use crate::utils::{
+    in_macro, is_expn_of, last_path_segment, match_def_path, match_type, opt_def_id, resolve_node, snippet,
+    span_lint_and_then, walk_ptrs_ty,
+};
+use if_chain::if_chain;
 
 /// **What it does:** Checks for the use of `format!("string literal with no
 /// argument")` and `format!("{}", foo)` where `foo` is a string.
@@ -92,17 +94,19 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     }
                 },
                 // `format!("foo")` expansion contains `match () { () => [], }`
-                ExprKind::Match(ref matchee, _, _) => if let ExprKind::Tup(ref tup) = matchee.node {
-                    if tup.is_empty() {
-                        let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned());
-                        span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
-                            db.span_suggestion_with_applicability(
-                                span,
-                                "consider using .to_string()",
-                                sugg,
-                                Applicability::MachineApplicable, // snippet
-                            );
-                        });
+                ExprKind::Match(ref matchee, _, _) => {
+                    if let ExprKind::Tup(ref tup) = matchee.node {
+                        if tup.is_empty() {
+                            let sugg = format!("{}.to_string()", snippet(cx, expr.span, "<expr>").into_owned());
+                            span_lint_and_then(cx, USELESS_FORMAT, span, "useless use of `format!`", |db| {
+                                db.span_suggestion_with_applicability(
+                                    span,
+                                    "consider using .to_string()",
+                                    sugg,
+                                    Applicability::MachineApplicable, // snippet
+                                );
+                            });
+                        }
                     }
                 },
                 _ => (),