Skip to content

Commit 1bf8841

Browse files
Update all tests to comply with clippy::manual_empty_string_creations
1 parent 80826c3 commit 1bf8841

23 files changed

+40
-38
lines changed

clippy_dev/src/new_lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn to_camel_case(name: &str) -> String {
155155
name.split('_')
156156
.map(|s| {
157157
if s.is_empty() {
158-
String::from("")
158+
String::new()
159159
} else {
160160
[&s[0..1].to_uppercase(), &s[1..]].concat()
161161
}

clippy_lints/src/manual_async_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str,
192192
match output.kind {
193193
TyKind::Tup(tys) if tys.is_empty() => {
194194
let sugg = "remove the return type";
195-
Some((sugg, "".into()))
195+
Some((sugg, String::new()))
196196
},
197197
_ => {
198198
let sugg = "return the output of the future directly";

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(super) fn check<'tcx>(
7878
map_span,
7979
String::from(if unwrap_snippet_none { "and_then" } else { "map_or" }),
8080
),
81-
(expr.span.with_lo(unwrap_recv.span.hi()), String::from("")),
81+
(expr.span.with_lo(unwrap_recv.span.hi()), String::new()),
8282
];
8383

8484
if !unwrap_snippet_none {

clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
4646
"these patterns are unneeded as the `..` pattern can match those elements"
4747
},
4848
if only_one { "remove it" } else { "remove them" },
49-
"".to_string(),
49+
String::new(),
5050
Applicability::MachineApplicable,
5151
);
5252
}

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
130130
(
131131
ret_expr.span,
132132
if inner_type.is_unit() {
133-
"".to_string()
133+
String::new()
134134
} else {
135135
snippet(cx, arg.span.source_callsite(), "..").to_string()
136136
}

tests/ui/case_sensitive_file_extension_comparisons.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ fn is_rust_file(filename: &str) -> bool {
1414

1515
fn main() {
1616
// std::string::String and &str should trigger the lint failure with .ext12
17-
let _ = String::from("").ends_with(".ext12");
17+
let _ = String::new().ends_with(".ext12");
1818
let _ = "str".ends_with(".ext12");
1919

2020
// The test struct should not trigger the lint failure with .ext12
2121
TestStruct {}.ends_with(".ext12");
2222

2323
// std::string::String and &str should trigger the lint failure with .EXT12
24-
let _ = String::from("").ends_with(".EXT12");
24+
let _ = String::new().ends_with(".EXT12");
2525
let _ = "str".ends_with(".EXT12");
2626

2727
// The test struct should not trigger the lint failure with .EXT12
2828
TestStruct {}.ends_with(".EXT12");
2929

3030
// Should not trigger the lint failure with .eXT12
31-
let _ = String::from("").ends_with(".eXT12");
31+
let _ = String::new().ends_with(".eXT12");
3232
let _ = "str".ends_with(".eXT12");
3333
TestStruct {}.ends_with(".eXT12");
3434

3535
// Should not trigger the lint failure with .EXT123 (too long)
36-
let _ = String::from("").ends_with(".EXT123");
36+
let _ = String::new().ends_with(".EXT123");
3737
let _ = "str".ends_with(".EXT123");
3838
TestStruct {}.ends_with(".EXT123");
3939

4040
// Shouldn't fail if it doesn't start with a dot
41-
let _ = String::from("").ends_with("a.ext");
41+
let _ = String::new().ends_with("a.ext");
4242
let _ = "str".ends_with("a.extA");
4343
TestStruct {}.ends_with("a.ext");
4444
}

tests/ui/case_sensitive_file_extension_comparisons.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | filename.ends_with(".rs")
88
= help: consider using a case-insensitive comparison instead
99

1010
error: case-sensitive file extension comparison
11-
--> $DIR/case_sensitive_file_extension_comparisons.rs:17:30
11+
--> $DIR/case_sensitive_file_extension_comparisons.rs:17:27
1212
|
13-
LL | let _ = String::from("").ends_with(".ext12");
14-
| ^^^^^^^^^^^^^^^^^^^
13+
LL | let _ = String::new().ends_with(".ext12");
14+
| ^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: consider using a case-insensitive comparison instead
1717

@@ -24,10 +24,10 @@ LL | let _ = "str".ends_with(".ext12");
2424
= help: consider using a case-insensitive comparison instead
2525

2626
error: case-sensitive file extension comparison
27-
--> $DIR/case_sensitive_file_extension_comparisons.rs:24:30
27+
--> $DIR/case_sensitive_file_extension_comparisons.rs:24:27
2828
|
29-
LL | let _ = String::from("").ends_with(".EXT12");
30-
| ^^^^^^^^^^^^^^^^^^^
29+
LL | let _ = String::new().ends_with(".EXT12");
30+
| ^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: consider using a case-insensitive comparison instead
3333

tests/ui/format.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() {
3333
format!("foo {}", "bar");
3434
format!("{} bar", "foo");
3535

36-
let arg: String = "".to_owned();
36+
let arg = String::new();
3737
arg.to_string();
3838
format!("{:?}", arg); // Don't warn about debug.
3939
format!("{:8}", arg);

tests/ui/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() {
3535
format!("foo {}", "bar");
3636
format!("{} bar", "foo");
3737

38-
let arg: String = "".to_owned();
38+
let arg = String::new();
3939
format!("{}", arg);
4040
format!("{:?}", arg); // Don't warn about debug.
4141
format!("{:8}", arg);

tests/ui/identity_op.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() {
6868
&x;
6969
x;
7070

71-
let mut a = A("".into());
71+
let mut a = A(String::new());
7272
let b = a << 0; // no error: non-integer
7373

7474
1 * Meter; // no error: non-integer

0 commit comments

Comments
 (0)