Skip to content

refactor rustc_on_unimplemented's filtering#155940

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
mejrs:filter
May 3, 2026
Merged

refactor rustc_on_unimplemented's filtering#155940
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
mejrs:filter

Conversation

@mejrs
Copy link
Copy Markdown
Contributor

@mejrs mejrs commented Apr 28, 2026

Previously when you had a

pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}

that condition would control the emission of the message, label, notes etc. I've changed that to

pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted, which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so OnUnimplementedCondition and the like would have to be renamed anyway.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Copy Markdown
Contributor

r? jdonszelmann (I don't mind taking this one for tomorrow :)

pub subcommands: ThinVec<Directive>,
/// This is never nested more than once, i.e. the directives in this
/// thinvec have no filters of their own.
pub filters: ThinVec<(Filter, Directive)>,
Copy link
Copy Markdown
Contributor

@jdonszelmann jdonszelmann Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are toplevel and nested directives any different? like are some fields like mesage always None at the top level? Just wondering if it would maybe make sense to have a TopLevelDirective and a Directive for example

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write a rustc_on_unimplemented attribute that populates all those fields, at both top level and secondary level. Just the filters in that secondary level are always empty.

Regular diagnostic attributes are just a much more restricted form of that, where only message, label and note can be populated.

if it would maybe make sense to have a TopLevelDirective and a Directive for example

It's possible; this structure would essentially be:

pub struct DiagnosticAttrDirective {
    pub message: Option<(Span, FormatString)>,
    pub label: Option<(Span, FormatString)>,
    pub notes: ThinVec<FormatString>,
}

pub struct TopRustcOnUnImplDirective {
    pub filters: ThinVec<(Filter, RustcOnUnImplDirective)>,
    pub message: Option<(Span, FormatString)>,
    pub label: Option<(Span, FormatString)>,
    pub notes: ThinVec<FormatString>,
    pub parent_label: Option<FormatString>,
}

pub struct RustcOnUnImplDirective {
    pub message: Option<(Span, FormatString)>,
    pub label: Option<(Span, FormatString)>,
    pub notes: ThinVec<FormatString>,
    pub parent_label: Option<FormatString>,
}

presumably we can do clever things with generics so we can reuse things and you end up with fields such as filters: ThinVec<!> etc to enforce this at the type level.

The downside of all of this is that everything becomes more complex, boilerplate-y and harder to read. The upside is that it's harder to misuse. But making things harder to misuse is only really important for the unwashed masses. This is important when you write a http framework because arbitrary people are are programming against your code. It's not as important in this case because diagnostic attr parsing infra is only used by people programming in the same crate. These are the same people that might as well just mess up the types themselves - so what is the point?

@jdonszelmann
Copy link
Copy Markdown
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 29, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mejrs
Copy link
Copy Markdown
Contributor Author

mejrs commented Apr 29, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2026
@rust-bors

This comment has been minimized.

@jdonszelmann
Copy link
Copy Markdown
Contributor

Alright, I agree with that reasoning. @bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

📋 This PR cannot be approved because it has merge conflicts. Please resolve the conflicts and try again.

@rustbot

This comment has been minimized.

@jdonszelmann
Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 1, 2026

📌 Commit f9e052d has been approved by jdonszelmann

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 1, 2026
refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
rust-bors Bot pushed a commit that referenced this pull request May 1, 2026
Rollup of 7 pull requests

Successful merges:

 - #152487 (core: drop unmapped ZSTs in array `map`)
 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - #156021 (Clean up some traits)
 - #156028 (Add a `Local::arg(i)` helper constructor)
 - #156037 (Add AcceptContext::expect_no_args)
 - #156040 (Add missing alias to mailmap)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 1, 2026
refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
rust-bors Bot pushed a commit that referenced this pull request May 1, 2026
Rollup of 7 pull requests

Successful merges:

 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - #156021 (Clean up some traits)
 - #156028 (Add a `Local::arg(i)` helper constructor)
 - #156037 (Add AcceptContext::expect_no_args)
 - #156040 (Add missing alias to mailmap)
 - #156048 (Make `diverging_type_vars` a vec of `TyVid`)
rust-bors Bot pushed a commit that referenced this pull request May 2, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #156030 (Make stable hashing names consistent (part 1))
 - #156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - #156021 (Clean up some traits)
 - #156028 (Add a `Local::arg(i)` helper constructor)
 - #156037 (Add AcceptContext::expect_no_args)
 - #156040 (Add missing alias to mailmap)
 - #156048 (Make `diverging_type_vars` a vec of `TyVid`)
 - #156053 (Reuse CTFE MIR for constructors.)
 - #156059 (compiler: Print valid `-Zmir-enable-passes` names if invalid name is used)

Failed merges:

 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156065 (Remove unused spans from AttributeKind)
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 2, 2026
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 2, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs
Copy link
Copy Markdown
Contributor Author

mejrs commented May 2, 2026

@bors r=jdonszelmann

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

📌 Commit 0610172 has been approved by jdonszelmann

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 2, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 2, 2026
refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
rust-bors Bot pushed a commit that referenced this pull request May 3, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #152277 (Validate source snippet when format input is raw string)
 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156065 (Remove unused spans from AttributeKind)
 - #156079 (Move and rename the `clone-never.rs` test)
 - #156091 (change field `tools` on `AttributeParser` to hold `&'tcx RegisteredTools`)
rust-bors Bot pushed a commit that referenced this pull request May 3, 2026
Rollup of 5 pull requests

Successful merges:

 - #155666 (Interning cleanups)
 - #155940 (refactor rustc_on_unimplemented's filtering)
 - #156065 (Remove unused spans from AttributeKind)
 - #156079 (Move and rename the `clone-never.rs` test)
 - #156091 (change field `tools` on `AttributeParser` to hold `&'tcx RegisteredTools`)
@rust-bors rust-bors Bot merged commit b7c6551 into rust-lang:main May 3, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 3, 2026
rust-timer added a commit that referenced this pull request May 3, 2026
Rollup merge of #155940 - mejrs:filter, r=jdonszelmann

refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request May 4, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#156030 (Make stable hashing names consistent (part 1))
 - rust-lang/rust#156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - rust-lang/rust#156021 (Clean up some traits)
 - rust-lang/rust#156028 (Add a `Local::arg(i)` helper constructor)
 - rust-lang/rust#156037 (Add AcceptContext::expect_no_args)
 - rust-lang/rust#156040 (Add missing alias to mailmap)
 - rust-lang/rust#156048 (Make `diverging_type_vars` a vec of `TyVid`)
 - rust-lang/rust#156053 (Reuse CTFE MIR for constructors.)
 - rust-lang/rust#156059 (compiler: Print valid `-Zmir-enable-passes` names if invalid name is used)

Failed merges:

 - rust-lang/rust#155940 (refactor rustc_on_unimplemented's filtering)
 - rust-lang/rust#156065 (Remove unused spans from AttributeKind)
pull Bot pushed a commit to Kokoro2336/rust-analyzer that referenced this pull request May 4, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#156030 (Make stable hashing names consistent (part 1))
 - rust-lang/rust#156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - rust-lang/rust#156021 (Clean up some traits)
 - rust-lang/rust#156028 (Add a `Local::arg(i)` helper constructor)
 - rust-lang/rust#156037 (Add AcceptContext::expect_no_args)
 - rust-lang/rust#156040 (Add missing alias to mailmap)
 - rust-lang/rust#156048 (Make `diverging_type_vars` a vec of `TyVid`)
 - rust-lang/rust#156053 (Reuse CTFE MIR for constructors.)
 - rust-lang/rust#156059 (compiler: Print valid `-Zmir-enable-passes` names if invalid name is used)

Failed merges:

 - rust-lang/rust#155940 (refactor rustc_on_unimplemented's filtering)
 - rust-lang/rust#156065 (Remove unused spans from AttributeKind)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants