Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

on_unimplemented label and notes are not displayed for transitive bounds #134700

Open
cramertj opened this issue Dec 23, 2024 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cramertj
Copy link
Member

cramertj commented Dec 23, 2024

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
@cramertj cramertj added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 23, 2024
@compiler-errors
Copy link
Member

compiler-errors commented Dec 23, 2024

This probably got messed up by #121826, which applied some really messy hacks to not note the transitive bound. I'd kinda prefer if we reverted that PR, frankly, rather than keep working around it.

We have #[diagnostic::do_not_recommend] for cases where we want to avoid recursing into unnecessary blanket impls, but the current state of the report_selection_error function makes it incredibly difficult to distinguish what the diagnostic is actually aiming to report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants