Skip to content

Commit

Permalink
Run rustfix for string_lit_as_bytes tests
Browse files Browse the repository at this point in the history
This moves the `string_lit_as_bytes` tests into a new file and enables
rustfix tests for them.
  • Loading branch information
phansch committed Mar 14, 2019
1 parent 99fdf26 commit 67aad6c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 36 deletions.
19 changes: 19 additions & 0 deletions tests/ui/string_lit_as_bytes.fixed
@@ -0,0 +1,19 @@
// run-rustfix

#![allow(dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]

fn str_lit_as_bytes() {
let bs = b"hello there";

let bs = br###"raw string with three ### in it and some " ""###;

// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();

let strify = stringify!(foobar).as_bytes();

let includestr = include_bytes!("entry.rs");
}

fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/string_lit_as_bytes.rs
@@ -0,0 +1,19 @@
// run-rustfix

#![allow(dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]

fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();

let bs = r###"raw string with three ### in it and some " ""###.as_bytes();

// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();

let strify = stringify!(foobar).as_bytes();

let includestr = include_str!("entry.rs").as_bytes();
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/string_lit_as_bytes.stderr
@@ -0,0 +1,22 @@
error: calling `as_bytes()` on a string literal
--> $DIR/string_lit_as_bytes.rs:7:14
|
LL | let bs = "hello there".as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"`
|
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`

error: calling `as_bytes()` on a string literal
--> $DIR/string_lit_as_bytes.rs:9:14
|
LL | let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with three ### in it and some " ""###`

error: calling `as_bytes()` on `include_str!(..)`
--> $DIR/string_lit_as_bytes.rs:16:22
|
LL | let includestr = include_str!("entry.rs").as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry.rs")`

error: aborting due to 3 previous errors

15 changes: 0 additions & 15 deletions tests/ui/strings.rs
Expand Up @@ -42,21 +42,6 @@ fn both() {
assert_eq!(&x, &z);
}

#[allow(dead_code, unused_variables)]
#[warn(clippy::string_lit_as_bytes)]
fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();

let bs = r###"raw string with three ### in it and some " ""###.as_bytes();

// no warning, because this cannot be written as a byte string literal:
let ubs = "☃".as_bytes();

let strify = stringify!(foobar).as_bytes();

let includestr = include_str!("entry.rs").as_bytes();
}

#[allow(clippy::assign_op_pattern)]
fn main() {
add_only();
Expand Down
22 changes: 1 addition & 21 deletions tests/ui/strings.stderr
Expand Up @@ -52,25 +52,5 @@ error: you added something to a string. Consider using `String::push_str()` inst
LL | let z = y + "...";
| ^^^^^^^^^

error: calling `as_bytes()` on a string literal
--> $DIR/strings.rs:48:14
|
LL | let bs = "hello there".as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"`
|
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`

error: calling `as_bytes()` on a string literal
--> $DIR/strings.rs:50:14
|
LL | let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with three ### in it and some " ""###`

error: calling `as_bytes()` on `include_str!(..)`
--> $DIR/strings.rs:57:22
|
LL | let includestr = include_str!("entry.rs").as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("entry.rs")`

error: aborting due to 11 previous errors
error: aborting due to 8 previous errors

0 comments on commit 67aad6c

Please sign in to comment.