1
1
# Lints
2
+
2
3
This page documents some of the machinery around lint registration and how we
3
4
run lints in the compiler.
4
5
@@ -8,6 +9,7 @@ everything rotates. It's not available during the early parts of compilation
8
9
lints, which can only happen after plugin registration.
9
10
10
11
## Lints vs. lint passes
12
+
11
13
There are two parts to the linting mechanism within the compiler: lints and
12
14
lint passes. Unfortunately, a lot of the documentation we have refers to both
13
15
of these as just "lints."
@@ -34,6 +36,7 @@ lints are emitted as part of other work (e.g., type checking, etc.).
34
36
## Registration
35
37
36
38
### High-level overview
39
+
37
40
In [ ` rustc_interface::register_plugins ` ] the [ ` LintStore ` ] is created and all
38
41
lints are registered.
39
42
@@ -61,6 +64,7 @@ then invoke the lint pass methods. The lint pass methods take `&mut self` so
61
64
they can keep track of state internally.
62
65
63
66
#### Internal lints
67
+
64
68
These are lints used just by the compiler or plugins like ` clippy ` . They can be
65
69
found in ` rustc_lint::internal ` .
66
70
@@ -73,6 +77,7 @@ function which is called when constructing a new lint store inside
73
77
[ ` rustc_lint::new_lint_store ` ] .
74
78
75
79
### Builtin Lints
80
+
76
81
These are primarily described in two places: ` rustc_session::lint::builtin ` and
77
82
` rustc_lint::builtin ` . Often the first provides the definitions for the lints
78
83
themselves, and the latter provides the lint pass definitions (and
@@ -83,6 +88,7 @@ function. Just like with internal lints, this happens inside of
83
88
[ ` rustc_lint::new_lint_store ` ] .
84
89
85
90
#### Plugin lints
91
+
86
92
This is one of the primary use cases remaining for plugins/drivers. Plugins are
87
93
given access to the mutable ` LintStore ` during registration (which happens
88
94
inside of [ ` rustc_interface::register_plugins ` ] ) and they can call any
@@ -94,6 +100,7 @@ diagnostics and help text; otherwise plugin lints are mostly just as first
94
100
class as rustc builtin lints.
95
101
96
102
#### Driver lints
103
+
97
104
These are the lints provided by drivers via the ` rustc_interface::Config `
98
105
[ ` register_lints ` ] field, which is a callback. Drivers should, if finding it
99
106
already set, call the function currently set within the callback they add. The
@@ -102,6 +109,7 @@ best way for drivers to get access to this is by overriding the
102
109
structure.
103
110
104
111
## Compiler lint passes are combined into one pass
112
+
105
113
Within the compiler, for performance reasons, we usually do not register dozens
106
114
of lint passes. Instead, we have a single lint pass of each variety (e.g.,
107
115
` BuiltinCombinedModuleLateLintPass ` ) which will internally call all of the
0 commit comments