rustc_middle/
error.rs
1use std::path::{Path, PathBuf};
2use std::{fmt, io};
3
4use rustc_errors::codes::*;
5use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage};
6use rustc_macros::{Diagnostic, Subdiagnostic};
7use rustc_span::{Span, Symbol};
8
9use crate::ty::Ty;
10
11#[derive(Diagnostic)]
12#[diag(middle_drop_check_overflow, code = E0320)]
13#[note]
14pub(crate) struct DropCheckOverflow<'tcx> {
15 #[primary_span]
16 pub span: Span,
17 pub ty: Ty<'tcx>,
18 pub overflow_ty: Ty<'tcx>,
19}
20
21#[derive(Diagnostic)]
22#[diag(middle_failed_writing_file)]
23pub(crate) struct FailedWritingFile<'a> {
24 pub path: &'a Path,
25 pub error: io::Error,
26}
27
28#[derive(Diagnostic)]
29#[diag(middle_opaque_hidden_type_mismatch)]
30pub(crate) struct OpaqueHiddenTypeMismatch<'tcx> {
31 pub self_ty: Ty<'tcx>,
32 pub other_ty: Ty<'tcx>,
33 #[primary_span]
34 #[label]
35 pub other_span: Span,
36 #[subdiagnostic]
37 pub sub: TypeMismatchReason,
38}
39
40#[derive(Diagnostic)]
42#[diag(middle_unsupported_union)]
43pub struct UnsupportedUnion {
44 pub ty_name: String,
45}
46
47#[derive(Diagnostic)]
49#[diag(middle_autodiff_unsafe_inner_const_ref)]
50pub struct AutodiffUnsafeInnerConstRef<'tcx> {
51 #[primary_span]
52 pub span: Span,
53 pub ty: Ty<'tcx>,
54}
55
56#[derive(Subdiagnostic)]
57pub enum TypeMismatchReason {
58 #[label(middle_conflict_types)]
59 ConflictType {
60 #[primary_span]
61 span: Span,
62 },
63 #[note(middle_previous_use_here)]
64 PreviousUse {
65 #[primary_span]
66 span: Span,
67 },
68}
69
70#[derive(Diagnostic)]
71#[diag(middle_recursion_limit_reached)]
72#[help]
73pub(crate) struct RecursionLimitReached<'tcx> {
74 pub ty: Ty<'tcx>,
75 pub suggested_limit: rustc_session::Limit,
76}
77
78#[derive(Diagnostic)]
79#[diag(middle_const_eval_non_int)]
80pub(crate) struct ConstEvalNonIntError {
81 #[primary_span]
82 pub span: Span,
83}
84
85#[derive(Diagnostic)]
86#[diag(middle_strict_coherence_needs_negative_coherence)]
87pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
88 #[primary_span]
89 pub span: Span,
90 #[label]
91 pub attr_span: Option<Span>,
92}
93
94#[derive(Diagnostic)]
95#[diag(middle_requires_lang_item)]
96pub(crate) struct RequiresLangItem {
97 #[primary_span]
98 pub span: Option<Span>,
99 pub name: Symbol,
100}
101
102#[derive(Diagnostic)]
103#[diag(middle_const_not_used_in_type_alias)]
104pub(super) struct ConstNotUsedTraitAlias {
105 pub ct: String,
106 #[primary_span]
107 pub span: Span,
108}
109
110pub struct CustomSubdiagnostic<'a> {
111 pub msg: fn() -> DiagMessage,
112 pub add_args: Box<dyn FnOnce(&mut dyn FnMut(DiagArgName, DiagArgValue)) + 'a>,
113}
114
115impl<'a> CustomSubdiagnostic<'a> {
116 pub fn label(x: fn() -> DiagMessage) -> Self {
117 Self::label_and_then(x, |_| {})
118 }
119 pub fn label_and_then<F: FnOnce(&mut dyn FnMut(DiagArgName, DiagArgValue)) + 'a>(
120 msg: fn() -> DiagMessage,
121 f: F,
122 ) -> Self {
123 Self { msg, add_args: Box::new(move |x| f(x)) }
124 }
125}
126
127impl fmt::Debug for CustomSubdiagnostic<'_> {
128 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129 f.debug_struct("CustomSubdiagnostic").finish_non_exhaustive()
130 }
131}
132
133#[derive(Diagnostic)]
134pub enum LayoutError<'tcx> {
135 #[diag(middle_layout_unknown)]
136 Unknown { ty: Ty<'tcx> },
137
138 #[diag(middle_layout_too_generic)]
139 TooGeneric { ty: Ty<'tcx> },
140
141 #[diag(middle_layout_size_overflow)]
142 Overflow { ty: Ty<'tcx> },
143
144 #[diag(middle_layout_normalization_failure)]
145 NormalizationFailure { ty: Ty<'tcx>, failure_ty: String },
146
147 #[diag(middle_layout_cycle)]
148 Cycle,
149
150 #[diag(middle_layout_references_error)]
151 ReferencesError,
152}
153
154#[derive(Diagnostic)]
155#[diag(middle_erroneous_constant)]
156pub(crate) struct ErroneousConstant {
157 #[primary_span]
158 pub span: Span,
159}
160
161#[derive(Diagnostic)]
162#[diag(middle_type_length_limit)]
163#[help(middle_consider_type_length_limit)]
164pub(crate) struct TypeLengthLimit {
165 #[primary_span]
166 pub span: Span,
167 pub shrunk: String,
168 #[note(middle_written_to_path)]
169 pub was_written: bool,
170 pub path: PathBuf,
171 pub type_length: usize,
172}