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