Skip to content

Commit

Permalink
Auto merge of #5672 - phansch:regression-test-env, r=yaahc
Browse files Browse the repository at this point in the history
Add regression test for `string_lit_as_bytes` issue

Closes #5619

Before the fix in rust-lang/rust#72637, `string_lit_as_bytes` was incorrectly triggering on the `env!` macro. With the fix merged, this test makes sure that the lint is not triggering anymore.

changelog: none
  • Loading branch information
bors committed Jun 2, 2020
2 parents 5cb9ef3 + ae0ce22 commit 153ef1c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/ui/string_lit_as_bytes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fn str_lit_as_bytes() {

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

let current_version = env!("CARGO_PKG_VERSION").as_bytes();

let includestr = include_bytes!("entry_unfixable.rs");

let _ = b"string with newline\t\n";
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/string_lit_as_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fn str_lit_as_bytes() {

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

let current_version = env!("CARGO_PKG_VERSION").as_bytes();

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

let _ = "string with newline\t\n".as_bytes();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/string_lit_as_bytes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ LL | let bs = r###"raw string with 3# plus " ""###.as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###`

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

error: calling `as_bytes()` on a string literal
--> $DIR/string_lit_as_bytes.rs:19:13
--> $DIR/string_lit_as_bytes.rs:21:13
|
LL | let _ = "string with newline/t/n".as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"`
Expand Down

0 comments on commit 153ef1c

Please sign in to comment.