-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
61 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters