@@ -4,9 +4,8 @@ This page documents some of the machinery around lint registration and how we
44run lints in the compiler.
55
66The [ ` 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.
109
1110## Lints vs. lint passes
1211
@@ -39,25 +38,23 @@ lints are emitted as part of other work (e.g., type checking, etc.).
3938
4039### High-level overview
4140
42- In [ ` rustc_interface::register_plugins ` ] ,
41+ In [ ` rustc_interface::run_compiler ` ] ,
4342the [ ` LintStore ` ] is created,
4443and all lints are registered.
4544
46- There are four 'sources' of lints:
45+ There are three 'sources' of lints:
4746
4847* internal lints: lints only used by the rustc codebase
4948* builtin lints: lints built into the compiler and not provided by some outside
5049 source
51- * plugin lints: lints created by plugins through the plugin system.
5250* ` rustc_interface::Config ` [ ` register_lints ` ] : lints passed into the compiler
5351 during construction
5452
5553Lints are registered via the [ ` LintStore::register_lint ` ] function. This should
5654happen just once for any lint, or an ICE will occur.
5755
5856Once 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 ` .
6158
6259Lint passes are registered separately into one of the categories
6360(pre-expansion, early, late, late module). Passes are registered as a closure
@@ -68,8 +65,8 @@ they can keep track of state internally.
6865
6966#### Internal lints
7067
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 ` ] .
7370
7471An example of such a lint is the check that lint passes are implemented using
7572the ` declare_lint_pass! ` macro and not by hand. This is accomplished with the
@@ -92,18 +89,6 @@ the [`rustc_lint::register_builtins`] function.
9289Just like with internal lints,
9390this happens inside of [ ` rustc_lint::new_lint_store ` ] .
9491
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-
10792#### Driver lints
10893
10994These 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.
127112
128113[ `LintStore` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LintStore.html
129114[ `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
131115[ `rustc_lint::register_builtins` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.register_builtins.html
132116[ `rustc_lint::register_internals` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.register_internals.html
133117[ `rustc_lint::new_lint_store` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/fn.new_lint_store.html
134118[ `declare_lint!` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_lint.html
135119[ `declare_tool_lint!` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/macro.declare_tool_lint.html
136120[ `register_lints` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html#structfield.register_lints
137121[ `&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