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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+61 −36
Diff settings

Always

Just for now

@@ -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() {}
@@ -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() {}
@@ -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

@@ -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();
@@ -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

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.