]> git.lizzy.rs Git - rust.git/blob - tests/ui/iterators/into-iter-on-arrays-2021.rs
Rollup merge of #106605 - notriddle:notriddle/outdated-rustbook, r=GuillaumeGomez
[rust.git] / tests / ui / iterators / into-iter-on-arrays-2021.rs
1 // check-pass
2 // edition:2021
3
4 use std::array::IntoIter;
5 use std::ops::Deref;
6 use std::rc::Rc;
7
8 fn main() {
9     let array = [0; 10];
10
11     // In 2021, the method dispatches to `IntoIterator for [T; N]`.
12     let _: IntoIter<i32, 10> = array.into_iter();
13     let _: IntoIter<i32, 10> = Box::new(array).into_iter();
14
15     // The `array_into_iter` lint doesn't cover other wrappers that deref to an array.
16     let _: IntoIter<i32, 10> = Rc::new(array).into_iter();
17     let _: IntoIter<i32, 10> = Array(array).into_iter();
18
19     // You can always use the trait method explicitly as an array.
20     let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
21 }
22
23 /// User type that dereferences to an array.
24 struct Array([i32; 10]);
25
26 impl Deref for Array {
27     type Target = [i32; 10];
28
29     fn deref(&self) -> &Self::Target {
30         &self.0
31     }
32 }