Skip to content

E0046 suggests unsupported equality constraint bounds #91007

Closed
@quantatic

Description

@quantatic

Given the following code:

struct Foo;

impl Extend<u8> for Foo {
}

fn main() {
}

The current output is:

error[E0046]: not all trait items implemented, missing: `extend`
 --> main.rs:3:1
  |
3 | impl Extend<u8> for Foo {
  | ^^^^^^^^^^^^^^^^^^^^^^^ missing `extend` in implementation
  |
  = help: implement the missing item: `fn extend<T>(&mut self, _: T) where T: IntoIterator, std::iter::IntoIterator::Item = A { todo!() }`

error: aborting due to previous error

Following the suggestion given:

struct Foo;

impl Extend<u8> for Foo {
    fn extend<T>(&mut self, _: T) where T: IntoIterator, std::iter::IntoIterator::Item = A { todo!() }
}

fn main() {
}

two additional errors are raised:

error: equality constraints are not yet supported in `where` clauses
 --> src/main.rs:4:58
  |
4 |     fn extend<T>(&mut self, _: T) where T: IntoIterator, std::iter::IntoIterator::Item = A { todo!() }
  |                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not supported
  |
  = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information

error[E0412]: cannot find type `A` in this scope
 --> src/main.rs:4:90
  |
4 |     fn extend<T>(&mut self, _: T) where T: IntoIterator, std::iter::IntoIterator::Item = A { todo!() }
  |               - similarly named type parameter `T` defined here                          ^ help: a type parameter with a similar name exists: `T`

These errors are fixable like so:

struct Foo;

impl Extend<u8> for Foo {
    fn extend<T>(&mut self, _: T) where T: IntoIterator<Item = u8> { todo!() }
}

fn main() {
}

This issue is present on both stable and nightly:

$ rustc --version --verbose
rustc 1.56.1 (59eed8a2a 2021-11-01)
binary: rustc
commit-hash: 59eed8a2aac0230a8b53e89d4e99d55912ba6b35
commit-date: 2021-11-01
host: x86_64-unknown-linux-gnu
release: 1.56.1
LLVM version: 13.0.0

$ rustc --version --verbose
rustc 1.58.0-nightly (c9c4b5d72 2021-11-17)
binary: rustc
commit-hash: c9c4b5d7276297679387189d96a952f2b760e7ad
commit-date: 2021-11-17
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

I would expect rustc to give a working suggestion here, and definitely not to give a suggestion that is invalid in two distinct ways.

The second issue is also reported by #89220.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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