Skip to content

Commit 82196c0

Browse files
committed
Fix register_tool headers
This updates section headers to use Markdown 2nd level headings. As part of #3883 we switched the template to not use level-1 headings
1 parent 1eba84a commit 82196c0

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

text/3808-register-tool.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- RFC PR: [#3803](https://github.com/rust-lang/rfcs/pull/3808)
44
- Rust Issue: [rust-lang/rust#66079](https://github.com/rust-lang/rust/issues/66079)
55

6-
# Summary
6+
## Summary
77
[summary]: #summary
88

99
This RFC adds three new attributes:
@@ -13,7 +13,7 @@ This RFC adds three new attributes:
1313

1414
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.
1515

16-
# Motivation
16+
## Motivation
1717
[motivation]: #motivation
1818

1919
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:
3232
|`rustc`|✅ (with `-Z unstable-options`)||
3333
|`diagnostic`|||
3434

35-
## Why support custom lints?
35+
### Why support custom lints?
3636

3737
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.
3838

@@ -50,7 +50,7 @@ There are also several linting tools that don't make sense to upstream to Clippy
5050
- [`marker`](https://github.com/rust-marker/marker) (custom, user-extensible lints, but a different approach)
5151
- [`klint`](https://github.com/Rust-for-Linux/linux/pull/958) (Rust-for-Linux specific linter)
5252

53-
## Why support custom attributes?
53+
### Why support custom attributes?
5454

5555
There are also some tools that would benefit from using developer-added metadata on portions of source code:
5656

@@ -66,10 +66,10 @@ There are also some tools that would benefit from using developer-added metadata
6666
[c2rust]: https://github.com/immunant/c2rust/blob/d28087df86d7fca8532d8679d35efec66f074f8b/c2rust-refactor/tests/reorganize_definitions/old.rs#L18
6767
[Source Map]: https://web.dev/articles/source-maps
6868

69-
# Guide-level explanation
69+
## Guide-level explanation
7070
[guide-level-explanation]: #guide-level-explanation
7171

72-
## For users of external tools
72+
### For users of external tools
7373

7474
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.
7575

@@ -79,7 +79,7 @@ Crate-level lints for external tools can use `#![warn(some_tool::lint_name)]`, l
7979
Tools may also support a custom configuration format that allows you to control lints for your whole workspace at once.
8080
Consult the documentation of the tool you use.
8181

82-
### Fixing name resolution errors
82+
#### Fixing name resolution errors
8383

8484
Note that `register_tool` changes name resolution, and may give errors if you have a crate named `some_tool`.
8585
The compiler will suggest ways to fix the new errors.
@@ -118,7 +118,7 @@ Overlaps like this are expected to be rare in practice.
118118
[`bevy_lint`]: https://thebevyflock.github.io/bevy_cli/bevy_lint/
119119
[Bevy game engine]: https://bevyengine.org/
120120

121-
## For authors of external tools
121+
### For authors of external tools
122122

123123
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.
124124

@@ -133,12 +133,12 @@ Please do *not* suggest using `#[cfg_attr(your_tool, your_attribute)]`. Doing so
133133

134134
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]`.
135135

136-
# Reference-level explanation
136+
## Reference-level explanation
137137
[reference-level-explanation]: #reference-level-explanation
138138

139-
## Language
139+
### Language
140140

141-
### Background: name resolution of preludes
141+
#### Background: name resolution of preludes
142142

143143
Currently, names in the type namespace are resolved in [the following order](https://github.com/rust-lang/reference/pull/1765):
144144

@@ -159,7 +159,7 @@ extern crate rustfmt; // or --extern rustfmt
159159
fn foo ( ) { }
160160
```
161161

162-
### Semantics
162+
#### Semantics
163163

164164
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).
165165

@@ -228,7 +228,7 @@ This is technically a breaking change since it can produce new ambiguity errors
228228
[`unknown_lints`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unknown-lints
229229
[custom-inner-attributes]: https://github.com/rust-lang/rust/issues/54726
230230

231-
# Drawbacks
231+
## Drawbacks
232232
[drawbacks]: #drawbacks
233233

234234
This makes the rules for name resolution even more complicated.
@@ -241,7 +241,7 @@ The lang team [expressed a concern][lang concern] in 2022 that the name `registe
241241

242242
[lang concern]: https://github.com/rust-lang/rust/issues/66079#issuecomment-1010266282
243243

244-
# Rationale and alternatives
244+
## Rationale and alternatives
245245
[rationale-and-alternatives]: #rationale-and-alternatives
246246

247247
- 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
255255

256256
[crate-attr]: https://github.com/rust-lang/rfcs/pull/3791
257257

258-
# Prior art
258+
## Prior art
259259
[prior-art]: #prior-art
260260

261261
- [`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
275275
[active]: https://rustc-dev-guide.rust-lang.org/attributes.html#non-builtinactive-attributes
276276
[`Resyntax`]: https://docs.racket-lang.org/resyntax/Refactoring_Rules_and_Suites.html#(part._.Exercising_.Fine_.Control_.Over_.Comments)
277277

278-
# Unresolved questions
278+
## Unresolved questions
279279
[unresolved-questions]: #unresolved-questions
280280

281281
How does this interact with [proc-macro lints][`proc_macro_lint`]?
282282

283-
# Future possibilities
283+
## Future possibilities
284284
[future-possibilities]: #future-possibilities
285285

286286
- 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

Comments
 (0)