Skip to main content

rustc_interface/
diagnostics.rs

1use std::io;
2use std::path::Path;
3
4use rustc_macros::Diagnostic;
5use rustc_span::{Span, Symbol};
6use rustc_structures::CrateType;
7use rustc_target::spec::TargetTuple;
8
9#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            CrateNameDoesNotMatch {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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> rustc_errors::Diagnostic<'_sess> for
            CrateNameInvalid<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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> rustc_errors::Diagnostic<'_sess> for FerrisIdentifier {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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.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(crate) 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> rustc_errors::Diagnostic<'_sess> for EmojiIdentifier {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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(crate) struct EmojiIdentifier {
43    #[primary_span]
44    pub spans: Vec<Span>,
45    pub ident: Symbol,
46}
47
48#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for MixedBinCrate {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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(crate) struct MixedBinCrate;
51
52#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for MixedProcMacroCrate
            {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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(crate) struct MixedProcMacroCrate;
55
56#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            UnstableWasmProcMacro {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    UnstableWasmProcMacro => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot compile `proc-macro` crate to wasm targets without -Zwasm-proc-macros")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
57#[diag("cannot compile `proc-macro` crate to wasm targets without -Zwasm-proc-macros")]
58pub(crate) struct UnstableWasmProcMacro;
59
60#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            ErrorWritingDependencies<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
61#[diag("error writing dependencies to `{$path}`: {$error}")]
62pub(crate) struct ErrorWritingDependencies<'a> {
63    pub path: &'a Path,
64    pub error: io::Error,
65}
66
67#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            InputFileWouldBeOverWritten<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
68#[diag("the input file \"{$path}\" would be overwritten by the generated executable")]
69pub(crate) struct InputFileWouldBeOverWritten<'a> {
70    pub path: &'a Path,
71}
72
73#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            GeneratedFileConflictsWithDirectory<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
74#[diag(
75    "the generated executable for the input file \"{$input_path}\" conflicts with the existing directory \"{$dir_path}\""
76)]
77pub(crate) struct GeneratedFileConflictsWithDirectory<'a> {
78    pub input_path: &'a Path,
79    pub dir_path: &'a Path,
80}
81
82#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for TempsDirError {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
83#[diag("failed to find or create the directory specified by `--temps-dir`")]
84pub(crate) struct TempsDirError;
85
86#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for OutDirError {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
87#[diag("failed to find or create the directory specified by `--out-dir`")]
88pub(crate) struct OutDirError;
89
90#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            FailedWritingFile<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
91#[diag("failed to write file {$path}: {$error}")]
92pub(crate) struct FailedWritingFile<'a> {
93    pub path: &'a Path,
94    pub error: io::Error,
95}
96
97#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            ProcMacroCratePanicAbort {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
98#[diag(
99    "building proc macro crate with `panic=abort` or `panic=immediate-abort` may crash the compiler should the proc-macro panic"
100)]
101pub(crate) struct ProcMacroCratePanicAbort;
102
103#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            CannotSanitizeProcMacro {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    CannotSanitizeProcMacro => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("building proc macro crate with sanitizers enabled is not supported")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
104#[diag("building proc macro crate with sanitizers enabled is not supported")]
105pub(crate) struct CannotSanitizeProcMacro;
106
107#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            MultipleOutputTypesAdaption {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
108#[diag(
109    "due to multiple output types requested, the explicitly specified output file name will be adapted for each output type"
110)]
111pub(crate) struct MultipleOutputTypesAdaption;
112
113#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            IgnoringExtraFilename {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
114#[diag("ignoring -C extra-filename flag due to -o flag")]
115pub(crate) struct IgnoringExtraFilename;
116
117#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for IgnoringOutDir {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
118#[diag("ignoring --out-dir flag due to -o flag")]
119pub(crate) struct IgnoringOutDir;
120
121#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            MultipleOutputTypesToStdout {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
122#[diag("can't use option `-o` or `--emit` to write multiple output types to stdout")]
123pub(crate) struct MultipleOutputTypesToStdout;
124
125#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            AbiRequiredTargetFeature<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                match self {
                    AbiRequiredTargetFeature {
                        feature: __binding_0, enabled: __binding_1, fcw: __binding_2
                        } => {
                        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.arg("feature", __binding_0);
                        diag.arg("enabled", __binding_1);
                        if __binding_2 {
                            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!")));
                        }
                        if __binding_2 {
                            diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
126#[diag(
127    "target feature `{$feature}` must be {$enabled} to ensure that the ABI of the current target can be implemented correctly"
128)]
129pub(crate) struct AbiRequiredTargetFeature<'a> {
130    pub feature: &'a str,
131    pub enabled: &'a str,
132    #[note(
133        "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
134    )]
135    #[note(
136        "for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>"
137    )]
138    pub fcw: bool,
139}
140
141#[derive(const _: () =
    {
        impl<'_sess> rustc_errors::Diagnostic<'_sess> for
            UnsupportedCrateTypeForCodegenBackend {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
142#[diag("dropping unsupported crate type `{$crate_type}` for codegen backend `{$codegen_backend}`")]
143pub(crate) struct UnsupportedCrateTypeForCodegenBackend {
144    pub(crate) crate_type: CrateType,
145    pub(crate) codegen_backend: &'static str,
146}
147
148#[derive(const _: () =
    {
        impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
            UnsupportedCrateTypeForTarget<'a> {
            #[track_caller]
            fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
                level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
                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)]
149#[diag("dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`")]
150pub(crate) struct UnsupportedCrateTypeForTarget<'a> {
151    pub(crate) crate_type: CrateType,
152    pub(crate) target_triple: &'a TargetTuple,
153}