rust-lang / rust-lang/rust

`on_unimplemented` label and notes are not displayed for transitive bounds

Open
#134,700 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
struct S;

#[diagnostic::on_unimplemented(
    message = "unable to generate binding for function",
    label = "Some label",
    note = "note 1",
    note = "note 2",
    note = "note 3",
)]
trait Failure7<'a> {}

impl<'a> Clone for S where S: Failure7<'a> {
    fn clone(&self) -> Self {
        unreachable!()
    }
}

fn main() {
    fn take_clone(_: impl Clone) {}
    take_clone(S);
}
Current output
error[E0277]: the trait bound `S: Clone` is not satisfied
  --> src/main.rs:20:16
   |
20 |     take_clone(S);
   |     ---------- ^ the trait `Clone` is not implemented for `S`
   |     |
   |     required by a bound introduced by this call
   |
note: required for `S` to implement `Clone`
  --> src/main.rs:12:10
   |
12 | impl<'a> Clone for S where S: Failure7<'a> {
   |          ^^^^^     ^          ------------ unsatisfied trait bound introduced here
note: required by a bound in `take_clone`
  --> src/main.rs:19:27
   |
19 |     fn take_clone(_: impl Clone) {}
   |                           ^^^^^ required by this bound in `take_clone`
help: consider borrowing here
   |
20 |     take_clone(&S);
   |                +

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Rationale and extra context

The output should include the provided label and note values, as it does when depending on the trait bound directly.

Rust Version
1.83.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided Rust code with rustc 1.83.0 and compare this transitive-bound diagnostic with the direct trait-bound case, where the label and notes appear. Trace the compiler's on_unimplemented diagnostic handling for these two paths; done means the transitive error includes the supplied label and all three notes without regressing the existing output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.