@@ -549,6 +549,56 @@ mod prim_pointer {}
549549/// move_away(roa);
550550/// ```
551551///
552+ /// # Editions
553+ ///
554+ /// Prior to Rust 1.53, arrays did not implement `IntoIterator` by value, so the method call
555+ /// `array.into_iter()` auto-referenced into a slice iterator. That behavior is preserved in the
556+ /// 2015 and 2018 editions of Rust for compatability, ignoring `IntoIterator` by value.
557+ ///
558+ /// ```rust,edition2018
559+ /// # #![allow(array_into_iter)] // override our `deny(warnings)`
560+ /// let array: [i32; 3] = [0; 3];
561+ ///
562+ /// // This creates a slice iterator, producing references to each value.
563+ /// for item in array.into_iter().enumerate() {
564+ /// let (i, x): (usize, &i32) = item;
565+ /// println!("array[{}] = {}", i, x);
566+ /// }
567+ ///
568+ /// // The `array_into_iter` lint suggests this change for future compatibility:
569+ /// for item in array.iter().enumerate() {
570+ /// let (i, x): (usize, &i32) = item;
571+ /// println!("array[{}] = {}", i, x);
572+ /// }
573+ ///
574+ /// // You can explicitly iterate an array by value using
575+ /// // `IntoIterator::into_iter` or `std::array::IntoIter::new`:
576+ /// for item in IntoIterator::into_iter(array).enumerate() {
577+ /// let (i, x): (usize, i32) = item;
578+ /// println!("array[{}] = {}", i, x);
579+ /// }
580+ /// ```
581+ ///
582+ /// Starting in the 2021 edition, `array.into_iter()` will use `IntoIterator` normally to iterate
583+ /// by value, and `iter()` should be used to iterate by reference like previous editions.
584+ ///
585+ /// ```rust,edition2021,ignore
586+ /// # // FIXME: ignored because 2021 testing is still unstable
587+ /// let array: [i32; 3] = [0; 3];
588+ ///
589+ /// // This iterates by reference:
590+ /// for item in array.iter().enumerate() {
591+ /// let (i, x): (usize, &i32) = item;
592+ /// println!("array[{}] = {}", i, x);
593+ /// }
594+ ///
595+ /// // This iterates by value:
596+ /// for item in array.into_iter().enumerate() {
597+ /// let (i, x): (usize, i32) = item;
598+ /// println!("array[{}] = {}", i, x);
599+ /// }
600+ /// ```
601+ ///
552602/// [slice]: prim@slice
553603/// [`Debug`]: fmt::Debug
554604/// [`Hash`]: hash::Hash
0 commit comments