resolve paths in rustc_on_unimplemented#156505
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
| Path { | ||
| #[visitable(ignore)] | ||
| name: Name, | ||
| id: NodeId, | ||
| value: Path, | ||
| }, | ||
| DefId { | ||
| #[visitable(ignore)] | ||
| name: Name, | ||
| #[visitable(ignore)] | ||
| def_id: Option<DefId>, | ||
| }, |
There was a problem hiding this comment.
These are switched during ast lowering, so we never have a Path variant inside a hir::Attribute. An alternative is to make NameValue generic over these two but that introduces a lot of generics everywhere. I tried that first and it was quite messy.
| /// 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)>, | ||
| #[visitable(ignore)] |
There was a problem hiding this comment.
I'm not sure about #[visitable(ignore)] here and elsewhere. Can I just put these on everything that doesn't have something "ast-y" like NodeId in it?
| /// An AST-based "inert" attribute. | ||
| /// | ||
| /// These represent otherwise inert attributes. Instead of creating or modifying items like | ||
| /// a macro would, they instead attach state to these items which is carried through | ||
| /// ast/hir lowering and then emitted like an actual inert attribute. | ||
| InertAttr( | ||
| /// An expander with signature (&mut AST). | ||
| Arc<dyn AstAnnotate + sync::DynSync + sync::DynSend>, | ||
| ), |
There was a problem hiding this comment.
I decided on a new variant for several reasons:
- I wanted to use ArgParser so I can reuse the implementation in
rustc_attr_parsing, keeping that and a MetaItem impl at the same time is too error prone. - I would like to experiment with making this masquerade like an actual inert attribute so this can be stabilized without it being observable by other macros.
|
The Clippy subtree was changed cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
|
The Rustfmt subtree was changed cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Is DSL used by |
|
It is documented at https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented |
|
(I started reviewing and will continue either tomorrow or on Friday.) |
|
As you could guess from my previous comments in the related threads (paths and types in
|
|
If there's growing desire to add some activity to a number of built-in attributes, and there's no desire to turn all of those attributes into macros (which are active by definition), then I guess we have to make some framework for adding more active built-in attributes. This is unfortunate, but maybe bearable. |
|
The general problem is as follows:
|
|
I think it's important for the generated AST (and then HIR, etc) to not be a part of Attribute IR. I'd also like to decouple the AST generation from This logic would probably run from There's some choice in where to put the AST nodes generated by the active attributes.
This is sort of a stylistic choice, in either location they would be processed by all the regular AST passes, visited by AST visitors, etc. Semi-relevant comment - #154708 (comment). |
|
One small extra bit of novelty that this PR adds is adding not just an active built-in attribute, but an active built-in tool attribute. |
|
(Not sure what is the correct label here now, something like waiting-on-design, but marking as waiting-on-author to maintain my review queue.) |
View all comments
This creates a new (unstable)
#[diagnostic::rustc_on_unimplemented]attribute that compares types by defid, rather than stringly at error reporting time. This is necessary to finally fix issues like #112923. This is the first step in our (@estebank and mine) plans to eventually stabilize a subset ofrustc_on_unimplemented's filtering api.It does this by acting as an attribute macro which passes the attribute through ast and resolving and then emits it as an attribute during ast lowering.
For simplicity the functionality is rather limited at the time, that's to be expanded in follow up prs:
PrintAttributeandast_prettyimpls need improvementr? @petrochenkov
@JonathanBrouwer you might be interested in reviewing as well
cc @estebank @weiznich
@BarronKane you might be interested in looking at the implementation