Skip to content

Suggestion is placed at the wrong scope with nested IntoIter requirement #81524

@saethlin

Description

@saethlin

rustc 1.49.0 and rustc 1.51.0-nightly (a2f8f62 2021-01-27)

use std::borrow::Borrow;

fn accepts_intoiter_iter<OuterIter, Iter, T>(items: OuterIter)
where
    OuterIter: IntoIterator<Item = Iter>,
    Iter: IntoIterator<Item = T>,
    T: Borrow<u8>,
{
}

fn main() {
    let items: Vec<u16> = Vec::new();
    accepts_intoiter_iter(items.iter().map(|c| c.to_be_bytes()));
}
error[E0277]: `[u8; 2]` is not an iterator
  --> src/lib.rs:13:27
   |
3  | fn accepts_intoiter_iter<OuterIter, Iter, T>(items: OuterIter)
   |    --------------------- required by a bound in this
...
6  |     Iter: IntoIterator<Item = T>,
   |           ---------------------- required by this bound in `accepts_intoiter_iter`
...
13 |     accepts_intoiter_iter(items.iter().map(|c| c.to_be_bytes()));
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                           |
   |                           expected an implementor of trait `IntoIterator`
   |                           help: consider borrowing here: `&items.iter().map(|c| c.to_be_bytes())`
   |
   = note: the trait bound `[u8; 2]: IntoIterator` is not satisfied
   = note: required because of the requirements on the impl of `IntoIterator` for `[u8; 2]`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions