Rollup merge of #132221 - ehuss:lint-docs, r=compiler-errors
Clean up some comments on lint implementation This updates some doc comments that have gotten very out of date. Some of these macros were removed or renamed in #57726 and #104863 and others. Manual emitting of lints was significantly reworked when the `Diagnostic` infrastructure was added. Rather than try to replicate the high-level documentation, I added pointers to the rustc-dev-guide. I linkified some types so that if they are renamed/removed without updating the docs, it will break CI.
This commit is contained in:
commit
4649a1b141
@ -4,21 +4,14 @@
|
||||
//! AST visitor. Also see `rustc_session::lint::builtin`, which contains the
|
||||
//! definitions of lints that are emitted directly inside the main compiler.
|
||||
//!
|
||||
//! To add a new lint to rustc, declare it here using `declare_lint!()`.
|
||||
//! To add a new lint to rustc, declare it here using [`declare_lint!`].
|
||||
//! Then add code to emit the new lint in the appropriate circumstances.
|
||||
//! You can do that in an existing `LintPass` if it makes sense, or in a
|
||||
//! new `LintPass`, or using `Session::add_lint` elsewhere in the
|
||||
//! compiler. Only do the latter if the check can't be written cleanly as a
|
||||
//! `LintPass` (also, note that such lints will need to be defined in
|
||||
//! `rustc_session::lint::builtin`, not here).
|
||||
//!
|
||||
//! If you define a new `EarlyLintPass`, you will also need to add it to the
|
||||
//! `add_early_builtin!` or `add_early_builtin_with_new!` invocation in
|
||||
//! `lib.rs`. Use the former for unit-like structs and the latter for structs
|
||||
//! with a `pub fn new()`.
|
||||
//! If you define a new [`EarlyLintPass`], you will also need to add it to the
|
||||
//! [`crate::early_lint_methods!`] invocation in `lib.rs`.
|
||||
//!
|
||||
//! If you define a new `LateLintPass`, you will also need to add it to the
|
||||
//! `late_lint_methods!` invocation in `lib.rs`.
|
||||
//! If you define a new [`LateLintPass`], you will also need to add it to the
|
||||
//! [`crate::late_lint_methods!`] invocation in `lib.rs`.
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
|
@ -1,18 +1,7 @@
|
||||
//! Implementation of lint checking.
|
||||
//! Basic types for managing and implementing lints.
|
||||
//!
|
||||
//! The lint checking is mostly consolidated into one pass which runs
|
||||
//! after all other analyses. Throughout compilation, lint warnings
|
||||
//! can be added via the `add_lint` method on the Session structure. This
|
||||
//! requires a span and an ID of the node that the lint is being added to. The
|
||||
//! lint isn't actually emitted at that time because it is unknown what the
|
||||
//! actual lint level at that location is.
|
||||
//!
|
||||
//! To actually emit lint warnings/errors, a separate pass is used.
|
||||
//! A context keeps track of the current state of all lint levels.
|
||||
//! Upon entering a node of the ast which can modify the lint settings, the
|
||||
//! previous lint state is pushed onto a stack and the ast is then recursed
|
||||
//! upon. As the ast is traversed, this keeps track of the current lint level
|
||||
//! for all lint attributes.
|
||||
//! See <https://rustc-dev-guide.rust-lang.org/diagnostics.html> for an
|
||||
//! overview of how lints are implemented.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::{iter, slice};
|
||||
@ -52,9 +41,6 @@
|
||||
dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::DynSend + sync::DynSync;
|
||||
|
||||
/// Information about the registered lints.
|
||||
///
|
||||
/// This is basically the subset of `Context` that we can
|
||||
/// build early in the compile pipeline.
|
||||
pub struct LintStore {
|
||||
/// Registered lints.
|
||||
lints: Vec<&'static Lint>,
|
||||
|
@ -1,18 +1,8 @@
|
||||
//! Implementation of lint checking.
|
||||
//! Implementation of the early lint pass.
|
||||
//!
|
||||
//! The lint checking is mostly consolidated into one pass which runs
|
||||
//! after all other analyses. Throughout compilation, lint warnings
|
||||
//! can be added via the `add_lint` method on the Session structure. This
|
||||
//! requires a span and an ID of the node that the lint is being added to. The
|
||||
//! lint isn't actually emitted at that time because it is unknown what the
|
||||
//! actual lint level at that location is.
|
||||
//!
|
||||
//! To actually emit lint warnings/errors, a separate pass is used.
|
||||
//! A context keeps track of the current state of all lint levels.
|
||||
//! Upon entering a node of the ast which can modify the lint settings, the
|
||||
//! previous lint state is pushed onto a stack and the ast is then recursed
|
||||
//! upon. As the ast is traversed, this keeps track of the current lint level
|
||||
//! for all lint attributes.
|
||||
//! The early lint pass works on AST nodes after macro expansion and name
|
||||
//! resolution, just before AST lowering. These lints are for purely
|
||||
//! syntactical lints.
|
||||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{self as ast_visit, Visitor, walk_list};
|
||||
|
@ -1,18 +1,7 @@
|
||||
//! Implementation of lint checking.
|
||||
//! Implementation of the late lint pass.
|
||||
//!
|
||||
//! The lint checking is mostly consolidated into one pass which runs
|
||||
//! after all other analyses. Throughout compilation, lint warnings
|
||||
//! can be added via the `add_lint` method on the Session structure. This
|
||||
//! requires a span and an ID of the node that the lint is being added to. The
|
||||
//! lint isn't actually emitted at that time because it is unknown what the
|
||||
//! actual lint level at that location is.
|
||||
//!
|
||||
//! To actually emit lint warnings/errors, a separate pass is used.
|
||||
//! A context keeps track of the current state of all lint levels.
|
||||
//! Upon entering a node of the ast which can modify the lint settings, the
|
||||
//! previous lint state is pushed onto a stack and the ast is then recursed
|
||||
//! upon. As the ast is traversed, this keeps track of the current lint level
|
||||
//! for all lint attributes.
|
||||
//! The late lint pass Works on HIR nodes, towards the end of analysis (after
|
||||
//! borrow checking, etc.). These lints have full type information available.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
|
@ -6,20 +6,14 @@
|
||||
//! other phases of the compiler, which are generally required to hold in order
|
||||
//! to compile the program at all.
|
||||
//!
|
||||
//! Most lints can be written as [LintPass] instances. These run after
|
||||
//! Most lints can be written as [`LintPass`] instances. These run after
|
||||
//! all other analyses. The `LintPass`es built into rustc are defined
|
||||
//! within [rustc_session::lint::builtin],
|
||||
//! which has further comments on how to add such a lint.
|
||||
//! rustc can also load external lint plugins, as is done for Clippy.
|
||||
//!
|
||||
//! Some of rustc's lints are defined elsewhere in the compiler and work by
|
||||
//! calling `add_lint()` on the overall `Session` object. This works when
|
||||
//! it happens before the main lint pass, which emits the lints stored by
|
||||
//! `add_lint()`. To emit lints after the main lint pass (from codegen, for
|
||||
//! example) requires more effort. See `emit_lint` and `GatherNodeLevels`
|
||||
//! in `context.rs`.
|
||||
//!
|
||||
//! Some code also exists in [rustc_session::lint], [rustc_middle::lint].
|
||||
//! See <https://rustc-dev-guide.rust-lang.org/diagnostics.html> for an
|
||||
//! overview of how lints are implemented.
|
||||
//!
|
||||
//! ## Note
|
||||
//!
|
||||
|
Loading…
Reference in New Issue
Block a user