rust-lang / rust-lang/rust

Nested APITs are excessively opaque

Open
#118,339 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-trait-system C-enhancement T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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

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

Reproduce the nested APIT example from src/lib.rs with the reported rustc version, then compare the compiler's behavior with the expected successful compilation. Done means the example compiles successfully or the diagnostic behavior is corrected and verified against the same reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.