Skip to content

Make diagnostics emitting independent of the happy code path #61132

Closed
@oli-obk

Description

@oli-obk

In our first @rust-lang/wg-diagnostics meeting on zulip we figured that a first start would be to create a new trait

trait AsError {
    /// ParseSess, Session or `TyCtxt`
    type Session;
    fn to_error(self, session: Self::Session) -> DiagnosticBuilder;
    fn emit(self) {
        self.to_error().emit()
    }
}

that is implemented for structs containing all relevant info for a diagnostic, e.g.

struct TypeError {
    expected: Ty,
    found: Ty,
    span: Span,
}

and then the code that currently constructs the diagnostic and emits it would just become

TypeError {
    expected,
    found,
    span: Span,
}.emit();

This issue has been assigned to @jumbatm via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.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