Skip to content

improve the way we deal with ambiguity errors #103911

Open
@lcnr

Description

@lcnr

right now we report each ambiguity error separately, sprinkling in a bunch of self.is_tainted_by_errors() and friends in there to deduplicate errors.

This can often cause us to emit less useful errors because the more relevant error happens later.
It also restricts us in the suggestions we can emit.

This happens in fn report_fulfillment_errors:

for (error, suppressed) in iter::zip(errors, is_suppressed) {
if !suppressed {
self.report_fulfillment_error(error, body_id, fallback_has_occurred);
}
}

I think ideally what we should do is:

  • look at all CodeAmbiguity errors and merge them by their annotated inference variable1.
  • if there are multiple obligations ambiguous due to the same inference variable, talk about them as part of the same error message, ignoring "less important" obligations.
  • further work: with selection failure: recompute applicable impls #103252 we will have a list of all maybe applicable impls, so if we have multiple trait obligations we can just try each combination of candidates to e.g. be able to say "you may have wanted to specify the type String here" in this example.

cc @estebank @jackh726

Open to review/help out if somebody wants to experiment with this. I won't be able to spend too much time on this though, so it's probably pretty difficult without prior experience with this code.

Footnotes

  1. This is currently computed ad-hoc in maybe_report_ambiguity and should be moved into a separate function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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