rust-lang / rust-lang/rust-by-example

into_iter() for arrays example is not valid for more recent rust compilers

Open
#1,604 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Hello!

When I copy the snippet in the section 9.2.6.1 and try compile locally, I get an error:

// rustc learn-1.rs
error[E0277]: can't compare `&{integer}` with `{integer}`
  --> learn-1.rs:16:62
   |
16 |     println!("2 in array2: {}", array2.into_iter().any(|x| x == 2));
   |                                                              ^^ no implementation for `&{integer} == {integer}`
   |
   = help: the trait `PartialEq<{integer}>` is not implemented for `&{integer}`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             f32
             f64
             i128
             i16
             i32
             i64
             i8
             isize
           and 6 others

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

My rust compiler version:

rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)

The web application is still compiling it correctly though!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/fn/closures/closure_examples/iter_any.md at section 9.2.6.1 and reproduce the reported failure using a recent rustc. Check the example's array into_iter behavior and the corresponding web application example; done means the documented snippet compiles locally on current compilers and remains correct in the web application.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.