Skip to main content

rustc_hir/
lints.rs

1use rustc_data_structures::sync::{DynSend, DynSync};
2use rustc_error_messages::MultiSpan;
3use rustc_errors::{Diag, DiagCtxtHandle, Level};
4use rustc_hir_id::HirId;
5use rustc_lint_defs::LintId;
6
7pub type DelayedLints = Box<[DelayedLint]>;
8
9/// During ast lowering, no lints can be emitted.
10/// That is because lints attach to nodes either in the AST, or on the built HIR.
11/// When attached to AST nodes, they're emitted just before building HIR,
12/// and then there's a gap where no lints can be emitted until HIR is done.
13/// The variants in this enum represent lints that are temporarily stashed during
14/// AST lowering to be emitted once HIR is built.
15pub struct DelayedLint {
16    pub lint_id: LintId,
17    pub id: HirId,
18    pub span: MultiSpan,
19    pub callback: Box<
20        dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level, &dyn std::any::Any) -> Diag<'a, ()>
21            + DynSend
22            + DynSync
23            + 'static,
24    >,
25}
26
27impl std::fmt::Debug for DelayedLint {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        f.debug_struct("DelayedLint")
30            .field("lint_id", &self.lint_id)
31            .field("id", &self.id)
32            .field("span", &self.span)
33            .finish()
34    }
35}