X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fformat.rs;h=ac80580b14820c9dc1d0b51b9aa2deeb557c5d8e;hb=f5831523d335bc57a6371806b2ea1978942ac490;hp=bd9fa6f80be38d73fb639753af748d43759b5ed1;hpb=93324f1acfc1929b935f9fdfec5a0a319679fca5;p=rust.git diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index bd9fa6f80be..ac80580b148 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -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, "").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, "").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 + ); + }); + } } }, _ => (),