Skip to content

Nested APITs are excessively opaque #118339

Open
@Jules-Bertholet

Description

I tried this code:

fn foo(iter: impl IntoIterator<IntoIter = impl Sized>) {
    iter.into_iter().next();
}

I expected to see this happen: compiles successfully

Instead, this happened:

error[E0599]: no method named `next` found for type parameter `impl Sized` in the current scope
 --> src/lib.rs:2:22
  |
1 | fn foo(iter: impl IntoIterator<IntoIter = impl Sized>) {
  |                                           ---------- method `next` not found for this type parameter
2 |     iter.into_iter().next();
  |                      ^^^^ method not found in `impl Sized`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `next`, perhaps you need to restrict type parameter `impl Sized` with it:
  |
1 | fn foo(iter: impl IntoIterator<IntoIter = impl Sized + Iterator>) {
  |                                                      ++++++++++

For more information about this error, try `rustc --explain E0599`.
error: could not compile `scratch` (lib) due to previous error

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (f5dc2653f 2023-11-25)
binary: rustc
commit-hash: f5dc2653fdd8b5d177b2ccbd84057954340a89fc
commit-date: 2023-11-25
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

@rustbot label A-impl-trait T-types

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-typesRelevant to the types 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