Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run rustfix for string_lit_as_bytes tests #3879

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ui/string_lit_as_bytes.fixed
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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