Skip to content

Commit 71dc466

Browse files
authored
Refine the lintstore section (rust-lang#1429)
1 parent b08631e commit 71dc466

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

src/doc/rustc-dev-guide/src/diagnostics/lintstore.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Lints
2+
23
This page documents some of the machinery around lint registration and how we
34
run lints in the compiler.
45

@@ -8,18 +9,26 @@ everything rotates. It's not available during the early parts of compilation
89
lints, which can only happen after plugin registration.
910

1011
## Lints vs. lint passes
12+
1113
There are two parts to the linting mechanism within the compiler: lints and
1214
lint passes. Unfortunately, a lot of the documentation we have refers to both
1315
of these as just "lints."
1416

1517
First, we have the lint declarations themselves: this is where the name and
1618
default lint level and other metadata come from. These are normally defined by
1719
way of the [`declare_lint!`] macro, which boils down to a static with type
18-
`&rustc_session::lint::Lint`.
20+
[`&rustc_lint_defs::Lint`].
21+
22+
First, we have the lint declarations themselves,
23+
and this is where the name and default lint level and other metadata come from.
24+
These are normally defined by way of the [`declare_lint!`] macro,
25+
which boils down to a static with type [`&rustc_lint_defs::Lint`]
26+
(although this may change in the future,
27+
as the macro is somewhat unwieldy to add new fields to,
28+
like all macros).
1929

20-
As of <!-- date-check --> February 2022, we lint against direct declarations
21-
without the use of the macro today (although this may change in the future, as
22-
the macro is somewhat unwieldy to add new fields to, like all macros).
30+
As of <!-- date-check --> Aug 2022,
31+
we lint against direct declarations without the use of the macro.
2332

2433
Lint declarations don't carry any "state" - they are merely global identifiers
2534
and descriptions of lints. We assert at runtime that they are not registered
@@ -34,8 +43,10 @@ lints are emitted as part of other work (e.g., type checking, etc.).
3443
## Registration
3544

3645
### High-level overview
37-
In [`rustc_interface::register_plugins`] the [`LintStore`] is created and all
38-
lints are registered.
46+
47+
In [`rustc_interface::register_plugins`],
48+
the [`LintStore`] is created,
49+
and all lints are registered.
3950

4051
There are four 'sources' of lints:
4152

@@ -61,6 +72,7 @@ then invoke the lint pass methods. The lint pass methods take `&mut self` so
6172
they can keep track of state internally.
6273

6374
#### Internal lints
75+
6476
These are lints used just by the compiler or plugins like `clippy`. They can be
6577
found in `rustc_lint::internal`.
6678

@@ -73,16 +85,20 @@ function which is called when constructing a new lint store inside
7385
[`rustc_lint::new_lint_store`].
7486

7587
### Builtin Lints
76-
These are primarily described in two places: `rustc_session::lint::builtin` and
77-
`rustc_lint::builtin`. Often the first provides the definitions for the lints
78-
themselves, and the latter provides the lint pass definitions (and
79-
implementations), but this is not always true.
8088

81-
The builtin lint registration happens in the [`rustc_lint::register_builtins`]
82-
function. Just like with internal lints, this happens inside of
83-
[`rustc_lint::new_lint_store`].
89+
These are primarily described in two places,
90+
`rustc_lint_defs::builtin` and `rustc_lint::builtin`.
91+
Often the first provides the definitions for the lints themselves,
92+
and the latter provides the lint pass definitions (and implementations),
93+
but this is not always true.
94+
95+
The builtin lint registration happens in
96+
the [`rustc_lint::register_builtins`] function.
97+
Just like with internal lints,
98+
this happens inside of [`rustc_lint::new_lint_store`].
8499

85100
#### Plugin lints
101+
86102
This is one of the primary use cases remaining for plugins/drivers. Plugins are
87103
given access to the mutable `LintStore` during registration (which happens
88104
inside of [`rustc_interface::register_plugins`]) and they can call any
@@ -94,6 +110,7 @@ diagnostics and help text; otherwise plugin lints are mostly just as first
94110
class as rustc builtin lints.
95111

96112
#### Driver lints
113+
97114
These are the lints provided by drivers via the `rustc_interface::Config`
98115
[`register_lints`] field, which is a callback. Drivers should, if finding it
99116
already set, call the function currently set within the callback they add. The
@@ -102,6 +119,7 @@ best way for drivers to get access to this is by overriding the
102119
structure.
103120

104121
## Compiler lint passes are combined into one pass
122+
105123
Within the compiler, for performance reasons, we usually do not register dozens
106124
of lint passes. Instead, we have a single lint pass of each variety (e.g.,
107125
`BuiltinCombinedModuleLateLintPass`) which will internally call all of the
@@ -121,3 +139,4 @@ approach, it is beneficial to do so for performance reasons.
121139
[`declare_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_lint.html
122140
[`declare_tool_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_tool_lint.html
123141
[`register_lints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html#structfield.register_lints
142+
[`&rustc_lint_defs::Lint`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/struct.Lint.html

0 commit comments

Comments
 (0)