From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/iterators/into-iter-on-arrays-2021.rs | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/ui/iterators/into-iter-on-arrays-2021.rs (limited to 'src/test/ui/iterators/into-iter-on-arrays-2021.rs') diff --git a/src/test/ui/iterators/into-iter-on-arrays-2021.rs b/src/test/ui/iterators/into-iter-on-arrays-2021.rs new file mode 100644 index 000000000..158317efe --- /dev/null +++ b/src/test/ui/iterators/into-iter-on-arrays-2021.rs @@ -0,0 +1,32 @@ +// check-pass +// edition:2021 + +use std::array::IntoIter; +use std::ops::Deref; +use std::rc::Rc; + +fn main() { + let array = [0; 10]; + + // In 2021, the method dispatches to `IntoIterator for [T; N]`. + let _: IntoIter = array.into_iter(); + let _: IntoIter = Box::new(array).into_iter(); + + // The `array_into_iter` lint doesn't cover other wrappers that deref to an array. + let _: IntoIter = Rc::new(array).into_iter(); + let _: IntoIter = Array(array).into_iter(); + + // You can always use the trait method explicitly as an array. + let _: IntoIter = IntoIterator::into_iter(array); +} + +/// User type that dereferences to an array. +struct Array([i32; 10]); + +impl Deref for Array { + type Target = [i32; 10]; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} -- cgit v1.2.3