Skip to content

Commit f8e4d5c

Browse files
ehusstshepang
authored andcommitted
Define more lint terms
1 parent 17fe3e9 commit f8e4d5c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/diagnostics.md

+77
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,83 @@ module.
507507

508508
[rlint]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/index.html
509509

510+
### When do lints run?
511+
512+
Different lints will run at different times based on what information the lint
513+
needs to do its job. Some lints get grouped into *passes* where the lints
514+
within a pass are processed together via a single visitor. Some of the passes
515+
are:
516+
517+
- Pre-expansion pass: Works on [AST nodes] before [macro expansion]. This
518+
should generally be avoided.
519+
- Example: [`keyword_idents`] checks for identifiers that will become
520+
keywords in future editions, but is sensitive to identifiers used in
521+
macros.
522+
523+
- Early lint pass: Works on [AST nodes] after [macro expansion] and name
524+
resolution, just before [HIR lowering]. These lints are for purely
525+
syntactical lints.
526+
- Example: The [`unsued_parens`] lint checks for parenthesized-expressions
527+
in situations where they are not needed, like an `if` condition.
528+
529+
- Late lint pass: Works on [HIR nodes], towards the end of [analysis] (after
530+
borrow checking, etc.). These lints have full type information available.
531+
Most lints are late.
532+
- Example: The [`invalid_value`] lint (which checks for obviously invalid
533+
uninitialized values) is a late lint because it needs type information to
534+
figure out whether a type allows being left uninitialized.
535+
536+
- MIR pass: Works on [MIR nodes]. This isn't quite the same as other passes;
537+
lints that work on MIR nodes have their own methods for running.
538+
- Example: The [`arithmetic_overflow`] lint is emitted when it detects a
539+
constant value that may overflow.
540+
541+
Most lints work well via the pass systems, and they have a fairly
542+
straightforward interface and easy way to integrate (mostly just implementing
543+
a specific `check` function). However, some lints are easier to write when
544+
they live on a specific code path anywhere in the compiler. For example, the
545+
[`unused_mut`] lint is implemented in the borrow checker as it requires some
546+
information and state in the borrow checker.
547+
548+
Some of these inline lints fire before the linting system is ready. Those
549+
lints will be *buffered* where they are held until later phases of the
550+
compiler when the linting system is ready. See [Linting early in the
551+
compiler](#linting-early-in-the-compiler).
552+
553+
554+
[AST nodes]: the-parser.md
555+
[HIR lowering]: lowering.md
556+
[HIR nodes]: hir.md
557+
[MIR nodes]: mir/index.md
558+
[macro expansion]: macro-expansion.md
559+
[analysis]: part-4-intro.md
560+
[`keyword_idents`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#keyword-idents
561+
[`unsued_parens`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unused-parens
562+
[`invalid_value`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#invalid-value
563+
[`arithmetic_overflow`]: https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#arithmetic-overflow
564+
[`unused_mut`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unused-mut
565+
566+
### Lint definition terms
567+
568+
Lints are managed via the [`LintStore`][LintStore] and get registered in
569+
various ways. The following terms refer to the different classes of lints
570+
generally based on how they are registered.
571+
572+
- *Built-in* lints are defined inside the compiler source.
573+
- *Driver-registered* lints are registered when the compiler driver is created
574+
by an external driver. This is the mechanism used by Clippy, for example.
575+
- *Plugin* lints are registered by the [deprecated plugin system].
576+
- *Tool* lints are lints with a path prefix like `clippy::` or `rustdoc::`.
577+
- *Internal* lints are the `rustc::` scoped tool lints that only run on the
578+
rustc source tree itself and are defined in the compiler source like a
579+
regular built-in lint.
580+
581+
More information about lint registration can be found in the [LintStore]
582+
chapter.
583+
584+
[deprecated plugin system]: https://doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html
585+
[LintStore]: lintstore.md
586+
510587
### Declaring a lint
511588

512589
The built-in compiler lints are defined in the [`rustc_lint`][builtin]

0 commit comments

Comments
 (0)