-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue: RFC 2103 - attributes for tools #44690
Comments
As mentioned on the Gitter chat, I'm willing to take a try at this! Should just need pointed in the right direction :) |
@petrochenkov I suspect you'd be the best one to write up some mentoring instructions here. Any chance you can put some thought into it? |
I'll definitely be getting myself familiar with the parser and AST in the mean time, so no big rush! |
OK, since @petrochenkov has been busy, let me take a shot at some notes. Perhaps he can correct me if he thinks things could be done a better way. To start, the structure that represents attributes in the AST is called Basically, the model is this: within the AST, an attribute is just a token tree. However, sometimes, the compiler tries to parse and impose structure on this tree by parsing it as something like This parsing that converts an However, we must also decide how to expand |
@rep-nop hey, I'm just checking in -- are you still hacking on this? How's it going? |
@nikomatsakis sorry, school has been keeping me fairly busy lately but things look like they're starting to lighten up for now! I spent ~2ish hours about 2 weeks ago on it and was getting somewhere I think, but I'm going to be hopefully trying a new approach that I hope will work better within the week (if not today even!) |
@rep-nop great =) Let me know if I can be of any assistance. |
Okay so while doing a more thorough read through the RFC I came up with a quick requirements document to track progress on it (below, it wont let me attach it for some reason? Let me know if I missed anything major or important!). The only part of the RFC I don't think I understand very well is the "Activation and unused attributes/lints" section. It talks about
|
@nikomatsakis @nrc any input? :) |
@rep-nop seems reasonable. =)
I think what this means it that we won't accept |
@nikomatsakis so is that something that we're going to have to keep track of or..? Also, any idea where the whitelist will be located inside of the compiler? Currently, I just have it inside of the function as an array and the function checks against just the tool name (so should I make an attribute list for each one of them also?) and error if its not one of the whitelisted tools. The RFC talks about adding tools to that list from inside the source, however it looks like it wasn't decided on what that'd look like. @petrochenkov any suggestions/tips for a proper implementation? |
@rep-nop |
Yes. There are essentially two lists - one of lints and one of attributes. The compiler only cares about the active tools (initially both lists will be empty). So if the active attributes whitelist is
Yes, they are both on their way. The requirements looks good.
Good question! The lists could be provided by the build system, probably as an env var (or two). It should live somewhere that deals with tools. They could be hard-wired into the compiler, but I'm not really sure where I would put it. I don't think we need to worry about adding tools to the whitelist, we can do that manually. In terms of implementation, I think the checking of the whitelist names in attributes should happen either during macro name resolution or just afterwards. The key to when to do the check is about the behaviour we want with precedence (tool vs macro). If you have questions, @jseyfried is probably the best person to ask. |
Thanks for the answers! :) @nrc right now I have it checking the names at name resolution when it detects a path inside the attribute, which wasn't too difficult to get a quick and crude implementation done (which I believe is linked above in a commit I did). I'll look into using an env var to specify tool names! |
@rep-nop Do you have any update? This is (potentially) blocking rustfmt from reaching 1.0, so I would like to push this forward. If you do not have enough time to work on this, I am willing to take a shot at this. |
@topecongiro ah if this is going to be blocking rustfmt I'll release it as I'm going to be fairly busy this upcoming semester. I was unfortunately not able to progress as much as I'd liked to have for various reasons, so have at it! :) |
I would like to continue working on this, except @topecongiro wants to pick this up again? Since #47773 already implemented the |
@flip1995 I do not think that I can update the initial PR any time soon. So it will be great if you are going to work on this! |
Support registering inert attributes and attribute tools using crate-level attributes And remove `#[feature(custom_attribute)]`. (`rustc_plugin::Registry::register_attribute` is not removed yet, I'll do it in a follow up PR.) ```rust #![register_attr(my_attr)] #![register_tool(my_tool)] #[my_attr] // OK #[my_tool::anything] // OK fn main() {} ``` --- Some tools (`rustfmt` and `clippy`) used in tool attributes are hardcoded in the compiler. We need some way to introduce them without hardcoding as well. This PR introduces a way to do it with a crate level attribute. The previous attempt to introduce them through command line (#57921) met some resistance. This probably needs to go through an RFC before stabilization. However, I'd prefer to land *this* PR without an RFC to able to remove `#[feature(custom_attribute)]` and `Registry::register_attribute` while also providing a replacement. --- `register_attr` is a direct replacement for `#![feature(custom_attribute)]` (#29642), except it doesn't rely on implicit fallback from unresolved attributes to custom attributes (which was always hacky and is the primary reason for the removal of `custom_attribute`) and requires registering the attribute explicitly. It's not clear whether it should go through stabilization or not. It's quite possible that all the uses should migrate to `#![register_tool]` (#66079) instead. --- Details: - The naming is `register_attr`/`register_tool` rather than some `register_attributes` (plural, no abbreviation) for consistency with already existing attributes like `cfg_attr`, or `feature`, etc. --- Previous attempt: #57921 cc #44690 Tracking issues: #66079 (`register_tool`), #66080 (`register_attr`) Closes #29642
I opened #83216 which makes |
Is this done after #83216, or is there more left to do? |
Well, register_tool is still unstable. I think it's tracked elsewhere, I forget which issue. |
|
I cannot find any existing issue covering this particular case: I currently use When I replace all these with |
This is one of several stability checking holes in expression/statement attributes :) |
The workaround is to place |
visiting for backlog bonanza. It seems like as of end of 2019, there was still some remaining work to be done here. It is not super clear what remains to be done. For now, marking with implementation unfinished. @rustbot label: S-tracking-impl-incomplete |
Visited during compiler team tracking issue triage. After skimming through the discussion, it's not clear at this time what the current state of this feature is. For anyone who wants to help move this forward, I think the most valuable thing at this time would be a summary of what work has been completed and what (if any) known issues are with the current implementation as well as any salient points from the prior discussion. |
Support scoped attributes for white-listed tools, e.g.,
#[rustfmt::skip]
RFC
discussion thread
Current status: stabilised for attributes, some work still to do on lints.
The text was updated successfully, but these errors were encountered: