Skip to content

diagnostic::on_unimplemented fails to trigger #130082

Open
@konnorandrews

Description

@konnorandrews

Code

#[diagnostic::on_unimplemented(
    message = "message",
)]
pub trait ProviderLt {}

pub trait ProviderExt {
    fn request<R>(&self) {
        todo!()
    }
}

impl<T: ?Sized + ProviderLt> ProviderExt for T {}

struct A<'a>(&'a ());

struct B; // works

fn main() {
    A(&()).request();
    
    B.request(); // works
}

Current output

error[E0599]: the method `request` exists for struct `A<'_>`, but its trait bounds were not satisfied
  --> src/main.rs:19:12
   |
14 | struct A<'a>(&'a ());
   | ------------ method `request` not found for this struct because it doesn't satisfy `A<'_>: ProviderExt` or `A<'_>: ProviderLt`
...
19 |     A(&()).request();
   |            ^^^^^^^ method cannot be called on `A<'_>` due to unsatisfied trait bounds
   |
note: trait bound `A<'_>: ProviderLt` was not satisfied
  --> src/main.rs:12:18
   |
12 | impl<T: ?Sized + ProviderLt> ProviderExt for T {}
   |                  ^^^^^^^^^^  -----------     -
   |                  |
   |                  unsatisfied trait bound introduced here
note: the trait `ProviderLt` must be implemented
  --> src/main.rs:4:1
   |
4  | pub trait ProviderLt {}
   | ^^^^^^^^^^^^^^^^^^^^
   = help: items from traits can only be used if the trait is implemented and in scope
note: `ProviderExt` defines an item `request`, perhaps you need to implement it
  --> src/main.rs:6:1
   |
6  | pub trait ProviderExt {
   | ^^^^^^^^^^^^^^^^^^^^^

error[E0599]: message
  --> src/main.rs:21:7
   |
16 | struct B; // works
   | -------- method `request` not found for this struct because it doesn't satisfy `B: ProviderExt` or `B: ProviderLt`
...
21 |     B.request(); // works
   |       ^^^^^^^ method cannot be called on `B` due to unsatisfied trait bounds
   |
note: trait bound `B: ProviderLt` was not satisfied
  --> src/main.rs:12:18
   |
12 | impl<T: ?Sized + ProviderLt> ProviderExt for T {}
   |                  ^^^^^^^^^^  -----------     -
   |                  |
   |                  unsatisfied trait bound introduced here
note: the trait `ProviderLt` must be implemented
  --> src/main.rs:4:1
   |
4  | pub trait ProviderLt {}
   | ^^^^^^^^^^^^^^^^^^^^
   = help: items from traits can only be used if the trait is implemented and in scope
note: `ProviderExt` defines an item `request`, perhaps you need to implement it
  --> src/main.rs:6:1
   |
6  | pub trait ProviderExt {
   | ^^^^^^^^^^^^^^^^^^^^^

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

Desired output

The first error should also be using the "message" message like the second one.

Rationale and extra context

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f9313422f1b0da95507832b37b234c30

Other cases

No response

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.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