Skip to content

Spurious 'conflicting implementations' error when specializing a type with a compilation error #68830

New issue

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

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

Already on GitHub? # to your account

Open
Aaron1011 opened this issue Feb 4, 2020 · 2 comments · Fixed by #83699
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-specialization Area: Trait impl specialization C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-specialization `#![feature(specialization)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

#![feature(specialization)]

struct BadStruct {
    err: MissingType
}

trait MyTrait<T> {
    fn foo();
}

impl<T, D> MyTrait<T> for D {
    default fn foo() {}
}

impl<T> MyTrait<T> for BadStruct {
    fn foo() {}
}

gives the following errors:

error[E0412]: cannot find type `MissingType` in this scope
 --> src/lib.rs:4:10
  |
4 |     err: MissingType
  |          ^^^^^^^^^^^ not found in this scope

error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `BadStruct`:
  --> src/lib.rs:15:1
   |
11 | impl<T, D> MyTrait<T> for D {
   | --------------------------- first implementation here
...
15 | impl<T> MyTrait<T> for BadStruct {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `BadStruct`

error: aborting due to 2 previous errors

For some reason, the fact that the definition of BadStruct has an error (MissingType is not defining) causes a 'conflicting implementations' error to be emitted when BadStruct has a specialized impl. If MissingType is changed to a type which actually exists (e.g. ()), the 'conflicting implementations' error disappears.

I found this when working on rustc - a missing use statement caused 30 spurious specialization-related errors to be emiited, which all disappeared when I added the missing import.

@Aaron1011 Aaron1011 changed the title Spurious 'conflicting implementations' error when specializing a type with a compilation Spurious 'conflicting implementations' error when specializing a type with a compilation error Feb 4, 2020
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 4, 2020
@estebank estebank added A-specialization Area: Trait impl specialization D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-specialization `#![feature(specialization)]` labels Feb 4, 2020
@JohnTitor
Copy link
Member

Current output:

error[E0412]: cannot find type `MissingType` in this scope
 --> src/main.rs:5:10
  |
5 |     err: MissingType
  |          ^^^^^^^^^^^ not found in this scope

error: aborting due to previous error

The E0119 is no longer shown, marking as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 30, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 31, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 31, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 31, 2021
@bors bors closed this as completed in e40601e Apr 1, 2021
@gurry
Copy link
Contributor

gurry commented Apr 21, 2024

This issue regressed due to PR #123491. @Aaron1011 please reopen it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-specialization Area: Trait impl specialization C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-specialization `#![feature(specialization)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants