]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/errors.rs
Rollup merge of #96900 - GuillaumeGomez:fix-js-error, r=notriddle
[rust.git] / compiler / rustc_typeck / src / errors.rs
1 //! Errors emitted by typeck.
2 use rustc_errors::Applicability;
3 use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
4 use rustc_middle::ty::Ty;
5 use rustc_span::{symbol::Ident, Span, Symbol};
6
7 #[derive(SessionDiagnostic)]
8 #[error(code = "E0062", slug = "typeck-field-multiply-specified-in-initializer")]
9 pub struct FieldMultiplySpecifiedInInitializer {
10     #[primary_span]
11     #[label]
12     pub span: Span,
13     #[label = "previous-use-label"]
14     pub prev_span: Span,
15     pub ident: Ident,
16 }
17
18 #[derive(SessionDiagnostic)]
19 #[error(code = "E0092", slug = "typeck-unrecognized-atomic-operation")]
20 pub struct UnrecognizedAtomicOperation<'a> {
21     #[primary_span]
22     #[label]
23     pub span: Span,
24     pub op: &'a str,
25 }
26
27 #[derive(SessionDiagnostic)]
28 #[error(code = "E0094", slug = "typeck-wrong-number-of-generic-arguments-to-intrinsic")]
29 pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
30     #[primary_span]
31     #[label]
32     pub span: Span,
33     pub found: usize,
34     pub expected: usize,
35     pub descr: &'a str,
36 }
37
38 #[derive(SessionDiagnostic)]
39 #[error(code = "E0093", slug = "typeck-unrecognized-intrinsic-function")]
40 pub struct UnrecognizedIntrinsicFunction {
41     #[primary_span]
42     #[label]
43     pub span: Span,
44     pub name: Symbol,
45 }
46
47 #[derive(SessionDiagnostic)]
48 #[error(code = "E0195", slug = "typeck-lifetimes-or-bounds-mismatch-on-trait")]
49 pub struct LifetimesOrBoundsMismatchOnTrait {
50     #[primary_span]
51     #[label]
52     pub span: Span,
53     #[label = "generics-label"]
54     pub generics_span: Option<Span>,
55     pub item_kind: &'static str,
56     pub ident: Ident,
57 }
58
59 #[derive(SessionDiagnostic)]
60 #[error(code = "E0120", slug = "typeck-drop-impl-on-wrong-item")]
61 pub struct DropImplOnWrongItem {
62     #[primary_span]
63     #[label]
64     pub span: Span,
65 }
66
67 #[derive(SessionDiagnostic)]
68 #[error(code = "E0124", slug = "typeck-field-already-declared")]
69 pub struct FieldAlreadyDeclared {
70     pub field_name: Ident,
71     #[primary_span]
72     #[label]
73     pub span: Span,
74     #[label = "previous-decl-label"]
75     pub prev_span: Span,
76 }
77
78 #[derive(SessionDiagnostic)]
79 #[error(code = "E0184", slug = "typeck-copy-impl-on-type-with-dtor")]
80 pub struct CopyImplOnTypeWithDtor {
81     #[primary_span]
82     #[label]
83     pub span: Span,
84 }
85
86 #[derive(SessionDiagnostic)]
87 #[error(code = "E0203", slug = "typeck-multiple-relaxed-default-bounds")]
88 pub struct MultipleRelaxedDefaultBounds {
89     #[primary_span]
90     pub span: Span,
91 }
92
93 #[derive(SessionDiagnostic)]
94 #[error(code = "E0206", slug = "typeck-copy-impl-on-non-adt")]
95 pub struct CopyImplOnNonAdt {
96     #[primary_span]
97     #[label]
98     pub span: Span,
99 }
100
101 #[derive(SessionDiagnostic)]
102 #[error(code = "E0224", slug = "typeck-trait-object-declared-with-no-traits")]
103 pub struct TraitObjectDeclaredWithNoTraits {
104     #[primary_span]
105     pub span: Span,
106     #[label = "alias-span"]
107     pub trait_alias_span: Option<Span>,
108 }
109
110 #[derive(SessionDiagnostic)]
111 #[error(code = "E0227", slug = "typeck-ambiguous-lifetime-bound")]
112 pub struct AmbiguousLifetimeBound {
113     #[primary_span]
114     pub span: Span,
115 }
116
117 #[derive(SessionDiagnostic)]
118 #[error(code = "E0229", slug = "typeck-assoc-type-binding-not-allowed")]
119 pub struct AssocTypeBindingNotAllowed {
120     #[primary_span]
121     #[label]
122     pub span: Span,
123 }
124
125 #[derive(SessionDiagnostic)]
126 #[error(code = "E0436", slug = "typeck-functional-record-update-on-non-struct")]
127 pub struct FunctionalRecordUpdateOnNonStruct {
128     #[primary_span]
129     pub span: Span,
130 }
131
132 #[derive(SessionDiagnostic)]
133 #[error(code = "E0516", slug = "typeck-typeof-reserved-keyword-used")]
134 pub struct TypeofReservedKeywordUsed<'tcx> {
135     pub ty: Ty<'tcx>,
136     #[primary_span]
137     #[label]
138     pub span: Span,
139     #[suggestion_verbose(code = "{ty}")]
140     pub opt_sugg: Option<(Span, Applicability)>,
141 }
142
143 #[derive(SessionDiagnostic)]
144 #[error(code = "E0572", slug = "typeck-return-stmt-outside-of-fn-body")]
145 pub struct ReturnStmtOutsideOfFnBody {
146     #[primary_span]
147     pub span: Span,
148     #[label = "encl-body-label"]
149     pub encl_body_span: Option<Span>,
150     #[label = "encl-fn-label"]
151     pub encl_fn_span: Option<Span>,
152 }
153
154 #[derive(SessionDiagnostic)]
155 #[error(code = "E0627", slug = "typeck-yield-expr-outside-of-generator")]
156 pub struct YieldExprOutsideOfGenerator {
157     #[primary_span]
158     pub span: Span,
159 }
160
161 #[derive(SessionDiagnostic)]
162 #[error(code = "E0639", slug = "typeck-struct-expr-non-exhaustive")]
163 pub struct StructExprNonExhaustive {
164     #[primary_span]
165     pub span: Span,
166     pub what: &'static str,
167 }
168
169 #[derive(SessionDiagnostic)]
170 #[error(code = "E0699", slug = "typeck-method-call-on-unknown-type")]
171 pub struct MethodCallOnUnknownType {
172     #[primary_span]
173     pub span: Span,
174 }
175
176 #[derive(SessionDiagnostic)]
177 #[error(code = "E0719", slug = "typeck-value-of-associated-struct-already-specified")]
178 pub struct ValueOfAssociatedStructAlreadySpecified {
179     #[primary_span]
180     #[label]
181     pub span: Span,
182     #[label = "previous-bound-label"]
183     pub prev_span: Span,
184     pub item_name: Ident,
185     pub def_path: String,
186 }
187
188 #[derive(SessionDiagnostic)]
189 #[error(code = "E0745", slug = "typeck-address-of-temporary-taken")]
190 pub struct AddressOfTemporaryTaken {
191     #[primary_span]
192     #[label]
193     pub span: Span,
194 }
195
196 #[derive(SessionSubdiagnostic)]
197 pub enum AddReturnTypeSuggestion<'tcx> {
198     #[suggestion(
199         slug = "typeck-add-return-type-add",
200         code = "-> {found} ",
201         applicability = "machine-applicable"
202     )]
203     Add {
204         #[primary_span]
205         span: Span,
206         found: Ty<'tcx>,
207     },
208     #[suggestion(
209         slug = "typeck-add-return-type-missing-here",
210         code = "-> _ ",
211         applicability = "has-placeholders"
212     )]
213     MissingHere {
214         #[primary_span]
215         span: Span,
216     },
217 }
218
219 #[derive(SessionSubdiagnostic)]
220 pub enum ExpectedReturnTypeLabel<'tcx> {
221     #[label(slug = "typeck-expected-default-return-type")]
222     Unit {
223         #[primary_span]
224         span: Span,
225     },
226     #[label(slug = "typeck-expected-return-type")]
227     Other {
228         #[primary_span]
229         span: Span,
230         expected: Ty<'tcx>,
231     },
232 }
233
234 #[derive(SessionDiagnostic)]
235 #[error(slug = "typeck-unconstrained-opaque-type")]
236 #[note]
237 pub struct UnconstrainedOpaqueType {
238     #[primary_span]
239     pub span: Span,
240     pub name: Symbol,
241 }
242
243 #[derive(SessionDiagnostic)]
244 #[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")]
245 #[note]
246 pub struct ExplicitGenericArgsWithImplTrait {
247     #[primary_span]
248     #[label]
249     pub spans: Vec<Span>,
250 }
251
252 #[derive(SessionSubdiagnostic)]
253 #[help(slug = "typeck-explicit-generic-args-with-impl-trait-feature")]
254 pub struct ExplicitGenericArgsWithImplTraitFeature;