Skip to content

E0046 suggests unsupported equality constraint bounds #91007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quantatic opened this issue Nov 18, 2021 · 1 comment
Closed

E0046 suggests unsupported equality constraint bounds #91007

quantatic opened this issue Nov 18, 2021 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@quantatic
Copy link

quantatic commented Nov 18, 2021

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.

@quantatic quantatic added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 18, 2021
@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Nov 18, 2021
@estebank
Copy link
Contributor

Current output:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants