]> git.lizzy.rs Git - rust.git/commitdiff
convert "".to_string() and "".to_owned() to String::new()
authorMatthias Krüger <matthias.krueger@famsik.de>
Tue, 21 Aug 2018 10:46:18 +0000 (12:46 +0200)
committerflip1995 <9744647+flip1995@users.noreply.github.com>
Sat, 15 Sep 2018 09:20:35 +0000 (11:20 +0200)
clippy_lints/src/else_if_without_else.rs
clippy_lints/src/loops.rs
clippy_lints/src/misc.rs
clippy_lints/src/ranges.rs
clippy_lints/src/swap.rs
clippy_lints/src/types.rs

index 21a77e2263f7d0acdfce6dc1e1e5914803250af8..da6e860e236ce92ba4cce85dcab52d5a1e42c7a6 100644 (file)
@@ -62,7 +62,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) {
                     els.span,
                     "if expression with an `else if`, but without a final `else`",
                     "add an `else` block here",
                     els.span,
                     "if expression with an `else if`, but without a final `else`",
                     "add an `else` block here",
-                    "".to_string()
+                    String::new()
                 );
             }
 
                 );
             }
 
index 7472700ddbc2b1728c4c72412b5ff212c205f557..3adc4302730ff311405857da33ca23a40743c68c 100644 (file)
@@ -956,7 +956,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
                         return if offset.negate {
                             format!("({} - {})", snippet(cx, end.span, "<src>.len()"), offset.value)
                         } else {
                         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 {
                 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) {
                 } 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 => {
                     } else {
                         match limits {
                             ast::RangeLimits::Closed => {
@@ -1085,7 +1085,7 @@ fn check_for_loop_range<'a, 'tcx>(
                         }
                     }
                 } else {
                         }
                     }
                 } else {
-                    "".to_owned()
+                    String::new()
                 };
 
                 let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) {
                 };
 
                 let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) {
index f52d3ccf5a4cc41830f979cdfe8a27fd4fa5b8a7..dcc4dca392975babb357f2f450d52b666a14d82f 100644 (file)
@@ -287,7 +287,7 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
                     let tyopt = if let Some(ref ty) = l.ty {
                         format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
                     } else {
                     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,
                     };
                     span_lint_and_then(cx,
                         TOPLEVEL_REF_ARG,
index 6616099eb9e67f241d0d2337c0c19f3fda772588..6292af92e260219a348353cdd086157bc302e2f0 100644 (file)
@@ -146,7 +146,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     expr.span,
                     "an inclusive range would be more readable",
                     |db| {
                     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(')') {
                         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 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     expr.span,
                     "an exclusive range would be more readable",
                     |db| {
                     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",
                         let end = Sugg::hir(cx, y, "y");
                         db.span_suggestion(expr.span,
                                            "use",
index 1c4092634994b2e3c85abb33f7b28b39f71c40f1..c6668288a556ee307f46e3350af9f6c668c2e955 100644 (file)
@@ -119,7 +119,7 @@ fn check_for_slice<'a>(
                                  snippet(cx, idx1.span, ".."),
                                  snippet(cx, idx2.span, "..")))
                     } else {
                                  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),
                     }
                 } 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 {
                         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);
                 };
 
                 let span = first.span.to(second.span);
index 2766ea58d2d24a9673a47903601d5a51c92f6b2a..857238e9002bf5a8092c2f02c3701df94f42889a 100644 (file)
@@ -319,7 +319,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt:
                     }
 
                     let ltopt = if lt.is_elided() {
                     }
 
                     let ltopt = if lt.is_elided() {
-                        "".to_owned()
+                        String::new()
                     } else {
                         format!("{} ", lt.name.ident().name.as_str())
                     };
                     } else {
                         format!("{} ", lt.name.ident().name.as_str())
                     };