Skip to content

Commit bb41b16

Browse files
committed
Auto merge of #3879 - phansch:rustfix_string_lit_as_bytes, r=flip1995
Run rustfix for string_lit_as_bytes tests This moves the `string_lit_as_bytes` tests into a new file and enables rustfix tests for them. cc #3603, #2038
2 parents 9df3811 + 67aad6c commit bb41b16

File tree

5 files changed

+61
-36
lines changed

5 files changed

+61
-36
lines changed

tests/ui/string_lit_as_bytes.fixed

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
3+
#![allow(dead_code, unused_variables)]
4+
#![warn(clippy::string_lit_as_bytes)]
5+
6+
fn str_lit_as_bytes() {
7+
let bs = b"hello there";
8+
9+
let bs = br###"raw string with three ### in it and some " ""###;
10+
11+
// no warning, because this cannot be written as a byte string literal:
12+
let ubs = "☃".as_bytes();
13+
14+
let strify = stringify!(foobar).as_bytes();
15+
16+
let includestr = include_bytes!("entry.rs");
17+
}
18+
19+
fn main() {}

tests/ui/string_lit_as_bytes.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
3+
#![allow(dead_code, unused_variables)]
4+
#![warn(clippy::string_lit_as_bytes)]
5+
6+
fn str_lit_as_bytes() {
7+
let bs = "hello there".as_bytes();
8+
9+
let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
10+
11+
// no warning, because this cannot be written as a byte string literal:
12+
let ubs = "☃".as_bytes();
13+
14+
let strify = stringify!(foobar).as_bytes();
15+
16+
let includestr = include_str!("entry.rs").as_bytes();
17+
}
18+
19+
fn main() {}

tests/ui/string_lit_as_bytes.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: calling `as_bytes()` on a string literal
2+
--> $DIR/string_lit_as_bytes.rs:7:14
3+
|
4+
LL | let bs = "hello there".as_bytes();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"`
6+
|
7+
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
8+
9+
error: calling `as_bytes()` on a string literal
10+
--> $DIR/string_lit_as_bytes.rs:9:14
11+
|
12+
LL | let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with three ### in it and some " ""###`
14+
15+
error: calling `as_bytes()` on `include_str!(..)`
16+
--> $DIR/string_lit_as_bytes.rs:16:22
17+
|
18+
LL | let includestr = include_str!("entry.rs").as_bytes();
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry.rs")`
20+
21+
error: aborting due to 3 previous errors
22+

tests/ui/strings.rs

-15
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ fn both() {
4242
assert_eq!(&x, &z);
4343
}
4444

45-
#[allow(dead_code, unused_variables)]
46-
#[warn(clippy::string_lit_as_bytes)]
47-
fn str_lit_as_bytes() {
48-
let bs = "hello there".as_bytes();
49-
50-
let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
51-
52-
// no warning, because this cannot be written as a byte string literal:
53-
let ubs = "☃".as_bytes();
54-
55-
let strify = stringify!(foobar).as_bytes();
56-
57-
let includestr = include_str!("entry.rs").as_bytes();
58-
}
59-
6045
#[allow(clippy::assign_op_pattern)]
6146
fn main() {
6247
add_only();

tests/ui/strings.stderr

+1-21
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,5 @@ error: you added something to a string. Consider using `String::push_str()` inst
5252
LL | let z = y + "...";
5353
| ^^^^^^^^^
5454

55-
error: calling `as_bytes()` on a string literal
56-
--> $DIR/strings.rs:48:14
57-
|
58-
LL | let bs = "hello there".as_bytes();
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"`
60-
|
61-
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
62-
63-
error: calling `as_bytes()` on a string literal
64-
--> $DIR/strings.rs:50:14
65-
|
66-
LL | let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with three ### in it and some " ""###`
68-
69-
error: calling `as_bytes()` on `include_str!(..)`
70-
--> $DIR/strings.rs:57:22
71-
|
72-
LL | let includestr = include_str!("entry.rs").as_bytes();
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry.rs")`
74-
75-
error: aborting due to 11 previous errors
55+
error: aborting due to 8 previous errors
7656

0 commit comments

Comments
 (0)