You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,7 +13,7 @@ This RFC adds three new attributes:
13
13
14
14
Note that this does not add any new functionality into the compiler; it only relaxes the current restrictions. While `rustc` verifies that tool attributes and lints are syntactically valid and do not cause ambiguity during name resolution, it does no extra processing.
15
15
16
-
# Motivation
16
+
##Motivation
17
17
[motivation]: #motivation
18
18
19
19
There are [several tools predefined in the tool namespace][builtin-tools]. These tools are hard-coded, and cannot be extended with user-defined tools. There are many external programs that would benefit from being able to annotate specific portions of a crate or register custom lints without the compiler raising an error.
@@ -32,7 +32,7 @@ Here is a short summary of the built-in tools:
32
32
|`rustc`|✅ (with `-Z unstable-options`)|❌|
33
33
|`diagnostic`|❌|✅|
34
34
35
-
## Why support custom lints?
35
+
###Why support custom lints?
36
36
37
37
There are several crates, such as `bevy` and `regex`, that would benefit from API-specific lints that encourage specific styles or warn against potential footguns. While it is possible to create a custom `rustc` driver that registers these lints, any reference to them in code would cause the default compiler to raise an error.
38
38
@@ -50,7 +50,7 @@ There are also several linting tools that don't make sense to upstream to Clippy
50
50
-[`marker`](https://github.com/rust-marker/marker) (custom, user-extensible lints, but a different approach)
51
51
-[`klint`](https://github.com/Rust-for-Linux/linux/pull/958) (Rust-for-Linux specific linter)
52
52
53
-
## Why support custom attributes?
53
+
###Why support custom attributes?
54
54
55
55
There are also some tools that would benefit from using developer-added metadata on portions of source code:
56
56
@@ -66,10 +66,10 @@ There are also some tools that would benefit from using developer-added metadata
Several official tools let you configure their behavior on specific parts of your code. For example, Clippy lets you use `#[warn(clippy::as_ptr_cast_mut)]` to warn on that lint for a single item, and Rustfmt lets you use `#[rustfmt::skip]` to avoid formatting a single item. You can also do this for external tools that are not provided in the Rust toolchain. See the documentation of those tools for the lints and attributes they support.
75
75
@@ -79,7 +79,7 @@ Crate-level lints for external tools can use `#![warn(some_tool::lint_name)]`, l
79
79
Tools may also support a custom configuration format that allows you to control lints for your whole workspace at once.
80
80
Consult the documentation of the tool you use.
81
81
82
-
### Fixing name resolution errors
82
+
####Fixing name resolution errors
83
83
84
84
Note that `register_tool` changes name resolution, and may give errors if you have a crate named `some_tool`.
85
85
The compiler will suggest ways to fix the new errors.
@@ -118,7 +118,7 @@ Overlaps like this are expected to be rare in practice.
The Rust language can be extended and analyzed using external tools. If your tool can parse Rust, you may wish to allow configuring it at sub-crate levels (e.g. individual functions, types, and modules). To reuse the same syntax as the official tools, like Clippy and Rustfmt, instruct your users to add `#![register_lint_tool(your_tool)]` (if your tool only adds new lints) or `#![register_attribute_tool(your_tool)]` (if your tool only adds new attributes). If your tool supports both lints and attributes, use `#![register_tool(your_tool]`. Then, instruct your users to add either `#[warn(your_tool::your_lint)]` or `#[your_tool::your_attribute(your_tokens)]` as appropriate.
124
124
@@ -133,12 +133,12 @@ Please do *not* suggest using `#[cfg_attr(your_tool, your_attribute)]`. Doing so
133
133
134
134
Please do *not* use tool attributes for metadata that changes the meaning of the code. At that point you are parsing a dialect of Rust, and there is no indication for your users that their code will be interpreted differently by your tool than by the compiler. For example, `#[must_use]` and `#[automatically_derived]` would be suitable for tool attributes, but `#[repr]` and `#[panic_handler]` are not, because they change the meaning of the code. For that use case, use proc-macros, generated code, or bare (un-namespaced) attributes instead, all of which will give a hard error if they cannot be understood by the compiler. If absolutely necessary to use bare attributes, use a C-style namespace like `#[rustc_const_stable]`.
The tool prelude is separated into the tool attribute prelude (which is in the type namespace) and the lint prelude (which is only active inside lint controls).
165
165
@@ -228,7 +228,7 @@ This is technically a breaking change since it can produce new ambiguity errors
- We could "just not do this". That makes it harder to write external tools, and in practice just means that people use `cfg_attr` instead of a namespace, which seems strictly worse.
@@ -255,7 +255,7 @@ The lang team [expressed a concern][lang concern] in 2022 that the name `registe
-[`clang-tidy`], [`pylint`], [`eslint`], and [`review`] (a racket linter) use inline comments. Whether these count as namespacing is debatable; pylint and eslint include their name in the inline comment and clang-tidy does not. `review` allows both `review: ignore` and `lint: ignore`.
@@ -275,12 +275,12 @@ The lang team [expressed a concern][lang concern] in 2022 that the name `registe
How does this interact with [proc-macro lints][`proc_macro_lint`]?
282
282
283
-
# Future possibilities
283
+
##Future possibilities
284
284
[future-possibilities]: #future-possibilities
285
285
286
286
- We could allow registering tools in Cargo.toml (with a `package.tools` or `workspace.tools` field). This would avoid duplicating tool registration for each crate in the package/workspace. This depends on [`--crate-attr`] being stabilized.
0 commit comments