Skip to content

Diagnostic regression when rustc cannot specialize (using min_specialization) #97296

Open
@robinmoussu

Description

@robinmoussu

Note: I’m not sure if anything need to be done since specialization should allow the following code when it will fully be implemented, but currently the quality of the diagnostic is decreased when min_specialization is used:


Given the following code: playground

trait Trait {
    fn foo() {}
    fn bar() {}
}
struct Struct<F> {
    f: F,
}

impl<F> Trait for Struct<F>
where F: FnMut() -> ()
{
    fn foo() {}
}

impl<F> Trait for Struct<F>
where F: FnOnce() -> ()
{
    fn bar() {}
}

The current output is:

  • With #![feature(min_specialization)]
error: cannot specialize on trait `FnMut`
  --> src/lib.rs:11:1
   |
11 | / impl<F> Trait for Struct<F>
12 | | where F: FnMut() -> ()
13 | | {
14 | |     fn foo() {}
15 | | }
   | |_^
  • Without (the diagnostic is much better):
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `Trait` for type `Struct<_>`
  --> src/lib.rs:17:1
   |
11 | / impl<F> Trait for Struct<F>
12 | | where F: FnMut() -> ()
13 | | {
14 | |     fn foo() {}
15 | | }
   | |_- first implementation here
16 | 
17 | / impl<F> Trait for Struct<F>
18 | | where F: FnOnce() -> ()
19 | | {
20 | |     fn bar() {}
21 | | }
   | |_^ conflicting implementation for `Struct<_>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsF-specialization`#![feature(specialization)]`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