title: Why can a for loop in Rust iterate over a slice or iterator, but not an array?
body: <p>Why can a <code>for</code> loop in Rust 1.44.0 iterate over a slice or iterator, but not an array?  For example, the following threw me for a loop:</p>
  <p>Loop over an array:</p>
  <pre><code>fn main() {
      let a = [1, 2, 3, 4, 5];
  
      for element in a {
          println!(&quot;element={}&quot;, element);
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>error[E0277]: `[{integer}; 5]` is not an iterator
   --&gt; main.rs:4:20
    |
  4 |     for element in a {
    |                    ^ borrow the array with `&amp;` or call `.iter()` on it to iterate over it
    |
    = help: the trait `std::iter::Iterator` is not implemented for `[{integer}; 5]`
    = note: arrays are not iterators, but slices like the following are: `&amp;[1, 2, 3]`
    = note: required by `std::iter::IntoIterator::into_iter`
  </code></pre>
  <p>Loop over a slice (version 1):</p>
  <pre><code>fn main() {
      let a = &amp;[1, 2, 3, 4, 5];
  
      for element in a {
          println!(&quot;element={}&quot;, element);
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>element=1
  element=2
  element=3
  element=4
  element=5
  </code></pre>
  <p>Loop over a slice (version 2):</p>
  <pre><code>fn main() {
      let a = [1, 2, 3, 4, 5];
  
      for element in &amp;a {
          println!(&quot;element={}&quot;, element);
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>element=1
  element=2
  element=3
  element=4
  element=5
  </code></pre>
  <p>Loop over an array iterator:</p>
  <pre><code>fn main() {
      let a = [1, 2, 3, 4, 5];
  
      for element in a.iter() {
          println!(&quot;element={}&quot;, element);
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>element=1
  element=2
  element=3
  element=4
  element=5
  </code></pre>
  <p>Rust can also loop in this way over a vector:</p>
  <pre><code>fn main() {
      let v = vec![1, 2, 3, 4, 5];
  
      for element in v {
          println!(&quot;element={}&quot;, element);
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>element=1
  element=2
  element=3
  element=4
  element=5
  </code></pre>