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