Skip to content

Confusing/incorrect "&mut &mut [T] is not an iterator" #84837

Closed
@Soveu

Description

@Soveu

Given the following code:

let mut v: Vec<u8> = Vec::new();
for _ in &mut &mut v {}
let mut v: &mut [u8] = &mut [];
for _ in &mut v {}

The current output is:

error[E0277]: `Vec<u8>` is not an iterator
 --> src/main.rs:4:14
  |
4 |     for _ in &mut &mut v {}
  |              ^^^^^^^^^^^ `Vec<u8>` is not an iterator
  |
  = help: the trait `Iterator` is not implemented for `Vec<u8>`
  = note: required because of the requirements on the impl of `Iterator` for `&mut Vec<u8>`
  = note: 1 redundant requirements hidden
  = note: required because of the requirements on the impl of `Iterator` for `&mut &mut Vec<u8>`
  = note: required because of the requirements on the impl of `IntoIterator` for `&mut &mut Vec<u8>`
  = note: required by `into_iter`
error[E0277]: `[u8]` is not an iterator
 --> src/main.rs:3:14
  |
3 |     for _ in &mut v {}
  |              ^^^^^^ `[u8]` is not an iterator
  |
  = help: the trait `Iterator` is not implemented for `[u8]`
  = note: required because of the requirements on the impl of `Iterator` for `&mut [u8]`
  = note: 1 redundant requirements hidden
  = note: required because of the requirements on the impl of `Iterator` for `&mut &mut [u8]`
  = note: required because of the requirements on the impl of `IntoIterator` for `&mut &mut [u8]`
  = note: required by `into_iter`

Ideally it would say that &mut &mut T is not an iterator and maybe suggest removing &mut.
On the other hand, for _ in &mut &mut (0usize..) just derefs and works fine.

@rustbot label: A-diagnostics D-incorrect D-confusing

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions