Skip to main content

rustc_interface/
errors.rs

1use std::io;
2use std::path::Path;
3
4use rustc_hir::attrs::CrateType;
5use rustc_macros::Diagnostic;
6use rustc_span::{Span, Symbol};
7use rustc_target::spec::TargetTuple;
8
9#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            CrateNameDoesNotMatch 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 {
                    CrateNameDoesNotMatch {
                        span: __binding_0,
                        crate_name: __binding_1,
                        attr_crate_name: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`")));
                        ;
                        diag.arg("crate_name", __binding_1);
                        diag.arg("attr_crate_name", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
10#[diag(
11    "`--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`"
12)]
13pub(crate) struct CrateNameDoesNotMatch {
14    #[primary_span]
15    pub(crate) span: Span,
16    pub(crate) crate_name: Symbol,
17    pub(crate) attr_crate_name: Symbol,
18}
19
20#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            CrateNameInvalid<'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 {
                    CrateNameInvalid { crate_name: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen")));
                        ;
                        diag.arg("crate_name", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
21#[diag("crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen")]
22pub(crate) struct CrateNameInvalid<'a> {
23    pub(crate) crate_name: &'a str,
24}
25
26#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            FerrisIdentifier 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 {
                    FerrisIdentifier {
                        spans: __binding_0,
                        first_span: __binding_1,
                        ferris_fix: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("Ferris cannot be used as an identifier")));
                        let __code_0 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_2))
                                            })].into_iter();
                        ;
                        diag.arg("ferris_fix", __binding_2);
                        diag.span(__binding_0.clone());
                        diag.span_suggestions_with_style(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using their name instead")),
                            __code_0, rustc_errors::Applicability::MaybeIncorrect,
                            rustc_errors::SuggestionStyle::ShowCode);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
27#[diag("Ferris cannot be used as an identifier")]
28pub struct FerrisIdentifier {
29    #[primary_span]
30    pub spans: Vec<Span>,
31    #[suggestion(
32        "try using their name instead",
33        code = "{ferris_fix}",
34        applicability = "maybe-incorrect"
35    )]
36    pub first_span: Span,
37    pub ferris_fix: &'static str,
38}
39
40#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            EmojiIdentifier 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 {
                    EmojiIdentifier { spans: __binding_0, ident: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("identifiers cannot contain emoji: `{$ident}`")));
                        ;
                        diag.arg("ident", __binding_1);
                        diag.span(__binding_0.clone());
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
41#[diag("identifiers cannot contain emoji: `{$ident}`")]
42pub struct EmojiIdentifier {
43    #[primary_span]
44    pub spans: Vec<Span>,
45    pub ident: Symbol,
46}
47
48#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for MixedBinCrate
            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 {
                    MixedBinCrate => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot mix `bin` crate type with others")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
49#[diag("cannot mix `bin` crate type with others")]
50pub struct MixedBinCrate;
51
52#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MixedProcMacroCrate 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 {
                    MixedProcMacroCrate => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot mix `proc-macro` crate type with others")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
53#[diag("cannot mix `proc-macro` crate type with others")]
54pub struct MixedProcMacroCrate;
55
56#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            ErrorWritingDependencies<'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 {
                    ErrorWritingDependencies {
                        path: __binding_0, error: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("error writing dependencies to `{$path}`: {$error}")));
                        ;
                        diag.arg("path", __binding_0);
                        diag.arg("error", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
57#[diag("error writing dependencies to `{$path}`: {$error}")]
58pub struct ErrorWritingDependencies<'a> {
59    pub path: &'a Path,
60    pub error: io::Error,
61}
62
63#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            InputFileWouldBeOverWritten<'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 {
                    InputFileWouldBeOverWritten { path: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the input file \"{$path}\" would be overwritten by the generated executable")));
                        ;
                        diag.arg("path", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
64#[diag("the input file \"{$path}\" would be overwritten by the generated executable")]
65pub struct InputFileWouldBeOverWritten<'a> {
66    pub path: &'a Path,
67}
68
69#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            GeneratedFileConflictsWithDirectory<'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 {
                    GeneratedFileConflictsWithDirectory {
                        input_path: __binding_0, dir_path: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the generated executable for the input file \"{$input_path}\" conflicts with the existing directory \"{$dir_path}\"")));
                        ;
                        diag.arg("input_path", __binding_0);
                        diag.arg("dir_path", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
70#[diag(
71    "the generated executable for the input file \"{$input_path}\" conflicts with the existing directory \"{$dir_path}\""
72)]
73pub struct GeneratedFileConflictsWithDirectory<'a> {
74    pub input_path: &'a Path,
75    pub dir_path: &'a Path,
76}
77
78#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TempsDirError
            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 {
                    TempsDirError => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to find or create the directory specified by `--temps-dir`")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
79#[diag("failed to find or create the directory specified by `--temps-dir`")]
80pub struct TempsDirError;
81
82#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for OutDirError
            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 {
                    OutDirError => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to find or create the directory specified by `--out-dir`")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
83#[diag("failed to find or create the directory specified by `--out-dir`")]
84pub struct OutDirError;
85
86#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            FailedWritingFile<'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 {
                    FailedWritingFile { path: __binding_0, error: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to write file {$path}: {$error}\"")));
                        ;
                        diag.arg("path", __binding_0);
                        diag.arg("error", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
87#[diag("failed to write file {$path}: {$error}\"")]
88pub struct FailedWritingFile<'a> {
89    pub path: &'a Path,
90    pub error: io::Error,
91}
92
93#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ProcMacroCratePanicAbort 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 {
                    ProcMacroCratePanicAbort => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("building proc macro crate with `panic=abort` or `panic=immediate-abort` may crash the compiler should the proc-macro panic")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
94#[diag(
95    "building proc macro crate with `panic=abort` or `panic=immediate-abort` may crash the compiler should the proc-macro panic"
96)]
97pub struct ProcMacroCratePanicAbort;
98
99#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MultipleOutputTypesAdaption 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 {
                    MultipleOutputTypesAdaption => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to multiple output types requested, the explicitly specified output file name will be adapted for each output type")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
100#[diag(
101    "due to multiple output types requested, the explicitly specified output file name will be adapted for each output type"
102)]
103pub struct MultipleOutputTypesAdaption;
104
105#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            IgnoringExtraFilename 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 {
                    IgnoringExtraFilename => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ignoring -C extra-filename flag due to -o flag")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
106#[diag("ignoring -C extra-filename flag due to -o flag")]
107pub struct IgnoringExtraFilename;
108
109#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for IgnoringOutDir
            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 {
                    IgnoringOutDir => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ignoring --out-dir flag due to -o flag")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
110#[diag("ignoring --out-dir flag due to -o flag")]
111pub struct IgnoringOutDir;
112
113#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MultipleOutputTypesToStdout 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 {
                    MultipleOutputTypesToStdout => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't use option `-o` or `--emit` to write multiple output types to stdout")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
114#[diag("can't use option `-o` or `--emit` to write multiple output types to stdout")]
115pub struct MultipleOutputTypesToStdout;
116
117#[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 {
                        feature: __binding_0, enabled: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("target feature `{$feature}` must be {$enabled} to ensure that the ABI of the current target can be implemented correctly")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>")));
                        ;
                        diag.arg("feature", __binding_0);
                        diag.arg("enabled", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
118#[diag(
119    "target feature `{$feature}` must be {$enabled} to ensure that the ABI of the current target can be implemented correctly"
120)]
121#[note(
122    "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
123)]
124#[note("for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>")]
125pub(crate) struct AbiRequiredTargetFeature<'a> {
126    pub feature: &'a str,
127    pub enabled: &'a str,
128}
129
130#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnsupportedCrateTypeForCodegenBackend 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 {
                    UnsupportedCrateTypeForCodegenBackend {
                        crate_type: __binding_0, codegen_backend: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dropping unsupported crate type `{$crate_type}` for codegen backend `{$codegen_backend}`")));
                        ;
                        diag.arg("crate_type", __binding_0);
                        diag.arg("codegen_backend", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
131#[diag("dropping unsupported crate type `{$crate_type}` for codegen backend `{$codegen_backend}`")]
132pub(crate) struct UnsupportedCrateTypeForCodegenBackend {
133    pub(crate) crate_type: CrateType,
134    pub(crate) codegen_backend: &'static str,
135}
136
137#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            UnsupportedCrateTypeForTarget<'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 {
                    UnsupportedCrateTypeForTarget {
                        crate_type: __binding_0, target_triple: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`")));
                        ;
                        diag.arg("crate_type", __binding_0);
                        diag.arg("target_triple", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
138#[diag("dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`")]
139pub(crate) struct UnsupportedCrateTypeForTarget<'a> {
140    pub(crate) crate_type: CrateType,
141    pub(crate) target_triple: &'a TargetTuple,
142}