Merge pull request #3068 from matthiaskrgr/string
convert "".to_string() and "".to_owned() to String::new()
This commit is contained in:
commit
fbb6b13140
@ -62,7 +62,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
|
||||
els.span,
|
||||
"if expression with an `else if`, but without a final `else`",
|
||||
"add an `else` block here",
|
||||
"".to_string()
|
||||
String::new()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -956,7 +956,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
||||
return if offset.negate {
|
||||
format!("({} - {})", snippet(cx, end.span, "<src>.len()"), offset.value)
|
||||
} else {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1067,14 +1067,14 @@ fn check_for_loop_range<'a, 'tcx>(
|
||||
let starts_at_zero = is_integer_literal(start, 0);
|
||||
|
||||
let skip = if starts_at_zero {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
} else {
|
||||
format!(".skip({})", snippet(cx, start.span, ".."))
|
||||
};
|
||||
|
||||
let take = if let Some(end) = *end {
|
||||
if is_len_call(end, indexed) {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
} else {
|
||||
match limits {
|
||||
ast::RangeLimits::Closed => {
|
||||
@ -1085,7 +1085,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
};
|
||||
|
||||
let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) {
|
||||
|
@ -287,7 +287,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
let tyopt = if let Some(ref ty) = l.ty {
|
||||
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
|
||||
} else {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
};
|
||||
span_lint_and_then(cx,
|
||||
TOPLEVEL_REF_ARG,
|
||||
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
expr.span,
|
||||
"an inclusive range would be more readable",
|
||||
|db| {
|
||||
let start = start.map_or("".to_owned(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||
let end = Sugg::hir(cx, y, "y");
|
||||
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
|
||||
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
|
||||
@ -175,7 +175,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
expr.span,
|
||||
"an exclusive range would be more readable",
|
||||
|db| {
|
||||
let start = start.map_or("".to_owned(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
|
||||
let end = Sugg::hir(cx, y, "y");
|
||||
db.span_suggestion(expr.span,
|
||||
"use",
|
||||
|
@ -119,13 +119,13 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
snippet(cx, idx1.span, ".."),
|
||||
snippet(cx, idx2.span, "..")))
|
||||
} else {
|
||||
(false, "".to_owned(), "".to_owned())
|
||||
(false, String::new(), String::new())
|
||||
}
|
||||
} else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) {
|
||||
(true, format!(" `{}` and `{}`", first, second),
|
||||
format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr()))
|
||||
} else {
|
||||
(true, "".to_owned(), "".to_owned())
|
||||
(true, String::new(), String::new())
|
||||
};
|
||||
|
||||
let span = w[0].span.to(second.span);
|
||||
@ -169,7 +169,7 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
second.mut_addr().to_string(),
|
||||
)
|
||||
} else {
|
||||
("".to_owned(), "".to_owned(), "".to_owned())
|
||||
(String::new(), String::new(), String::new())
|
||||
};
|
||||
|
||||
let span = first.span.to(second.span);
|
||||
|
@ -319,7 +319,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt:
|
||||
}
|
||||
|
||||
let ltopt = if lt.is_elided() {
|
||||
"".to_owned()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{} ", lt.name.ident().name.as_str())
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user