Skip to content

#[diagnostic::on_unimplemented] hint not shown for associated type mismatch #125231

Closed as not planned
@TimNN

Description

@TimNN

Code

#[diagnostic::on_unimplemented(message = "Very important message!")]
trait TheImportantOne {}

trait ImplementationDetail {
    type Restriction;
}

impl<T: ImplementationDetail<Restriction = ()>> TheImportantOne for T {}

// Comment out this `impl` to show the expected error message.
impl ImplementationDetail for u8 {
    type Restriction = u8;
}

fn verify<T: TheImportantOne>() {}

pub fn main() {
    verify::<u8>();
}

Current output

error[E0271]: type mismatch resolving `<u8 as ImplementationDetail>::Restriction == ()`
  --> src/main.rs:18:14
   |
18 |     verify::<u8>();
   |              ^^ type mismatch resolving `<u8 as ImplementationDetail>::Restriction == ()`
   |
note: expected this to be `()`
  --> src/main.rs:12:24
   |
12 |     type Restriction = u8;
   |                        ^^
note: required for `u8` to implement `TheImportantOne`
  --> src/main.rs:8:49
   |
8  | impl<T: ImplementationDetail<Restriction = ()>> TheImportantOne for T {}
   |                              ----------------   ^^^^^^^^^^^^^^^     ^
   |                              |
   |                              unsatisfied trait bound introduced here
note: required by a bound in `verify`
  --> src/main.rs:15:14
   |
15 | fn verify<T: TheImportantOne>() {}
   |              ^^^^^^^^^^^^^^^ required by this bound in `verify`

For more information about this error, try `rustc --explain E0271`.

Desired output

The "Very important message!" should be shown somewhere in the output (similar to what is shown if impl ImplementationDetail for u8 is missing entirely).

Rationale and extra context

The fundamental error is required for `u8` to implement `TheImportantOne` in both cases (impl ImplementationDetail for u8 completely missing and impl ImplementationDetail for u8 having the wrong Restriction type). As such, I would expect the on_unimplemented message to display in both cases.

Other cases

No response

Rust Version

Playground nightly (`1.80.0-nightly (2024-05-16 8c127df75fde3d5ad8ef)`) and stable (`1.78.0`).

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsF-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`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