Skip to content

Commit fbb6b13

Browse files
authored
Merge pull request #3068 from matthiaskrgr/string
convert "".to_string() and "".to_owned() to String::new()
2 parents f166b7d + 021748e commit fbb6b13

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

clippy_lints/src/else_if_without_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
6262
els.span,
6363
"if expression with an `else if`, but without a final `else`",
6464
"add an `else` block here",
65-
"".to_string()
65+
String::new()
6666
);
6767
}
6868

clippy_lints/src/loops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
956956
return if offset.negate {
957957
format!("({} - {})", snippet(cx, end.span, "<src>.len()"), offset.value)
958958
} else {
959-
"".to_owned()
959+
String::new()
960960
};
961961
}
962962
}
@@ -1067,14 +1067,14 @@ fn check_for_loop_range<'a, 'tcx>(
10671067
let starts_at_zero = is_integer_literal(start, 0);
10681068

10691069
let skip = if starts_at_zero {
1070-
"".to_owned()
1070+
String::new()
10711071
} else {
10721072
format!(".skip({})", snippet(cx, start.span, ".."))
10731073
};
10741074

10751075
let take = if let Some(end) = *end {
10761076
if is_len_call(end, indexed) {
1077-
"".to_owned()
1077+
String::new()
10781078
} else {
10791079
match limits {
10801080
ast::RangeLimits::Closed => {
@@ -1085,7 +1085,7 @@ fn check_for_loop_range<'a, 'tcx>(
10851085
}
10861086
}
10871087
} else {
1088-
"".to_owned()
1088+
String::new()
10891089
};
10901090

10911091
let (ref_mut, method) = if visitor.indexed_mut.contains(&indexed) {

clippy_lints/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
287287
let tyopt = if let Some(ref ty) = l.ty {
288288
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, "_"))
289289
} else {
290-
"".to_owned()
290+
String::new()
291291
};
292292
span_lint_and_then(cx,
293293
TOPLEVEL_REF_ARG,

clippy_lints/src/ranges.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
146146
expr.span,
147147
"an inclusive range would be more readable",
148148
|db| {
149-
let start = start.map_or("".to_owned(), |x| Sugg::hir(cx, x, "x").to_string());
149+
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
150150
let end = Sugg::hir(cx, y, "y");
151151
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
152152
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
@@ -175,7 +175,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
175175
expr.span,
176176
"an exclusive range would be more readable",
177177
|db| {
178-
let start = start.map_or("".to_owned(), |x| Sugg::hir(cx, x, "x").to_string());
178+
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
179179
let end = Sugg::hir(cx, y, "y");
180180
db.span_suggestion(expr.span,
181181
"use",

clippy_lints/src/swap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
119119
snippet(cx, idx1.span, ".."),
120120
snippet(cx, idx2.span, "..")))
121121
} else {
122-
(false, "".to_owned(), "".to_owned())
122+
(false, String::new(), String::new())
123123
}
124124
} else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) {
125125
(true, format!(" `{}` and `{}`", first, second),
126126
format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr()))
127127
} else {
128-
(true, "".to_owned(), "".to_owned())
128+
(true, String::new(), String::new())
129129
};
130130

131131
let span = w[0].span.to(second.span);
@@ -169,7 +169,7 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
169169
second.mut_addr().to_string(),
170170
)
171171
} else {
172-
("".to_owned(), "".to_owned(), "".to_owned())
172+
(String::new(), String::new(), String::new())
173173
};
174174

175175
let span = first.span.to(second.span);

clippy_lints/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt:
319319
}
320320

321321
let ltopt = if lt.is_elided() {
322-
"".to_owned()
322+
String::new()
323323
} else {
324324
format!("{} ", lt.name.ident().name.as_str())
325325
};

0 commit comments

Comments
 (0)