Coalesce rustc_on_unimplemented attributes and lint malformed filters - #160113
Conversation
d048c27 to
0e36f43
Compare
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred to diagnostic attributes. cc @mejrs |
| //~^ ERROR invalid flag in `on`-clause | ||
| //~^ WARN invalid flag in `on`-clause |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| // the first matching filter provides each scalar option, while root options act as fallbacks. | ||
| // Notes from every matching filter and every root directive remain in source order. | ||
|
|
||
| //@ dont-require-annotations: NOTE |
There was a problem hiding this comment.
IMO we should have required note annotations in this file, in case we get new notes added, duplicate notes, etc, by accident
There was a problem hiding this comment.
I didn’t want to use it initially, but without it we’d have to annotate all notes unrelated to coalescing (as you can see in the stderr files), which I found to be noisy.
There was a problem hiding this comment.
A better approach would be to model the test such that it won't require extra notes outside coalescing
There was a problem hiding this comment.
It's important that the notes are annotated so that missing or extra notes actually fail the test. otherwise it is easy for people to just blindly bless the test and move on.
0e36f43 to
9628fa5
Compare
|
Also just to put context in here in the actual PR thread, this change is done to allow us to later migrate the whole Since we warn on malformed diagnostic attrs |
not without modifications, but yes. |
There was a problem hiding this comment.
Can you also add a test specifically combining a rustc_on_unimplemented with filters and a regular diagnostic attribute? That might up being (perhaps accidentally?) used in std and I want to be doubly sure it works.
like
#[rustc_on_unimplemented(
on(
...,
....
),
....
)]
#[diagnostic::on_unimplemented( ...)
trait Trait { }| if let Some(parent_label) = parent_label { | ||
| if let Some(first_parent_label) = &first.parent_label { | ||
| cx.emit_lint( | ||
| MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
| IgnoredDiagnosticOption { | ||
| first_span: first_parent_label.span, | ||
| later_span: parent_label.span, | ||
| option_name: sym::parent_label, | ||
| }, | ||
| parent_label.span, | ||
| ); | ||
| } else { | ||
| first.parent_label = Some(parent_label); | ||
| } | ||
| } |
There was a problem hiding this comment.
You can just call merge here instead? Like for message and label? Change parent_label to be of type Option<(Span, _)> instead if you need to.
There was a problem hiding this comment.
Fair enough, I avoided touching the HIR code since the files involved were outside the scope of this refactor
| let Directive { is_rustc_attr, filters, message, label, notes, parent_label } = later.1; | ||
|
|
||
| // Evaluation visits every filter before the root directive. Appending filters and notes | ||
| // preserves their source order across separate attribute occurrences. |
There was a problem hiding this comment.
This comment seems maybe a little bit out of place. And it reads like it vaguely implies that the ordering of the operations below it matters which afaik doesn't matter.
If you want to document what merge_directives does that would be best as a doc comment on the function itself.
| The `#[rustc_on_unimplemented]` attribute lets you specify a custom error | ||
| message for when a particular trait isn't implemented on a type placed in a | ||
| position that needs that trait. The attribute will let you filter on | ||
| various types, with `on`: | ||
|
|
||
| ```compile_fail,E0232 | ||
| ```ignore (error is no longer emitted) | ||
| #![feature(rustc_attrs)] | ||
| #![allow(internal_features)] |
There was a problem hiding this comment.
Can you edit this to say that now a lint is emitted instead?
There was a problem hiding this comment.
Sorry, I mean like in the prose above the example. As it reads now it's just kinda weird and confusing (and it wasn't great). Feel free to remove all the prose and example and just replace it with smth like
this used to emitted on an invalid rustc_on_unimplemented filter,
the `malformed_diagnostic_filters` lint is now emitted instead.
remember, good documentation > no documentation >>>> bad documentation.
There was a problem hiding this comment.
Done. I was trying to mirror neighboring error code files.
@rustbot ready
|
Reminder, once the PR becomes ready for a review, use |
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred to diagnostic attributes. cc @mejrs |
| The `#[rustc_on_unimplemented]` attribute lets you specify a custom error | ||
| message for when a particular trait isn't implemented on a type placed in a | ||
| position that needs that trait. The attribute will let you filter on | ||
| various types, with `on`: | ||
|
|
||
| ```compile_fail,E0232 | ||
| ```ignore (error is no longer emitted) | ||
| #![feature(rustc_attrs)] | ||
| #![allow(internal_features)] |
There was a problem hiding this comment.
Sorry, I mean like in the prose above the example. As it reads now it's just kinda weird and confusing (and it wasn't great). Feel free to remove all the prose and example and just replace it with smth like
this used to emitted on an invalid rustc_on_unimplemented filter,
the `malformed_diagnostic_filters` lint is now emitted instead.
remember, good documentation > no documentation >>>> bad documentation.
e194aa6 to
0a4168a
Compare
…, r=mejrs Coalesce `rustc_on_unimplemented` attributes and lint malformed filters Discussion on [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/613179950). Best reviewed in commit order. r? @mejrs
…, r=mejrs Coalesce `rustc_on_unimplemented` attributes and lint malformed filters Discussion on [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/613179950). Best reviewed in commit order. r? @mejrs
…, r=mejrs Coalesce `rustc_on_unimplemented` attributes and lint malformed filters Discussion on [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/613179950). Best reviewed in commit order. r? @mejrs
…uwer Rollup of 21 pull requests Successful merges: - #160100 (Add "system" option to `override-allocator` directive) - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - #160233 (Bubble bad path error while parsing field to avoid unecessary second error) - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - #154202 (rustfmt: Format `cfg_select!`) - #158835 (rustc_passes: lint unused `#[path]` attributes on inline modules) - #159520 (Suggest `Vec<T>` instead of `[T]`) - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - #160066 (rustc_middle: lint attribute cleanups) - #160085 (Remove various superfluous lint attributes) - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - #160157 (Remove outdated comments from `va_list.rs`) - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - #160244 (Rename splat to rustc_splat in error messages) - #160246 (dont fire `unused_mut` on `&pin mut self`) - #160247 (Configure backport nominations for rustfmt) - #160274 (renovate: update lock files weekly)
…uwer Rollup of 22 pull requests Successful merges: - #160100 (Add "system" option to `override-allocator` directive) - #160220 (Refactor: shrink region ext traits) - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler) - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends) - #160233 (Bubble bad path error while parsing field to avoid unecessary second error) - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`) - #154202 (rustfmt: Format `cfg_select!`) - #159520 (Suggest `Vec<T>` instead of `[T]`) - #159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts) - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser) - #160066 (rustc_middle: lint attribute cleanups) - #160085 (Remove various superfluous lint attributes) - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters) - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver) - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`) - #160157 (Remove outdated comments from `va_list.rs`) - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint) - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type) - #160244 (Rename splat to rustc_splat in error messages) - #160246 (dont fire `unused_mut` on `&pin mut self`) - #160247 (Configure backport nominations for rustfmt) - #160274 (renovate: update lock files weekly)
Rollup merge of #160113 - qaijuang:coalesce_on_unimplemented, r=mejrs Coalesce `rustc_on_unimplemented` attributes and lint malformed filters Discussion on [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/613179950). Best reviewed in commit order. r? @mejrs
Discussion on Zulip.
Best reviewed in commit order.
r? @mejrs