Skip to content

Commit 153ef1c

Browse files
committed
Auto merge of #5672 - phansch:regression-test-env, r=yaahc
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
2 parents 5cb9ef3 + ae0ce22 commit 153ef1c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

tests/ui/string_lit_as_bytes.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fn str_lit_as_bytes() {
1414

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

17+
let current_version = env!("CARGO_PKG_VERSION").as_bytes();
18+
1719
let includestr = include_bytes!("entry_unfixable.rs");
1820

1921
let _ = b"string with newline\t\n";

tests/ui/string_lit_as_bytes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fn str_lit_as_bytes() {
1414

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

17+
let current_version = env!("CARGO_PKG_VERSION").as_bytes();
18+
1719
let includestr = include_str!("entry_unfixable.rs").as_bytes();
1820

1921
let _ = "string with newline\t\n".as_bytes();

tests/ui/string_lit_as_bytes.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ LL | let bs = r###"raw string with 3# plus " ""###.as_bytes();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###`
1414

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

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

0 commit comments

Comments
 (0)