Skip to content

convert "".to_string() and "".to_owned() to String::new() #3068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/else_if_without_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
}
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(')') {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
};
Expand Down