Skip to content

Error reporting for trait failures should give backtrace #30976

Closed
@nikomatsakis

Description

@nikomatsakis

Now that #30533 has landed, we can change how we report trait errors to give a complete backtrace. In fact, I suspect the most intuitive thing would be to start from the root obligation and print that, and then show the chain of reasoning which ultimately failed. For example, if we had Vec<Box<Foo>>: Debug and it turns out that Foo: ?Debug, then we would print something like:

  • Vec<Box<Foo>>: Debug does not hold
    • impl from stdlib for Vec does not apply because Box<Foo>: Debug does not hold:
    • impl from stdlib for Box does not apply because Foo: Debug does not hold:
    • no impl of Debug for Foo found

As part of this, we will want to (I think) change how we assign "causes" to the subobligations. Currently, we propagate the cause of the root obligation. I think what we want to do instead is to assign a cause that indicates the impl whence the subobligation was created. That way, when printing the backtrace, we can walk through the impls and show them to the user.

PS, I know there is a duplicate of various existing bug reports. I didn't really look, but we should try to gather up all the various examples into one master bug. Perhaps this one?

cc @aturon @arielb1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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