From 26a7b322a37c1eeefb324bd3d082eeb36654c6a2 Mon Sep 17 00:00:00 2001 From: wowinter13 Date: Wed, 15 Jan 2025 22:15:49 +0100 Subject: Rename slice_as_bytes -> sliced_string_as_bytes --- tests/ui/sliced_string_as_bytes.fixed | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/ui/sliced_string_as_bytes.fixed (limited to 'tests/ui/sliced_string_as_bytes.fixed') diff --git a/tests/ui/sliced_string_as_bytes.fixed b/tests/ui/sliced_string_as_bytes.fixed new file mode 100644 index 00000000000..469ad27a99b --- /dev/null +++ b/tests/ui/sliced_string_as_bytes.fixed @@ -0,0 +1,34 @@ +#![allow(unused)] +#![warn(clippy::sliced_string_as_bytes)] + +use std::ops::{Index, Range}; + +struct Foo; + +struct Bar; + +impl Bar { + fn as_bytes(&self) -> &[u8] { + &[0, 1, 2, 3] + } +} + +impl Index> for Foo { + type Output = Bar; + + fn index(&self, _: Range) -> &Self::Output { + &Bar + } +} + +fn main() { + let s = "Lorem ipsum"; + let string: String = "dolor sit amet".to_owned(); + + let bytes = &s.as_bytes()[1..5]; + let bytes = &string.as_bytes()[1..]; + let bytes = &"consectetur adipiscing".as_bytes()[..=5]; + + let f = Foo; + let bytes = f[0..4].as_bytes(); +} -- cgit 1.4.1-3-g733a5