From 471f047a642d9557464fcd21237168aab04236be Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Thu, 18 Jul 2024 15:14:54 +0200 Subject: [PATCH] clippy: simplify code according to nightly 'byte_char_slices' lint https://rust-lang.github.io/rust-clippy/master/index.html#/byte_char_slices --- src/uu/cat/src/cat.rs | 4 ++-- src/uucore/src/lib/features/encoding.rs | 2 +- src/uucore/src/lib/features/sum.rs | 10 +++++----- tests/by-util/test_hashsum.rs | 2 +- tests/by-util/test_tr.rs | 4 ++-- tests/common/util.rs | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index b239dc87a..d0a33a171 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -623,10 +623,10 @@ fn write_nonprint_to_end(in_buf: &[u8], writer: &mut W, tab: &[u8]) -> 9 => writer.write_all(tab), 0..=8 | 10..=31 => writer.write_all(&[b'^', byte + 64]), 32..=126 => writer.write_all(&[byte]), - 127 => writer.write_all(&[b'^', b'?']), + 127 => writer.write_all(b"^?"), 128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]), 160..=254 => writer.write_all(&[b'M', b'-', byte - 128]), - _ => writer.write_all(&[b'M', b'-', b'^', b'?']), + _ => writer.write_all(b"M-^?"), } .unwrap(); count += 1; diff --git a/src/uucore/src/lib/features/encoding.rs b/src/uucore/src/lib/features/encoding.rs index dd89c1f52..6a8e5ba22 100644 --- a/src/uucore/src/lib/features/encoding.rs +++ b/src/uucore/src/lib/features/encoding.rs @@ -86,7 +86,7 @@ pub fn decode(f: Format, input: &[u8]) -> DecodeResult { Z85 => { // The z85 crate implements a padded encoding by using a leading '#' which is otherwise not allowed. // We manually check for a leading '#' and return an error ourselves. - if input.starts_with(&[b'#']) { + if input.starts_with(b"#") { return Err(z85::DecodeError::InvalidByte(0, b'#').into()); } else { z85::decode(input)? diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index 498297023..086c6ca9d 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -402,7 +402,7 @@ impl<'a> DigestWriter<'a> { pub fn finalize(&mut self) -> bool { if self.was_last_character_carriage_return { - self.digest.hash_update(&[b'\r']); + self.digest.hash_update(b"\r"); true } else { false @@ -433,7 +433,7 @@ impl<'a> Write for DigestWriter<'a> { // call to `write()`. let n = buf.len(); if self.was_last_character_carriage_return && n > 0 && buf[0] != b'\n' { - self.digest.hash_update(&[b'\r']); + self.digest.hash_update(b"\r"); } // Next, find all occurrences of "\r\n", inputting the slice @@ -491,15 +491,15 @@ mod tests { // Writing "\r" in one call to `write()`, and then "\n" in another. let mut digest = Box::new(Md5::new()) as Box; let mut writer_crlf = DigestWriter::new(&mut digest, false); - writer_crlf.write_all(&[b'\r']).unwrap(); - writer_crlf.write_all(&[b'\n']).unwrap(); + writer_crlf.write_all(b"\r").unwrap(); + writer_crlf.write_all(b"\n").unwrap(); writer_crlf.finalize(); let result_crlf = digest.result_str(); // We expect "\r\n" to be replaced with "\n" in text mode on Windows. let mut digest = Box::new(Md5::new()) as Box; let mut writer_lf = DigestWriter::new(&mut digest, false); - writer_lf.write_all(&[b'\n']).unwrap(); + writer_lf.write_all(b"\n").unwrap(); writer_lf.finalize(); let result_lf = digest.result_str(); diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index f91752e25..0f4a6fd18 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -83,7 +83,7 @@ macro_rules! test_digest { // The asterisk indicates that the digest was computed in // binary mode. let n = expected.len(); - let expected = [&expected[..n - 3], &[b' ', b'-', b'\n']].concat(); + let expected = [&expected[..n - 3], b" -\n"].concat(); new_ucmd!() .args(&[DIGEST_ARG, BITS_ARG, "-t"]) .pipe_in("a\r\nb\r\nc\r\n") diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index c0421c248..7445b1dc5 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1434,8 +1434,8 @@ fn check_complement_set2_too_big() { #[test] #[cfg(unix)] fn test_truncate_non_utf8_set() { - let stdin = &[b'\x01', b'a', b'm', b'p', 0xfe_u8, 0xff_u8]; - let set1 = OsStr::from_bytes(&[b'a', 0xfe_u8, 0xff_u8, b'z']); + let stdin = b"\x01amp\xfe\xff"; + let set1 = OsStr::from_bytes(b"a\xfe\xffz"); // spell-checker:disable-line let set2 = OsStr::from_bytes(b"01234"); new_ucmd!() diff --git a/tests/common/util.rs b/tests/common/util.rs index a086831c1..07938cf84 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -59,7 +59,7 @@ static ALREADY_RUN: &str = " you have already run this UCommand, if you want to static MULTIPLE_STDIN_MEANINGLESS: &str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly."; static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is no stdin"; -static END_OF_TRANSMISSION_SEQUENCE: &[u8] = &[b'\n', 0x04]; +static END_OF_TRANSMISSION_SEQUENCE: &[u8] = b"\n\x04"; pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils"); pub const PATH: &str = env!("PATH"); @@ -3081,7 +3081,7 @@ mod tests { let result = TestScenario::new("echo").ucmd().arg("Hello world").run(); result.stdout_str_check(|stdout| stdout.ends_with("world\n")); - result.stdout_check(|stdout| stdout.get(0..2).unwrap().eq(&[b'H', b'e'])); + result.stdout_check(|stdout| stdout.get(0..2).unwrap().eq(b"He")); result.no_stderr(); } @@ -3096,7 +3096,7 @@ mod tests { )); result.stderr_str_check(|stderr| stderr.ends_with("world\n")); - result.stderr_check(|stderr| stderr.get(0..2).unwrap().eq(&[b'H', b'e'])); + result.stderr_check(|stdout| stdout.get(0..2).unwrap().eq(b"He")); result.no_stdout(); }