Skip to main content

rustc_attr_parsing/
errors.rs

1use rustc_errors::MultiSpan;
2use rustc_macros::{Diagnostic, Subdiagnostic};
3use rustc_span::{Span, Symbol};
4
5#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            InvalidAttrAtCrateLevel where G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    InvalidAttrAtCrateLevel {
                        span: __binding_0,
                        pound_to_opening_bracket: __binding_1,
                        name: __binding_2,
                        item: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` attribute cannot be used at crate level")));
                        let __code_0 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("#["))
                                            })].into_iter();
                        ;
                        diag.arg("name", __binding_2);
                        diag.span(__binding_0);
                        diag.span_suggestions_with_style(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("perhaps you meant to use an outer attribute")),
                            __code_0, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::ShowAlways);
                        if let Some(__binding_3) = __binding_3 {
                            diag.subdiagnostic(__binding_3);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
6#[diag("`{$name}` attribute cannot be used at crate level")]
7pub(crate) struct InvalidAttrAtCrateLevel {
8    #[primary_span]
9    pub span: Span,
10    #[suggestion(
11        "perhaps you meant to use an outer attribute",
12        code = "#[",
13        applicability = "machine-applicable",
14        style = "verbose"
15    )]
16    pub pound_to_opening_bracket: Span,
17    pub name: Symbol,
18    #[subdiagnostic]
19    pub item: Option<ItemFollowingInnerAttr>,
20}
21
22#[derive(#[automatically_derived]
impl ::core::clone::Clone for ItemFollowingInnerAttr {
    #[inline]
    fn clone(&self) -> ItemFollowingInnerAttr {
        let _: ::core::clone::AssertParamIsClone<Span>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ItemFollowingInnerAttr { }Copy, const _: () =
    {
        impl rustc_errors::Subdiagnostic for ItemFollowingInnerAttr {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    ItemFollowingInnerAttr { span: __binding_0 } => {
                        let mut sub_args = rustc_errors::DiagArgMap::default();
                        let __message =
                            rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the inner attribute doesn't annotate this item")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
23#[label("the inner attribute doesn't annotate this item")]
24pub(crate) struct ItemFollowingInnerAttr {
25    #[primary_span]
26    pub span: Span,
27}
28
29#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnreachableCfgSelectPredicate where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    UnreachableCfgSelectPredicate { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unreachable configuration predicate")));
                        ;
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this configuration predicate is never reached")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
30#[diag("unreachable configuration predicate")]
31pub(crate) struct UnreachableCfgSelectPredicate {
32    #[label("this configuration predicate is never reached")]
33    pub span: Span,
34}
35
36#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnsupportedAttributesInWhere where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    UnsupportedAttributesInWhere { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("most attributes are not supported in `where` clauses")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only `#[cfg]` and `#[cfg_attr]` are supported")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
37#[diag("most attributes are not supported in `where` clauses")]
38#[help("only `#[cfg]` and `#[cfg_attr]` are supported")]
39pub(crate) struct UnsupportedAttributesInWhere {
40    #[primary_span]
41    pub span: MultiSpan,
42}
43
44#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnreachableCfgSelectPredicateWildcard where
            G: rustc_errors::EmissionGuarantee {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
                match self {
                    UnreachableCfgSelectPredicateWildcard {
                        span: __binding_0, wildcard_span: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unreachable configuration predicate")));
                        ;
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this configuration predicate is never reached")));
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("always matches")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
45#[diag("unreachable configuration predicate")]
46pub(crate) struct UnreachableCfgSelectPredicateWildcard {
47    #[label("this configuration predicate is never reached")]
48    pub span: Span,
49
50    #[label("always matches")]
51    pub wildcard_span: Span,
52}