Skip to main content

rustc_monomorphize/
errors.rs

1use rustc_macros::{Diagnostic, LintDiagnostic};
2use rustc_middle::ty::{Instance, Ty};
3use rustc_span::{Span, Symbol};
4
5#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            RecursionLimit<'tcx> 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 {
                    RecursionLimit {
                        span: __binding_0,
                        instance: __binding_1,
                        def_span: __binding_2,
                        def_path_str: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reached the recursion limit while instantiating `{$instance}`")));
                        ;
                        diag.arg("instance", __binding_1);
                        diag.arg("def_path_str", __binding_3);
                        diag.span(__binding_0);
                        diag.span_note(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$def_path_str}` defined here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
6#[diag("reached the recursion limit while instantiating `{$instance}`")]
7pub(crate) struct RecursionLimit<'tcx> {
8    #[primary_span]
9    pub span: Span,
10    pub instance: Instance<'tcx>,
11    #[note("`{$def_path_str}` defined here")]
12    pub def_span: Span,
13    pub def_path_str: String,
14}
15
16#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for NoOptimizedMir
            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 {
                    NoOptimizedMir {
                        span: __binding_0,
                        crate_name: __binding_1,
                        instance: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("missing optimized MIR for `{$instance}` in the crate `{$crate_name}`")));
                        ;
                        diag.arg("crate_name", __binding_1);
                        diag.arg("instance", __binding_2);
                        diag.span_note(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
17#[diag("missing optimized MIR for `{$instance}` in the crate `{$crate_name}`")]
18pub(crate) struct NoOptimizedMir {
19    #[note(
20        "missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)"
21    )]
22    pub span: Span,
23    pub crate_name: Symbol,
24    pub instance: String,
25}
26
27#[derive(const _: () =
    {
        impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
            LargeAssignmentsLint {
            #[track_caller]
            fn decorate_lint<'__b>(self,
                diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
                match self {
                    LargeAssignmentsLint {
                        span: __binding_0, size: __binding_1, limit: __binding_2 }
                        => {
                        diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("moving {$size} bytes")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = \"...\"]`")));
                        ;
                        diag.arg("size", __binding_1);
                        diag.arg("limit", __binding_2);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value moved from here")));
                        diag
                    }
                };
            }
        }
    };LintDiagnostic)]
28#[diag("moving {$size} bytes")]
29#[note(
30    "the current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = \"...\"]`"
31)]
32pub(crate) struct LargeAssignmentsLint {
33    #[label("value moved from here")]
34    pub span: Span,
35    pub size: u64,
36    pub limit: u64,
37}
38
39#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            SymbolAlreadyDefined 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 {
                    SymbolAlreadyDefined {
                        span: __binding_0, symbol: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("symbol `{$symbol}` is already defined")));
                        ;
                        diag.arg("symbol", __binding_1);
                        if let Some(__binding_0) = __binding_0 {
                            diag.span(__binding_0);
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
40#[diag("symbol `{$symbol}` is already defined")]
41pub(crate) struct SymbolAlreadyDefined {
42    #[primary_span]
43    pub span: Option<Span>,
44    pub symbol: String,
45}
46
47#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            CouldntDumpMonoStats 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 {
                    CouldntDumpMonoStats { error: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unexpected error occurred while dumping monomorphization stats: {$error}")));
                        ;
                        diag.arg("error", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
48#[diag("unexpected error occurred while dumping monomorphization stats: {$error}")]
49pub(crate) struct CouldntDumpMonoStats {
50    pub error: String,
51}
52
53#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            EncounteredErrorWhileInstantiating<'tcx> 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 {
                    EncounteredErrorWhileInstantiating {
                        span: __binding_0, kind: __binding_1, instance: __binding_2
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the above error was encountered while instantiating `{$kind} {$instance}`")));
                        ;
                        diag.arg("kind", __binding_1);
                        diag.arg("instance", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
54#[diag("the above error was encountered while instantiating `{$kind} {$instance}`")]
55pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> {
56    #[primary_span]
57    pub span: Span,
58    pub kind: &'static str,
59    pub instance: Instance<'tcx>,
60}
61
62#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            EncounteredErrorWhileInstantiatingGlobalAsm 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 {
                    EncounteredErrorWhileInstantiatingGlobalAsm {
                        span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the above error was encountered while instantiating `global_asm`")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
63#[diag("the above error was encountered while instantiating `global_asm`")]
64pub(crate) struct EncounteredErrorWhileInstantiatingGlobalAsm {
65    #[primary_span]
66    pub span: Span,
67}
68
69#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for StartNotFound
            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 {
                    StartNotFound => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using `fn main` requires the standard library")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
70#[diag("using `fn main` requires the standard library")]
71#[help(
72    "use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`"
73)]
74pub(crate) struct StartNotFound;
75
76#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AbiErrorDisabledVectorType<'a> 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 {
                    AbiErrorDisabledVectorType {
                        span: __binding_0,
                        required_feature: __binding_1,
                        ty: __binding_2,
                        is_call: __binding_3,
                        is_scalable: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function {$is_call ->\n    [true] call\n    *[false] definition\n} uses {$is_scalable ->\n    [true] scalable\n    *[false] SIMD\n} vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->\n    [true] {\" \"}in the caller\n    *[false] {\"\"}\n}")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)")));
                        ;
                        diag.arg("required_feature", __binding_1);
                        diag.arg("ty", __binding_2);
                        diag.arg("is_call", __binding_3);
                        diag.arg("is_scalable", __binding_4);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function {$is_call ->\n        [true] called\n        *[false] defined\n    } here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
77#[diag("this function {$is_call ->
78    [true] call
79    *[false] definition
80} uses {$is_scalable ->
81    [true] scalable
82    *[false] SIMD
83} vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
84    [true] {\" \"}in the caller
85    *[false] {\"\"}
86}")]
87#[help(
88    "consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)"
89)]
90pub(crate) struct AbiErrorDisabledVectorType<'a> {
91    #[primary_span]
92    #[label(
93        "function {$is_call ->
94        [true] called
95        *[false] defined
96    } here"
97    )]
98    pub span: Span,
99    pub required_feature: &'a str,
100    pub ty: Ty<'a>,
101    /// Whether this is a problem at a call site or at a declaration.
102    pub is_call: bool,
103    /// Whether this is a problem with a fixed length vector or a scalable vector
104    pub is_scalable: bool,
105}
106
107#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AbiErrorUnsupportedUnsizedParameter<'a> 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 {
                    AbiErrorUnsupportedUnsizedParameter {
                        span: __binding_0, ty: __binding_1, is_call: __binding_2 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function {$is_call ->\n        [true] call\n        *[false] definition\n    } uses unsized type `{$ty}` which is not supported with the chosen ABI")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only rustic ABIs support unsized parameters")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("is_call", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function {$is_call ->\n            [true] called\n            *[false] defined\n        } here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
108#[diag(
109    "this function {$is_call ->
110        [true] call
111        *[false] definition
112    } uses unsized type `{$ty}` which is not supported with the chosen ABI"
113)]
114#[help("only rustic ABIs support unsized parameters")]
115pub(crate) struct AbiErrorUnsupportedUnsizedParameter<'a> {
116    #[primary_span]
117    #[label(
118        "function {$is_call ->
119            [true] called
120            *[false] defined
121        } here"
122    )]
123    pub span: Span,
124    pub ty: Ty<'a>,
125    /// Whether this is a problem at a call site or at a declaration.
126    pub is_call: bool,
127}
128
129#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AbiErrorUnsupportedVectorType<'a> 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 {
                    AbiErrorUnsupportedVectorType {
                        span: __binding_0, ty: __binding_1, is_call: __binding_2 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function {$is_call ->\n        [true] call\n        *[false] definition\n    } uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("is_call", __binding_2);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function {$is_call ->\n            [true] called\n            *[false] defined\n        } here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
130#[diag(
131    "this function {$is_call ->
132        [true] call
133        *[false] definition
134    } uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI"
135)]
136pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
137    #[primary_span]
138    #[label(
139        "function {$is_call ->
140            [true] called
141            *[false] defined
142        } here"
143    )]
144    pub span: Span,
145    pub ty: Ty<'a>,
146    /// Whether this is a problem at a call site or at a declaration.
147    pub is_call: bool,
148}
149
150#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            AbiRequiredTargetFeature<'a> 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 {
                    AbiRequiredTargetFeature {
                        span: __binding_0,
                        required_feature: __binding_1,
                        abi: __binding_2,
                        is_call: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function {$is_call ->\n    [true] call\n    *[false] definition\n} uses ABI \"{$abi}\" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->\n    [true] {\" \"}in the caller\n    *[false] {\"\"}\n}")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)")));
                        ;
                        diag.arg("required_feature", __binding_1);
                        diag.arg("abi", __binding_2);
                        diag.arg("is_call", __binding_3);
                        diag.span(__binding_0);
                        diag.span_label(__binding_0,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function {$is_call ->\n            [true] called\n            *[false] defined\n        } here")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
151#[diag("this function {$is_call ->
152    [true] call
153    *[false] definition
154} uses ABI \"{$abi}\" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
155    [true] {\" \"}in the caller
156    *[false] {\"\"}
157}")]
158#[help(
159    "consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)"
160)]
161pub(crate) struct AbiRequiredTargetFeature<'a> {
162    #[primary_span]
163    #[label(
164        "function {$is_call ->
165            [true] called
166            *[false] defined
167        } here"
168    )]
169    pub span: Span,
170    pub required_feature: &'a str,
171    pub abi: &'a str,
172    /// Whether this is a problem at a call site or at a declaration.
173    pub is_call: bool,
174}
175
176#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            StaticInitializerCyclic<'a> 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 {
                    StaticInitializerCyclic {
                        span: __binding_0,
                        labels: __binding_1,
                        head: __binding_2,
                        target: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("static initializer forms a cycle involving `{$head}`")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cyclic static initializers are not supported for target `{$target}`")));
                        ;
                        diag.arg("head", __binding_2);
                        diag.arg("target", __binding_3);
                        diag.span(__binding_0);
                        for __binding_1 in __binding_1 {
                            diag.span_label(__binding_1,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("part of this cycle")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
177#[diag("static initializer forms a cycle involving `{$head}`")]
178#[note("cyclic static initializers are not supported for target `{$target}`")]
179pub(crate) struct StaticInitializerCyclic<'a> {
180    #[primary_span]
181    pub span: Span,
182    #[label("part of this cycle")]
183    pub labels: Vec<Span>,
184    pub head: &'a str,
185    pub target: &'a str,
186}