Array iteration example from book does not compile

Listing 3.5 from the following page


fn main() {
    let a = [10, 20, 30, 40, 50];

    for element in a {
        println!("the value is: {}", element);

does not compile. The compiler gives me enough intormation to fix it, but should not this be fixed?

Works for me, as does the embedded play button in the Book.


You may be using a Rust version older than 1.53.0, in which IntoIterator for arrays was added. Prior to that version you would get error[E0277]: [{integer}; 5] is not an iterator.

You should consider upgrading your Rust version. If that is not practical, you could read an older version of the book.

If that's not what you see, please show us the complete output your compiler gives you.


@feraudyh on that note, see the title page for the minimum version you're expected to have for all the examples to work. At the moment that's 1.57.


I'll try to upgrade then.
I'm wondering if I can do that without uninstalling and then reinstalling.

Just noticed that
rustup update
does the job simply and beautifully.

Thanks to everyone for your friendly and timely help!


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.