rust/tests/ui/iterators/into-iter-on-boxed-slices-lint.fixed
2024-05-20 19:21:30 -04:00

31 lines
951 B
Rust

//@ run-pass
//@ run-rustfix
//@ rustfix-only-machine-applicable
#[allow(unused_must_use, unused_allocation)]
fn main() {
let boxed = vec![1, 2].into_boxed_slice();
// Expressions that should trigger the lint
boxed.iter();
//~^ WARNING this method call resolves to `<&Box<[T]> as IntoIterator>::into_iter`
//~| WARNING this changes meaning
Box::new(boxed.clone()).iter();
//~^ WARNING this method call resolves to `<&Box<[T]> as IntoIterator>::into_iter`
//~| WARNING this changes meaning
Box::new(Box::new(boxed.clone())).iter();
//~^ WARNING this method call resolves to `<&Box<[T]> as IntoIterator>::into_iter`
//~| WARNING this changes meaning
// Expressions that should not
(&boxed).into_iter();
for _ in &boxed {}
(&boxed as &[_]).into_iter();
boxed[..].into_iter();
std::iter::IntoIterator::into_iter(&boxed);
#[allow(boxed_slice_into_iter)]
boxed.into_iter();
}