Skip to main content

rustc_query_impl/
error.rs

1use rustc_errors::codes::*;
2use rustc_hir::limit::Limit;
3use rustc_macros::{Diagnostic, Subdiagnostic};
4use rustc_span::{Span, Symbol};
5
6#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for QueryOverflow
            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 {
                    QueryOverflow {
                        span: __binding_0,
                        note: __binding_1,
                        suggested_limit: __binding_2,
                        crate_name: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("queries overflow the depth limit!")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)")));
                        ;
                        diag.arg("suggested_limit", __binding_2);
                        diag.arg("crate_name", __binding_3);
                        diag.span(__binding_0);
                        diag.subdiagnostic(__binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
7#[help(
8    "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
9)]
10#[diag("queries overflow the depth limit!")]
11pub(crate) struct QueryOverflow {
12    #[primary_span]
13    pub span: Span,
14    #[subdiagnostic]
15    pub note: QueryOverflowNote,
16    pub suggested_limit: Limit,
17    pub crate_name: Symbol,
18}
19
20#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for QueryOverflowNote {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    QueryOverflowNote { desc: __binding_0, depth: __binding_1 }
                        => {
                        diag.store_args();
                        diag.arg("desc", __binding_0);
                        diag.arg("depth", __binding_1);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("query depth increased by {$depth} when {$desc}")));
                        diag.note(__message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
21#[note("query depth increased by {$depth} when {$desc}")]
22pub(crate) struct QueryOverflowNote {
23    pub desc: String,
24    pub depth: usize,
25}
26
27#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for CycleStack {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    CycleStack { span: __binding_0, desc: __binding_1 } => {
                        diag.store_args();
                        diag.arg("desc", __binding_1);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which requires {$desc}...")));
                        diag.span_note(__binding_0, __message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
28#[note("...which requires {$desc}...")]
29pub(crate) struct CycleStack {
30    #[primary_span]
31    pub span: Span,
32    pub desc: String,
33}
34
35#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for StackCount {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    StackCount::Single { stack_bottom: __binding_0 } => {
                        diag.store_args();
                        diag.arg("stack_bottom", __binding_0);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which immediately requires {$stack_bottom} again")));
                        diag.note(__message);
                        diag.restore_args();
                    }
                    StackCount::Multiple { stack_bottom: __binding_0 } => {
                        diag.store_args();
                        diag.arg("stack_bottom", __binding_0);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which again requires {$stack_bottom}, completing the cycle")));
                        diag.note(__message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
36pub(crate) enum StackCount {
37    #[note("...which immediately requires {$stack_bottom} again")]
38    Single { stack_bottom: String },
39    #[note("...which again requires {$stack_bottom}, completing the cycle")]
40    Multiple { stack_bottom: String },
41}
42
43#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for Alias {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    Alias::Ty => {
                        diag.store_args();
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type aliases cannot be recursive")));
                        diag.note(__message);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a struct, enum, or union instead to break the cycle")));
                        diag.help(__message);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information")));
                        diag.help(__message);
                        diag.restore_args();
                    }
                    Alias::Trait => {
                        diag.store_args();
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("trait aliases cannot be recursive")));
                        diag.note(__message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
44pub(crate) enum Alias {
45    #[note("type aliases cannot be recursive")]
46    #[help("consider using a struct, enum, or union instead to break the cycle")]
47    #[help(
48        "see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information"
49    )]
50    Ty,
51    #[note("trait aliases cannot be recursive")]
52    Trait,
53}
54
55#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for CycleUsage {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    CycleUsage { span: __binding_0, usage: __binding_1 } => {
                        diag.store_args();
                        diag.arg("usage", __binding_1);
                        let __message =
                            diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cycle used when {$usage}")));
                        diag.span_note(__binding_0, __message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
56#[note("cycle used when {$usage}")]
57pub(crate) struct CycleUsage {
58    #[primary_span]
59    pub span: Span,
60    pub usage: String,
61}
62
63#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for Cycle 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 {
                    Cycle {
                        span: __binding_0,
                        stack_bottom: __binding_1,
                        cycle_stack: __binding_2,
                        stack_count: __binding_3,
                        alias: __binding_4,
                        cycle_usage: __binding_5,
                        note_span: __binding_6 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cycle detected when {$stack_bottom}")));
                        diag.code(E0391);
                        ;
                        diag.arg("stack_bottom", __binding_1);
                        diag.span(__binding_0);
                        for __binding_2 in __binding_2 {
                            diag.subdiagnostic(__binding_2);
                        }
                        diag.subdiagnostic(__binding_3);
                        if let Some(__binding_4) = __binding_4 {
                            diag.subdiagnostic(__binding_4);
                        }
                        if let Some(__binding_5) = __binding_5 {
                            diag.subdiagnostic(__binding_5);
                        }
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
64#[diag("cycle detected when {$stack_bottom}", code = E0391)]
65pub(crate) struct Cycle {
66    #[primary_span]
67    pub span: Span,
68    pub stack_bottom: String,
69    #[subdiagnostic]
70    pub cycle_stack: Vec<CycleStack>,
71    #[subdiagnostic]
72    pub stack_count: StackCount,
73    #[subdiagnostic]
74    pub alias: Option<Alias>,
75    #[subdiagnostic]
76    pub cycle_usage: Option<CycleUsage>,
77    #[note(
78        "see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
79    )]
80    pub note_span: (),
81}