@@ -4,9 +4,8 @@ This page documents some of the machinery around lint registration and how we
4
4
run lints in the compiler.
5
5
6
6
The [ ` LintStore ` ] is the central piece of infrastructure, around which
7
- everything rotates. It's not available during the early parts of compilation
8
- (i.e., before TyCtxt) in most code, as we need to fill it in with all of the
9
- lints, which can only happen after plugin registration.
7
+ everything rotates. The ` LintStore ` is held as part of the [ ` Session ` ] , and it
8
+ gets populated with the list of lints shortly after the ` Session ` is created.
10
9
11
10
## Lints vs. lint passes
12
11
@@ -39,25 +38,23 @@ lints are emitted as part of other work (e.g., type checking, etc.).
39
38
40
39
### High-level overview
41
40
42
- In [ ` rustc_interface::register_plugins ` ] ,
41
+ In [ ` rustc_interface::run_compiler ` ] ,
43
42
the [ ` LintStore ` ] is created,
44
43
and all lints are registered.
45
44
46
- There are four 'sources' of lints:
45
+ There are three 'sources' of lints:
47
46
48
47
* internal lints: lints only used by the rustc codebase
49
48
* builtin lints: lints built into the compiler and not provided by some outside
50
49
source
51
- * plugin lints: lints created by plugins through the plugin system.
52
50
* ` rustc_interface::Config ` [ ` register_lints ` ] : lints passed into the compiler
53
51
during construction
54
52
55
53
Lints are registered via the [ ` LintStore::register_lint ` ] function. This should
56
54
happen just once for any lint, or an ICE will occur.
57
55
58
56
Once the registration is complete, we "freeze" the lint store by placing it in
59
- an ` Lrc ` . Later in the driver, it's passed into the ` GlobalCtxt ` constructor
60
- where it lives in an immutable form from then on.
57
+ an ` Lrc ` .
61
58
62
59
Lint passes are registered separately into one of the categories
63
60
(pre-expansion, early, late, late module). Passes are registered as a closure
@@ -68,8 +65,8 @@ they can keep track of state internally.
68
65
69
66
#### Internal lints
70
67
71
- These are lints used just by the compiler or plugins like ` clippy ` . They can be
72
- found in ` rustc_lint::internal ` .
68
+ These are lints used just by the compiler or drivers like ` clippy ` . They can be
69
+ found in [ ` rustc_lint::internal ` ] .
73
70
74
71
An example of such a lint is the check that lint passes are implemented using
75
72
the ` declare_lint_pass! ` macro and not by hand. This is accomplished with the
@@ -92,18 +89,6 @@ the [`rustc_lint::register_builtins`] function.
92
89
Just like with internal lints,
93
90
this happens inside of [ ` rustc_lint::new_lint_store ` ] .
94
91
95
- #### Plugin lints
96
-
97
- This is one of the primary use cases remaining for plugins/drivers. Plugins are
98
- given access to the mutable ` LintStore ` during registration (which happens
99
- inside of [ ` rustc_interface::register_plugins ` ] ) and they can call any
100
- functions they need on the ` LintStore ` , just like rustc code.
101
-
102
- Plugins are intended to declare lints with the ` plugin ` field set to true
103
- (e.g., by way of the [ ` declare_tool_lint! ` ] macro), but this is purely for
104
- diagnostics and help text; otherwise plugin lints are mostly just as first
105
- class as rustc builtin lints.
106
-
107
92
#### Driver lints
108
93
109
94
These are the lints provided by drivers via the ` rustc_interface::Config `
@@ -127,11 +112,13 @@ approach, it is beneficial to do so for performance reasons.
127
112
128
113
[ `LintStore` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html
129
114
[ `LintStore::register_lint` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html#method.register_lints
130
- [ `rustc_interface::register_plugins` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.register_plugins.html
131
115
[ `rustc_lint::register_builtins` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.register_builtins.html
132
116
[ `rustc_lint::register_internals` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.register_internals.html
133
117
[ `rustc_lint::new_lint_store` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.new_lint_store.html
134
118
[ `declare_lint!` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_lint.html
135
119
[ `declare_tool_lint!` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_tool_lint.html
136
120
[ `register_lints` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html#structfield.register_lints
137
121
[ `&rustc_lint_defs::Lint` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/struct.Lint.html
122
+ [ `Session` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/struct.Session.html
123
+ [ `rustc_interface::run_compiler` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html#reexport.run_compiler
124
+ [ `rustc_lint::internal` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/internal/index.html
0 commit comments