Skip to content

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Jan 25, 2026

When encountering a call to iter that should have been into_iter and vice-versa, provide a structured suggestion:

error[E0271]: type mismatch resolving `<IntoIter<{integer}, 3> as IntoIterator>::Item == &{integer}`
  --> $DIR/into_iter-when-iter-was-intended.rs:5:37
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                               ----- ^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
   |                               |
   |                               required by a bound introduced by this call
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/into_iter-when-iter-was-intended.rs:5:47
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                                     --------- ^^^^^^^^^^^ `IntoIterator::Item` is `{integer}` here
   |                                     |
   |                                     this expression has type `[{integer}; 3]`
note: required by a bound in `std::iter::Iterator::chain`
  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider not consuming the `[{integer}, 3]` to construct the `Iterator`
   |
LL -     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
LL +     let _a = [0, 1, 2].iter().chain([3, 4, 5].iter());
   |

Finish addressing the original case in #68095. Only the case of chaining a Vec or [] is left unhandled.

When encountering a call to `iter` that should have been `into_iter` and vice-versa, provide a structured suggestion:

```
error[E0271]: type mismatch resolving `<IntoIter<{integer}, 3> as IntoIterator>::Item == &{integer}`
  --> $DIR/into_iter-when-iter-was-intended.rs:5:37
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                               ----- ^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
   |                               |
   |                               required by a bound introduced by this call
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/into_iter-when-iter-was-intended.rs:5:47
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                                     --------- ^^^^^^^^^^^ `IntoIterator::Item` is `{integer}` here
   |                                     |
   |                                     this expression has type `[{integer}; 3]`
note: required by a bound in `std::iter::Iterator::chain`
  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider not consuming the `[{integer}, 3]` to construct the `Iterator`
   |
LL -     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
LL +     let _a = [0, 1, 2].iter().chain([3, 4, 5].iter());
   |
```
@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 25, 2026
Copy link
Member

@mati865 mati865 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 26, 2026

📌 Commit 2b32446 has been approved by mati865

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 26, 2026
@mati865
Copy link
Member

mati865 commented Jan 26, 2026

@bors rollup

Zalathar added a commit to Zalathar/rust that referenced this pull request Jan 26, 2026
Suggest changing `iter`/`into_iter` when the other was meant

When encountering a call to `iter` that should have been `into_iter` and vice-versa, provide a structured suggestion:

```
error[E0271]: type mismatch resolving `<IntoIter<{integer}, 3> as IntoIterator>::Item == &{integer}`
  --> $DIR/into_iter-when-iter-was-intended.rs:5:37
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                               ----- ^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
   |                               |
   |                               required by a bound introduced by this call
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/into_iter-when-iter-was-intended.rs:5:47
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                                     --------- ^^^^^^^^^^^ `IntoIterator::Item` is `{integer}` here
   |                                     |
   |                                     this expression has type `[{integer}; 3]`
note: required by a bound in `std::iter::Iterator::chain`
  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider not consuming the `[{integer}, 3]` to construct the `Iterator`
   |
LL -     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
LL +     let _a = [0, 1, 2].iter().chain([3, 4, 5].iter());
   |
```

Finish addressing the original case in rust-lang#68095. Only the case of chaining a `Vec` or `[]` is left unhandled.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 26, 2026
Suggest changing `iter`/`into_iter` when the other was meant

When encountering a call to `iter` that should have been `into_iter` and vice-versa, provide a structured suggestion:

```
error[E0271]: type mismatch resolving `<IntoIter<{integer}, 3> as IntoIterator>::Item == &{integer}`
  --> $DIR/into_iter-when-iter-was-intended.rs:5:37
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                               ----- ^^^^^^^^^^^^^^^^^^^^^ expected `&{integer}`, found integer
   |                               |
   |                               required by a bound introduced by this call
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/into_iter-when-iter-was-intended.rs:5:47
   |
LL |     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
   |                                     --------- ^^^^^^^^^^^ `IntoIterator::Item` is `{integer}` here
   |                                     |
   |                                     this expression has type `[{integer}; 3]`
note: required by a bound in `std::iter::Iterator::chain`
  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider not consuming the `[{integer}, 3]` to construct the `Iterator`
   |
LL -     let _a = [0, 1, 2].iter().chain([3, 4, 5].into_iter());
LL +     let _a = [0, 1, 2].iter().chain([3, 4, 5].iter());
   |
```

Finish addressing the original case in rust-lang#68095. Only the case of chaining a `Vec` or `[]` is left unhandled.
rust-bors bot pushed a commit that referenced this pull request Jan 26, 2026
Rollup of 3 pull requests

Successful merges:

 - #151676 (Do not return incorrectly constrained opaques in `method_autoderef_steps`)
 - #151626 (Remove `Deref<Target = TyCtxt>` from `QueryCtxt`)
 - #151661 (Suggest changing `iter`/`into_iter` when the other was meant)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants