mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 07:30:57 +00:00
88c4a22480
This patch adds a new lint that checks for potentially harder to read byte char slices: `&[b'a', b'b']` and suggests to replace them with the easier to read `b"ab"` form. Signed-Off-By: Marcel Müller <m.mueller@ifm.com> Co-authored-by: Matthias Beyer <matthias.beyer@ifm.com> Use iterator to skip validation Signed-off-by: Marcel Müller <m.mueller@ifm.com> Suggested-by: Alex Macleod <alex@macleod.io> Convert quote escapes to proper form Signed-off-by: Marcel Müller <m.mueller@ifm.com> Add more convertable test cases Signed-off-by: Marcel Müller <m.mueller@ifm.com>
38 lines
1.3 KiB
Text
38 lines
1.3 KiB
Text
error: can be more succinctly written as a byte str
|
|
--> tests/ui/byte_char_slices.rs:5:15
|
|
|
|
|
LL | let bad = &[b'a', b'b', b'c'];
|
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `b"abc"`
|
|
|
|
|
= note: `-D clippy::byte-char-slices` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::byte_char_slices)]`
|
|
|
|
error: can be more succinctly written as a byte str
|
|
--> tests/ui/byte_char_slices.rs:6:18
|
|
|
|
|
LL | let quotes = &[b'"', b'H', b'i'];
|
|
| ^^^^^^^^^^^^^^^^^^^ help: try: `b"\"Hi"`
|
|
|
|
error: can be more succinctly written as a byte str
|
|
--> tests/ui/byte_char_slices.rs:7:18
|
|
|
|
|
LL | let quotes = &[b'\'', b'S', b'u', b'p'];
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b"'Sup"`
|
|
|
|
error: can be more succinctly written as a byte str
|
|
--> tests/ui/byte_char_slices.rs:8:19
|
|
|
|
|
LL | let escapes = &[b'\x42', b'E', b's', b'c'];
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b"\x42Esc"`
|
|
|
|
error: useless use of `vec!`
|
|
--> tests/ui/byte_char_slices.rs:11:16
|
|
|
|
|
LL | let good = vec![b'a', b'a'];
|
|
| ^^^^^^^^^^^^^^^^ help: you can use an array directly: `[b'a', b'a']`
|
|
|
|
|
= note: `-D clippy::useless-vec` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]`
|
|
|
|
error: aborting due to 5 previous errors
|
|
|