]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/errors.rs
Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
[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 }
107
108 #[derive(SessionDiagnostic)]
109 #[error(code = "E0227", slug = "typeck-ambiguous-lifetime-bound")]
110 pub struct AmbiguousLifetimeBound {
111     #[primary_span]
112     pub span: Span,
113 }
114
115 #[derive(SessionDiagnostic)]
116 #[error(code = "E0229", slug = "typeck-assoc-type-binding-not-allowed")]
117 pub struct AssocTypeBindingNotAllowed {
118     #[primary_span]
119     #[label]
120     pub span: Span,
121 }
122
123 #[derive(SessionDiagnostic)]
124 #[error(code = "E0436", slug = "typeck-functional-record-update-on-non-struct")]
125 pub struct FunctionalRecordUpdateOnNonStruct {
126     #[primary_span]
127     pub span: Span,
128 }
129
130 #[derive(SessionDiagnostic)]
131 #[error(code = "E0516", slug = "typeck-typeof-reserved-keyword-used")]
132 pub struct TypeofReservedKeywordUsed<'tcx> {
133     pub ty: Ty<'tcx>,
134     #[primary_span]
135     #[label]
136     pub span: Span,
137     #[suggestion_verbose(code = "{ty}")]
138     pub opt_sugg: Option<(Span, Applicability)>,
139 }
140
141 #[derive(SessionDiagnostic)]
142 #[error(code = "E0572", slug = "typeck-return-stmt-outside-of-fn-body")]
143 pub struct ReturnStmtOutsideOfFnBody {
144     #[primary_span]
145     pub span: Span,
146     #[label = "encl-body-label"]
147     pub encl_body_span: Option<Span>,
148     #[label = "encl-fn-label"]
149     pub encl_fn_span: Option<Span>,
150 }
151
152 #[derive(SessionDiagnostic)]
153 #[error(code = "E0627", slug = "typeck-yield-expr-outside-of-generator")]
154 pub struct YieldExprOutsideOfGenerator {
155     #[primary_span]
156     pub span: Span,
157 }
158
159 #[derive(SessionDiagnostic)]
160 #[error(code = "E0639", slug = "typeck-struct-expr-non-exhaustive")]
161 pub struct StructExprNonExhaustive {
162     #[primary_span]
163     pub span: Span,
164     pub what: &'static str,
165 }
166
167 #[derive(SessionDiagnostic)]
168 #[error(code = "E0699", slug = "typeck-method-call-on-unknown-type")]
169 pub struct MethodCallOnUnknownType {
170     #[primary_span]
171     pub span: Span,
172 }
173
174 #[derive(SessionDiagnostic)]
175 #[error(code = "E0719", slug = "typeck-value-of-associated-struct-already-specified")]
176 pub struct ValueOfAssociatedStructAlreadySpecified {
177     #[primary_span]
178     #[label]
179     pub span: Span,
180     #[label = "previous-bound-label"]
181     pub prev_span: Span,
182     pub item_name: Ident,
183     pub def_path: String,
184 }
185
186 #[derive(SessionDiagnostic)]
187 #[error(code = "E0745", slug = "typeck-address-of-temporary-taken")]
188 pub struct AddressOfTemporaryTaken {
189     #[primary_span]
190     #[label]
191     pub span: Span,
192 }
193
194 #[derive(SessionSubdiagnostic)]
195 pub enum AddReturnTypeSuggestion<'tcx> {
196     #[suggestion(
197         slug = "typeck-add-return-type-add",
198         code = "-> {found} ",
199         applicability = "machine-applicable"
200     )]
201     Add {
202         #[primary_span]
203         span: Span,
204         found: Ty<'tcx>,
205     },
206     #[suggestion(
207         slug = "typeck-add-return-type-missing-here",
208         code = "-> _ ",
209         applicability = "has-placeholders"
210     )]
211     MissingHere {
212         #[primary_span]
213         span: Span,
214     },
215 }
216
217 #[derive(SessionSubdiagnostic)]
218 pub enum ExpectedReturnTypeLabel<'tcx> {
219     #[label(slug = "typeck-expected-default-return-type")]
220     Unit {
221         #[primary_span]
222         span: Span,
223     },
224     #[label(slug = "typeck-expected-return-type")]
225     Other {
226         #[primary_span]
227         span: Span,
228         expected: Ty<'tcx>,
229     },
230 }
231
232 #[derive(SessionDiagnostic)]
233 #[error(slug = "typeck-unconstrained-opaque-type")]
234 #[note]
235 pub struct UnconstrainedOpaqueType {
236     #[primary_span]
237     pub span: Span,
238     pub name: Symbol,
239 }
240
241 #[derive(SessionDiagnostic)]
242 #[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")]
243 #[note]
244 pub struct ExplicitGenericArgsWithImplTrait {
245     #[primary_span]
246     #[label]
247     pub spans: Vec<Span>,
248 }
249
250 #[derive(SessionSubdiagnostic)]
251 #[help(slug = "typeck-explicit-generic-args-with-impl-trait-feature")]
252 pub struct ExplicitGenericArgsWithImplTraitFeature;