• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::borrow::Cow;
2 use std::fmt;
3 
4 use rustc_errors::{DiagnosticArgValue, DiagnosticMessage};
5 use rustc_macros::Diagnostic;
6 use rustc_span::{Span, Symbol};
7 
8 use crate::ty::Ty;
9 
10 #[derive(Diagnostic)]
11 #[diag(middle_drop_check_overflow, code = "E0320")]
12 #[note]
13 pub 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(Diagnostic)]
21 #[diag(middle_opaque_hidden_type_mismatch)]
22 pub struct OpaqueHiddenTypeMismatch<'tcx> {
23     pub self_ty: Ty<'tcx>,
24     pub other_ty: Ty<'tcx>,
25     #[primary_span]
26     #[label]
27     pub other_span: Span,
28     #[subdiagnostic]
29     pub sub: TypeMismatchReason,
30 }
31 
32 #[derive(Subdiagnostic)]
33 pub enum TypeMismatchReason {
34     #[label(middle_conflict_types)]
35     ConflictType {
36         #[primary_span]
37         span: Span,
38     },
39     #[note(middle_previous_use_here)]
40     PreviousUse {
41         #[primary_span]
42         span: Span,
43     },
44 }
45 
46 #[derive(Diagnostic)]
47 #[diag(middle_limit_invalid)]
48 pub struct LimitInvalid<'a> {
49     #[primary_span]
50     pub span: Span,
51     #[label]
52     pub value_span: Span,
53     pub error_str: &'a str,
54 }
55 
56 #[derive(Diagnostic)]
57 #[diag(middle_recursion_limit_reached)]
58 #[help]
59 pub struct RecursionLimitReached<'tcx> {
60     pub ty: Ty<'tcx>,
61     pub suggested_limit: rustc_session::Limit,
62 }
63 
64 #[derive(Diagnostic)]
65 #[diag(middle_const_eval_non_int)]
66 pub struct ConstEvalNonIntError {
67     #[primary_span]
68     pub span: Span,
69 }
70 
71 #[derive(Diagnostic)]
72 #[diag(middle_strict_coherence_needs_negative_coherence)]
73 pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
74     #[primary_span]
75     pub span: Span,
76     #[label]
77     pub attr_span: Option<Span>,
78 }
79 
80 #[derive(Diagnostic)]
81 #[diag(middle_requires_lang_item)]
82 pub(crate) struct RequiresLangItem {
83     #[primary_span]
84     pub span: Option<Span>,
85     pub name: Symbol,
86 }
87 
88 #[derive(Diagnostic)]
89 #[diag(middle_const_not_used_in_type_alias)]
90 pub(super) struct ConstNotUsedTraitAlias {
91     pub ct: String,
92     #[primary_span]
93     pub span: Span,
94 }
95 
96 pub struct CustomSubdiagnostic<'a> {
97     pub msg: fn() -> DiagnosticMessage,
98     pub add_args:
99         Box<dyn FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>)) + 'a>,
100 }
101 
102 impl<'a> CustomSubdiagnostic<'a> {
label(x: fn() -> DiagnosticMessage) -> Self103     pub fn label(x: fn() -> DiagnosticMessage) -> Self {
104         Self::label_and_then(x, |_| {})
105     }
label_and_then< F: FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>)) + 'a, >( msg: fn() -> DiagnosticMessage, f: F, ) -> Self106     pub fn label_and_then<
107         F: FnOnce(&mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue<'static>)) + 'a,
108     >(
109         msg: fn() -> DiagnosticMessage,
110         f: F,
111     ) -> Self {
112         Self { msg, add_args: Box::new(move |x| f(x)) }
113     }
114 }
115 
116 impl fmt::Debug for CustomSubdiagnostic<'_> {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result117     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118         f.debug_struct("CustomSubdiagnostic").finish_non_exhaustive()
119     }
120 }
121 
122 #[derive(Diagnostic)]
123 pub enum LayoutError<'tcx> {
124     #[diag(middle_unknown_layout)]
125     Unknown { ty: Ty<'tcx> },
126 
127     #[diag(middle_values_too_big)]
128     Overflow { ty: Ty<'tcx> },
129 
130     #[diag(middle_cannot_be_normalized)]
131     NormalizationFailure { ty: Ty<'tcx>, failure_ty: String },
132 
133     #[diag(middle_cycle)]
134     Cycle,
135 }
136 
137 #[derive(Diagnostic)]
138 #[diag(middle_adjust_for_foreign_abi_error)]
139 pub struct UnsupportedFnAbi {
140     pub arch: Symbol,
141     pub abi: &'static str,
142 }
143 
144 /// Used by `rustc_const_eval`
145 pub use crate::fluent_generated::middle_adjust_for_foreign_abi_error;
146