diff --git a/src/collapsible_if.rs b/src/collapsible_if.rs index e5ad94fc6398..663d39cdbb2f 100644 --- a/src/collapsible_if.rs +++ b/src/collapsible_if.rs @@ -14,6 +14,7 @@ use rustc::lint::*; use rustc_front::hir::*; +use std::borrow::Cow; use syntax::codemap::Spanned; use utils::{in_macro, snippet, snippet_block, span_lint_and_then}; @@ -95,11 +96,11 @@ fn requires_brackets(e: &Expr) -> bool { } } -fn check_to_string(cx: &LateContext, e: &Expr) -> String { +fn check_to_string(cx: &LateContext, e: &Expr) -> Cow<'static, str> { if requires_brackets(e) { - format!("({})", snippet(cx, e.span, "..")) + format!("({})", snippet(cx, e.span, "..")).into() } else { - format!("{}", snippet(cx, e.span, "..")) + snippet(cx, e.span, "..") } } diff --git a/src/loops.rs b/src/loops.rs index 9e5745950dd7..fff73f907f07 100644 --- a/src/loops.rs +++ b/src/loops.rs @@ -245,13 +245,13 @@ impl LateLintPass for LoopsPass { let mut other_stuff = block.stmts .iter() .skip(1) - .map(|stmt| format!("{}", snippet(cx, stmt.span, ".."))) - .collect::>(); + .map(|stmt| snippet(cx, stmt.span, "..")) + .collect::>>(); if inner_stmt_expr.is_some() { // if we have a statement which has a match, if let Some(ref expr) = block.expr { // then collect the expression (without semicolon) below it - other_stuff.push(format!("{}", snippet(cx, expr.span, ".."))); + other_stuff.push(snippet(cx, expr.span, "..")); } } diff --git a/src/methods.rs b/src/methods.rs index f776d5890b79..1d529e175db5 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -530,10 +530,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P]) return; } - let sugg = match (fn_has_arguments, !or_has_args) { - (true, _) => format!("|_| {}", snippet(cx, arg.span, "..")), - (false, false) => format!("|| {}", snippet(cx, arg.span, "..")), - (false, true) => format!("{}", snippet(cx, fun.span, "..")), + let sugg: Cow<_> = match (fn_has_arguments, !or_has_args) { + (true, _) => format!("|_| {}", snippet(cx, arg.span, "..")).into(), + (false, false) => format!("|| {}", snippet(cx, arg.span, "..")).into(), + (false, true) => snippet(cx, fun.span, ".."), }; span_lint(cx, OR_FUN_CALL, span, &format!("use of `{}` followed by a function call", name)) diff --git a/src/misc_early.rs b/src/misc_early.rs index 28d5fb65f36a..bbed9ad4996b 100644 --- a/src/misc_early.rs +++ b/src/misc_early.rs @@ -45,10 +45,7 @@ impl EarlyLintPass for MiscEarly { fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) { if let PatKind::Struct(ref npat, ref pfields, _) = pat.node { let mut wilds = 0; - let type_name = match npat.segments.last() { - Some(elem) => format!("{}", elem.identifier.name), - None => String::new(), - }; + let type_name = npat.segments.last().expect("A path must have at least one segment").identifier.name; for field in pfields { if field.node.pat.node == PatKind::Wild { diff --git a/src/mut_reference.rs b/src/mut_reference.rs index 35904533719d..ea2c00bab94e 100644 --- a/src/mut_reference.rs +++ b/src/mut_reference.rs @@ -39,13 +39,13 @@ impl LateLintPass for UnnecessaryMutPassed { If this happened, the compiler would have \ aborted the compilation long ago"); if let ExprPath(_, ref path) = fn_expr.node { - check_arguments(cx, &arguments, function_type, &format!("{}", path)); + check_arguments(cx, &arguments, function_type, &path.to_string()); } } ExprMethodCall(ref name, _, ref arguments) => { let method_call = MethodCall::expr(e.id); let method_type = borrowed_table.method_map.get(&method_call).expect("This should never happen."); - check_arguments(cx, &arguments, method_type.ty, &format!("{}", name.node.as_str())) + check_arguments(cx, &arguments, method_type.ty, &name.node.as_str()) } _ => {} }