We have quite different APIs for emitting a lint vs a hard error #121077
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lint
Area: Lints (warnings about flaws in source code) such as unused_mut.
A-translation
Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Switching between a lint and a hard error used to be fairly simple, one basically just swapped out the function that is called to emit the diagnostic. However, with translatable diagnostic, this has become more work:
derive(LintDiagnostic)
toderive(Diagnostic)
span
field needs to be added and decorated with#[primary_span]
emit_err
instead ofemit_node_span_lint
It can be hard to find out about this recipe. It is also a (small) roadblock whenever one wants to do a crater run with a lint turned into a hard error, just to see how much it happens in the ecosystem.
So maybe something could be done to unify these two APIs? I don't know whether "span-in-error-type" vs "separate-span" is the better API. I was told that sometimes having the span in the type is very useful because then extra attributes can be easily applied to it. OTOH, for parts of the compiler (e.g. the interpreter), the logic that determines which error to emit and the logic that determines the span are quite far apart from each other, leading kind of a mess with the current error APIs. Maybe there is a way to make both styles possible for both lints and hard errors?
Cc @davidtwco (not sure who else is pushing translatable diagnostics?)
The text was updated successfully, but these errors were encountered: