From f3add4acb40faafda0f5727aaa2b9321eb97371a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 21 Aug 2018 12:46:18 +0200 Subject: [PATCH 1/2] convert "".to_string() and "".to_owned() to String::new() --- clippy_lints/src/else_if_without_else.rs | 2 +- clippy_lints/src/loops.rs | 8 ++++---- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/ranges.rs | 4 ++-- clippy_lints/src/swap.rs | 4 ++-- clippy_lints/src/types.rs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index 21a77e226..da6e860e2 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -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() ); } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 7472700dd..3adc43027 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -956,7 +956,7 @@ fn detect_manual_memcpy<'a, 'tcx>( return if offset.negate { format!("({} - {})", snippet(cx, end.span, ".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) { diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index f52d3ccf5..dcc4dca39 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -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, diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 6616099eb..6292af92e 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -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", diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 1c4092634..c6668288a 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -119,7 +119,7 @@ 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), @@ -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); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 2766ea58d..857238e90 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -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()) }; From 021748eb6a2fd86bd21e173cef04c19bdb456bb4 Mon Sep 17 00:00:00 2001 From: flip1995 <9744647+flip1995@users.noreply.github.com> Date: Sat, 15 Sep 2018 11:25:40 +0200 Subject: [PATCH 2/2] Replace another occurrence of "".to_owned() --- clippy_lints/src/swap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index c6668288a..cd3a7259a 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -125,7 +125,7 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) { (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);