-
Notifications
You must be signed in to change notification settings - Fork 14k
macros: LintDiagnostic derive
#98884
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment was marked as resolved.
This comment was marked as resolved.
17770ff to
1a011dc
Compare
Signed-off-by: David Wood <david.wood@huawei.com>
Signed-off-by: David Wood <david.wood@huawei.com>
Add a new trait to be generated by diagnostic derives which uses a `LintDiagnosticBuilder`. Signed-off-by: David Wood <david.wood@huawei.com>
Move the logic for building a field mapping (which is used by the building of format strings in `suggestion` annotations) into a helper function. Signed-off-by: David Wood <david.wood@huawei.com>
`sess` field of `SessionDiagnosticDeriveBuilder` is never actually used in the builder's member functions, so it doesn't need to be a field. Signed-off-by: David Wood <david.wood@huawei.com>
`SessionDiagnostic` isn't suitable for use on lints as whether or not it creates an error or a warning is decided at compile-time by the macro, whereas lints decide this at runtime based on the location of the lint being reported (as it will depend on the user's `allow`/`deny` attributes, etc). Re-using most of the machinery for `SessionDiagnostic`, this macro introduces a `LintDiagnostic` derive which implements a `DecorateLint` trait, taking a `LintDiagnosticBuilder` and adding to the lint according to the diagnostic struct.
1a011dc to
9d864c8
Compare
oli-obk
reviewed
Jul 6, 2022
Comment on lines
-1556
to
1571
| if matches!(fail_ordering, sym::Release | sym::AcqRel) { | ||
| cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg.span, |diag| { | ||
| diag.build(fluent::lint::atomic_ordering_invalid) | ||
| .set_arg("method", method) | ||
| .span_label(fail_order_arg.span, fluent::lint::label) | ||
| .help(fluent::lint::help) | ||
| .emit(); | ||
| }); | ||
| #[derive(LintDiagnostic)] | ||
| #[lint(lint::atomic_ordering_invalid)] | ||
| #[help] | ||
| struct InvalidAtomicOrderingDiag { | ||
| method: Symbol, | ||
| #[label] | ||
| fail_order_arg_span: Span, | ||
| } | ||
|
|
||
| cx.emit_spanned_lint( | ||
| INVALID_ATOMIC_ORDERING, | ||
| fail_order_arg.span, | ||
| InvalidAtomicOrderingDiag { method, fail_order_arg_span: fail_order_arg.span }, | ||
| ); | ||
| } |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @rust-lang/clippy this may allow some separation of lint logic and lint emitting in clippy, too
Contributor
|
@bors r+ |
Collaborator
|
📌 Commit 9d864c8 has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jul 6, 2022
Rollup of 5 pull requests Successful merges: - rust-lang#98881 (Only compute DefKind through the query.) - rust-lang#98884 (macros: `LintDiagnostic` derive) - rust-lang#98964 (fix typo in function name) - rust-lang#98967 (fix typo in note about multiple inaccessible type aliases) - rust-lang#98968 (assert Scalar sanity) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-translation
Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LintDiagnosticBuilderintorustc_errorsso that a diagnostic derive can refer to it.DecorateLinttrait, which is equivalent toSessionDiagnosticorAddToDiagnosticbut for lints. Necessary without making more changes to the lint infrastructure asDecorateLinttakes aLintDiagnosticBuilderand re-uses all of the existing logic for determining what type of diagnostic a lint should be emitted as (e.g. error/warning).build_field_mappinghelper and movingsessfield out of theDiagnosticDeriveBuilder).LintDiagnosticderive macro that works almost exactly like theSessionDiagnosticderive macro except that it derives aDecorateLintimplementation instead. A new derive is necessary for this becauseSessionDiagnosticis intended for when the generated code creates the diagnostic.AddToDiagnosticcould have been used but it would have required more changes to the lint machinery.At time of opening this pull request, ignore all of the commits from #98624, it's just the last few commits that are new.r? @oli-obk