Skip to main content

rustc_middle/
error.rs

1use std::io;
2use std::path::Path;
3
4use rustc_errors::codes::*;
5use rustc_macros::{Diagnostic, Subdiagnostic};
6use rustc_span::{Span, Symbol};
7
8use crate::ty::{Instance, Ty};
9
10#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            DropCheckOverflow<'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 {
                    DropCheckOverflow {
                        span: __binding_0, ty: __binding_1, overflow_ty: __binding_2
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow while adding drop-check rules for `{$ty}`")));
                        diag.code(E0320);
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflowed on `{$overflow_ty}`")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("overflow_ty", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
11#[diag("overflow while adding drop-check rules for `{$ty}`", code = E0320)]
12#[note("overflowed on `{$overflow_ty}`")]
13pub(crate) struct DropCheckOverflow<'tcx> {
14    #[primary_span]
15    pub span: Span,
16    pub ty: Ty<'tcx>,
17    pub overflow_ty: Ty<'tcx>,
18}
19
20#[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)]
21#[diag("failed to write file {$path}: {$error}\"")]
22pub(crate) struct FailedWritingFile<'a> {
23    pub path: &'a Path,
24    pub error: io::Error,
25}
26
27#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            OpaqueHiddenTypeMismatch<'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 {
                    OpaqueHiddenTypeMismatch {
                        self_ty: __binding_0,
                        other_ty: __binding_1,
                        other_span: __binding_2,
                        sub: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("concrete type differs from previous defining opaque type use")));
                        ;
                        diag.arg("self_ty", __binding_0);
                        diag.arg("other_ty", __binding_1);
                        diag.span(__binding_2);
                        diag.span_label(__binding_2,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$self_ty}`, got `{$other_ty}`")));
                        diag.subdiagnostic(__binding_3);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
28#[diag("concrete type differs from previous defining opaque type use")]
29pub(crate) struct OpaqueHiddenTypeMismatch<'tcx> {
30    pub self_ty: Ty<'tcx>,
31    pub other_ty: Ty<'tcx>,
32    #[primary_span]
33    #[label("expected `{$self_ty}`, got `{$other_ty}`")]
34    pub other_span: Span,
35    #[subdiagnostic]
36    pub sub: TypeMismatchReason,
37}
38
39#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for TypeMismatchReason {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    TypeMismatchReason::ConflictType { 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("this expression supplies two conflicting concrete types for the same opaque type")),
                                &sub_args);
                        diag.span_label(__binding_0, __message);
                    }
                    TypeMismatchReason::PreviousUse { 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("previous use here")),
                                &sub_args);
                        diag.span_note(__binding_0, __message);
                    }
                }
            }
        }
    };Subdiagnostic)]
40pub(crate) enum TypeMismatchReason {
41    #[label("this expression supplies two conflicting concrete types for the same opaque type")]
42    ConflictType {
43        #[primary_span]
44        span: Span,
45    },
46    #[note("previous use here")]
47    PreviousUse {
48        #[primary_span]
49        span: Span,
50    },
51}
52
53#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            RecursionLimitReached<'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 {
                    RecursionLimitReached {
                        span: __binding_0,
                        ty: __binding_1,
                        suggested_limit: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reached the recursion limit finding the struct tail for `{$ty}`")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`")));
                        ;
                        diag.arg("ty", __binding_1);
                        diag.arg("suggested_limit", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
54#[diag("reached the recursion limit finding the struct tail for `{$ty}`")]
55#[help(
56    "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`"
57)]
58pub(crate) struct RecursionLimitReached<'tcx> {
59    #[primary_span]
60    pub span: Span,
61    pub ty: Ty<'tcx>,
62    pub suggested_limit: rustc_hir::limit::Limit,
63}
64
65#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ConstEvalNonIntError 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 {
                    ConstEvalNonIntError { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation of enum discriminant resulted in non-integer")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
66#[diag("constant evaluation of enum discriminant resulted in non-integer")]
67pub(crate) struct ConstEvalNonIntError {
68    #[primary_span]
69    pub span: Span,
70}
71
72#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            StrictCoherenceNeedsNegativeCoherence 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 {
                    StrictCoherenceNeedsNegativeCoherence {
                        span: __binding_0, attr_span: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled")));
                        ;
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to this attribute")));
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
73#[diag(
74    "to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled"
75)]
76pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
77    #[primary_span]
78    pub span: Span,
79    #[label("due to this attribute")]
80    pub attr_span: Span,
81}
82
83#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            RequiresLangItem 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 {
                    RequiresLangItem { span: __binding_0, name: __binding_1 } =>
                        {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requires `{$name}` lang_item")));
                        ;
                        diag.arg("name", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
84#[diag("requires `{$name}` lang_item")]
85pub(crate) struct RequiresLangItem {
86    #[primary_span]
87    pub span: Span,
88    pub name: Symbol,
89}
90
91#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ConstNotUsedTraitAlias 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 {
                    ConstNotUsedTraitAlias { ct: __binding_0, span: __binding_1
                        } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias")));
                        ;
                        diag.arg("ct", __binding_0);
                        diag.span(__binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
92#[diag(
93    "const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias"
94)]
95pub(super) struct ConstNotUsedTraitAlias {
96    pub ct: String,
97    #[primary_span]
98    pub span: Span,
99}
100
101#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            ErroneousConstant 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 {
                    ErroneousConstant { span: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("erroneous constant encountered")));
                        ;
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
102#[diag("erroneous constant encountered")]
103pub(crate) struct ErroneousConstant {
104    #[primary_span]
105    pub span: Span,
106}
107
108#[derive(const _: () =
    {
        impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
            TypeLengthLimit<'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 {
                    TypeLengthLimit {
                        span: __binding_0,
                        instance: __binding_1,
                        type_length: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reached the type-length limit while instantiating `{$instance}`")));
                        diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")));
                        ;
                        diag.arg("instance", __binding_1);
                        diag.arg("type_length", __binding_2);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
109#[diag("reached the type-length limit while instantiating `{$instance}`")]
110#[help("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")]
111pub(crate) struct TypeLengthLimit<'tcx> {
112    #[primary_span]
113    pub span: Span,
114    pub instance: Instance<'tcx>,
115    pub type_length: usize,
116}
117
118#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MaxNumNodesInValtree 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 {
                    MaxNumNodesInValtree {
                        span: __binding_0, global_const_id: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maximum number of nodes exceeded in constant {$global_const_id}")));
                        ;
                        diag.arg("global_const_id", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
119#[diag("maximum number of nodes exceeded in constant {$global_const_id}")]
120pub(crate) struct MaxNumNodesInValtree {
121    #[primary_span]
122    pub span: Span,
123    pub global_const_id: String,
124}
125
126#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            InvalidConstInValtree 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 {
                    InvalidConstInValtree {
                        span: __binding_0, global_const_id: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant {$global_const_id} cannot be used as pattern")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constants that reference mutable or external memory cannot be used as patterns")));
                        ;
                        diag.arg("global_const_id", __binding_1);
                        diag.span(__binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
127#[diag("constant {$global_const_id} cannot be used as pattern")]
128#[note("constants that reference mutable or external memory cannot be used as patterns")]
129pub(crate) struct InvalidConstInValtree {
130    #[primary_span]
131    pub span: Span,
132    pub global_const_id: String,
133}
134
135#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for Reentrant
            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 {
                    Reentrant => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("internal compiler error: reentrant incremental verify failure, suppressing message")));
                        ;
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
136#[diag("internal compiler error: reentrant incremental verify failure, suppressing message")]
137pub(crate) struct Reentrant;
138
139#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            IncrementCompilation 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 {
                    IncrementCompilation {
                        run_cmd: __binding_0, dep_node: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("internal compiler error: encountered incremental compilation error with {$dep_node}")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("please follow the instructions below to create a bug report with the provided information")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for incremental compilation bugs, having a reproduction is vital")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again")));
                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("as a workaround, you can run {$run_cmd} to allow your project to compile")));
                        ;
                        diag.arg("run_cmd", __binding_0);
                        diag.arg("dep_node", __binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
140#[diag("internal compiler error: encountered incremental compilation error with {$dep_node}")]
141#[note("please follow the instructions below to create a bug report with the provided information")]
142#[note("for incremental compilation bugs, having a reproduction is vital")]
143#[note(
144    "an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again"
145)]
146#[note("as a workaround, you can run {$run_cmd} to allow your project to compile")]
147pub(crate) struct IncrementCompilation {
148    pub run_cmd: String,
149    pub dep_node: String,
150}