diff options
| author | Centri3 <114838443+Centri3@users.noreply.github.com> | 2023-04-18 02:14:00 -0500 |
|---|---|---|
| committer | Centri3 <114838443+Centri3@users.noreply.github.com> | 2023-04-25 05:06:11 -0500 |
| commit | acfb2c45ba337b3265ab35dee5c94d3641c3ccf7 (patch) | |
| tree | 362ba53ffa1d98dd5a86e39d2b4b43cb6c88bc05 /tests | |
| parent | c4f2c48d9bed4146b1b317e17854f1cefcaf0f42 (diff) | |
| download | rust-acfb2c45ba337b3265ab35dee5c94d3641c3ccf7.tar.gz rust-acfb2c45ba337b3265ab35dee5c94d3641c3ccf7.zip | |
don't check if from macro invocation
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/string_lit_as_bytes.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/string_lit_as_bytes.rs | 8 | ||||
| -rw-r--r-- | tests/ui/string_lit_as_bytes.stderr | 12 |
3 files changed, 22 insertions, 6 deletions
diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed index 058f2aa54da..14cb799d916 100644 --- a/tests/ui/string_lit_as_bytes.fixed +++ b/tests/ui/string_lit_as_bytes.fixed @@ -3,6 +3,12 @@ #![allow(dead_code, unused_variables)] #![warn(clippy::string_lit_as_bytes)] +macro_rules! b { + ($b:literal) => { + const C: &[u8] = $b.as_bytes(); + } +} + fn str_lit_as_bytes() { let bs = b"hello there"; @@ -11,6 +17,8 @@ fn str_lit_as_bytes() { let bs = b"lit to string".to_vec(); let bs = b"lit to owned".to_vec(); + b!("aaa"); + // no warning, because these cannot be written as byte string literals: let ubs = "☃".as_bytes(); let ubs = "hello there! this is a very long string".as_bytes(); diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs index b550bea001f..44b468e6bf0 100644 --- a/tests/ui/string_lit_as_bytes.rs +++ b/tests/ui/string_lit_as_bytes.rs @@ -3,6 +3,12 @@ #![allow(dead_code, unused_variables)] #![warn(clippy::string_lit_as_bytes)] +macro_rules! b { + ($b:literal) => { + const C: &[u8] = $b.as_bytes(); + } +} + fn str_lit_as_bytes() { let bs = "hello there".as_bytes(); @@ -11,6 +17,8 @@ fn str_lit_as_bytes() { let bs = "lit to string".to_string().into_bytes(); let bs = "lit to owned".to_owned().into_bytes(); + b!("aaa"); + // no warning, because these cannot be written as byte string literals: let ubs = "☃".as_bytes(); let ubs = "hello there! this is a very long string".as_bytes(); diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index f47d6161c6c..5be3eb9f2ff 100644 --- a/tests/ui/string_lit_as_bytes.stderr +++ b/tests/ui/string_lit_as_bytes.stderr @@ -1,5 +1,5 @@ error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:7:14 + --> $DIR/string_lit_as_bytes.rs:13:14 | LL | let bs = "hello there".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` @@ -7,31 +7,31 @@ LL | let bs = "hello there".as_bytes(); = 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 + --> $DIR/string_lit_as_bytes.rs:15:14 | 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 `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:11:14 + --> $DIR/string_lit_as_bytes.rs:17:14 | LL | let bs = "lit to string".to_string().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to string".to_vec()` error: calling `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:12:14 + --> $DIR/string_lit_as_bytes.rs:18:14 | LL | let bs = "lit to owned".to_owned().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to owned".to_vec()` error: calling `as_bytes()` on `include_str!(..)` - --> $DIR/string_lit_as_bytes.rs:25:22 + --> $DIR/string_lit_as_bytes.rs:33:22 | LL | let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("string_lit_as_bytes.rs")` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:27:13 + --> $DIR/string_lit_as_bytes.rs:35:13 | LL | let _ = "string with newline/t/n".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"` |
