Replace all format!("{}", foo) calls
This commit is contained in:
parent
ef4401d4ac
commit
b6443b9928
5 changed files with 14 additions and 16 deletions
|
|
@ -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, "..")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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::<Vec<String>>();
|
||||
.map(|stmt| snippet(cx, stmt.span, ".."))
|
||||
.collect::<Vec<Cow<_>>>();
|
||||
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, ".."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -530,10 +530,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &Expr, name: &str, args: &[P<Expr>])
|
|||
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))
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue