-
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 for #![register_tool]
#66079
Comments
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
Is the tool’s name an arbitrary identifier, that doesn’t necessarily map for example to any crate name? |
@SimonSapin |
Use `#![register_tool]` instead of `Registry::register_attribute` CC rust-lang/rust#66344, rust-lang/rust#66079
Use `#![register_tool]` instead of `Registry::register_attribute` CC rust-lang/rust#66344, rust-lang/rust#66079
…sper rustc_plugin: Remove `Registry::register_attribute` Legacy plugins cannot register inert attributes anymore. The preferred replacement is to use `register_tool` ([tracking issue](rust-lang#66079)). ```rust #![register_tool(servo)] #[servo::must_root] struct S; ``` The more direct replacement is `register_attribute` ([tracking issue](rust-lang#66080)) ```rust #![register_attr(must_root)] #[must_root] struct S; ``` , but it requires registering each attribute individually rather than registering the tool once, and is more likely to be removed rather than stabilized.
…sper rustc_plugin: Remove `Registry::register_attribute` Legacy plugins cannot register inert attributes anymore. The preferred replacement is to use `register_tool` ([tracking issue](rust-lang#66079)). ```rust #![register_tool(servo)] #[servo::must_root] struct S; ``` The more direct replacement is `register_attribute` ([tracking issue](rust-lang#66080)) ```rust #![register_attr(must_root)] #[must_root] struct S; ``` , but it requires registering each attribute individually rather than registering the tool once, and is more likely to be removed rather than stabilized.
This appears to only work for attributes, not lints. #![feature(register_tool)]
#![register_tool(xyz)]
#![warn(xyz::my_lint)]
|
AFAIK, registering a lint tool is useless without also registering actual lints, which are registered with |
Then there is no way at all to add tool lints, because rust/compiler/rustc_lint/src/levels.rs Lines 307 to 317 in edeee91
rust/compiler/rustc_ast/src/attr/mod.rs Lines 36 to 38 in edeee91
|
For what it’s worth this is how Servo uses this feature: https://github.com/servo/servo/blob/92d6c89a8f3ac3ace5dbf65871dfb7c188ce3f95/components/script_plugins/lib.rs |
@SimonSapin that looks like it only uses a tool attribute and not a lint. |
To clarify, we don't necessarily need to prohibit name conflicts; rather, we need to document what happens in that case. If what should happen is "silently shadow", we should document that. |
What about making |
I agree with this -- it's not obvious to me that we want these in attributes, which are harder to e.g. manage across an entire workspace. I think Manish is right in #57921 (comment) that -Z attributes can be harder to pass, particularly on a workspace basis today, but I'm not sure that's actually the right motivation for not doing things via the CLI, it just means that we need accompanying support in Cargo (or other build systems). That obviously requires its own design work. I think that a design document laying out the details for how both end-users consuming tools and tool authors should think about these attributes would be useful in moving forward here. |
I would definately like the attribute and lint controls separate. For https://github.com/LightningCreations/lccc, I want the ability to support additional lints via its own namespace, however, the namespace is also used for attributes. Unlike, e.g. |
From the previous discussion, it sounds like the main concern with stabilizing this feature is the question of how attributes should be handled and what implications this will have for the future. For external linters, the main concern is the ability to use lint names in lint attributes, like this: #[allow(marker::super_helpful_lint)]
fn unknown_linter() {} Which currently triggers E0710. (See Playground) Would it maybe be possible to reduce the error to a lint trigger? That would unblock external linters, while leaving all options open when it comes to attributes and other related tool discussions. It would also be inline with the |
Hey lang team, could you maybe discuss my suggestion to reduce the E0710 error to a lint trigger? (See comment above) @rustbot label +I-lang-nominated |
We talked about this in today's @rust-lang/lang meeting, and we still hold the position that this needs an RFC before stabilizing, to answer several of the questions here. |
Also, the questions in #66079 (comment) seem like they should still apply. |
@xFrednet, I would have concerns about the approach of downgrading that from a hard error to a lint. It'd be OK to explore that in the "alternatives' section of the aforementioned RFC, though. |
@xFrednet also, in case its not clear: the act of downgrading the existing hard error to a lint itself a stabilization action (since it would be part of the new stabilized surface of the language). Thus, the T-lang design team views such a path as best described in the context of an overall plan for stabilizing this feature as a whole. |
Alright, thank you for the feedback! In the coming months, I sadly won't have time to work on an RFC. If anyone else is interested, I'm happy to share my use case with Marker and also help with the RFC. |
A part of #44690.
Some tools (
rustfmt
andclippy
) used in tool attributes are hardcoded in the compiler.We need some way to introduce them without hardcoding as well.
#66070 introduced 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.
The text was updated successfully, but these errors were encountered: