]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/errors.rs
Rollup merge of #87646 - JohnTitor:fix-parser-ice, r=oli-obk
[rust.git] / compiler / rustc_typeck / src / errors.rs
1 //! Errors emitted by typeck.
2 use rustc_macros::SessionDiagnostic;
3 use rustc_span::{symbol::Ident, Span, Symbol};
4
5 #[derive(SessionDiagnostic)]
6 #[error = "E0062"]
7 pub struct FieldMultiplySpecifiedInInitializer {
8     #[message = "field `{ident}` specified more than once"]
9     #[label = "used more than once"]
10     pub span: Span,
11     #[label = "first use of `{ident}`"]
12     pub prev_span: Span,
13     pub ident: Ident,
14 }
15
16 #[derive(SessionDiagnostic)]
17 #[error = "E0092"]
18 pub struct UnrecognizedAtomicOperation<'a> {
19     #[message = "unrecognized atomic operation function: `{op}`"]
20     #[label = "unrecognized atomic operation"]
21     pub span: Span,
22     pub op: &'a str,
23 }
24
25 #[derive(SessionDiagnostic)]
26 #[error = "E0094"]
27 pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
28     #[message = "intrinsic has wrong number of {descr} \
29                          parameters: found {found}, expected {expected}"]
30     #[label = "expected {expected} {descr} parameter{expected_pluralize}"]
31     pub span: Span,
32     pub found: usize,
33     pub expected: usize,
34     pub expected_pluralize: &'a str,
35     pub descr: &'a str,
36 }
37
38 #[derive(SessionDiagnostic)]
39 #[error = "E0093"]
40 pub struct UnrecognizedIntrinsicFunction {
41     #[message = "unrecognized intrinsic function: `{name}`"]
42     #[label = "unrecognized intrinsic"]
43     pub span: Span,
44     pub name: Symbol,
45 }
46
47 #[derive(SessionDiagnostic)]
48 #[error = "E0195"]
49 pub struct LifetimesOrBoundsMismatchOnTrait {
50     #[message = "lifetime parameters or bounds on {item_kind} `{ident}` do not match the trait declaration"]
51     #[label = "lifetimes do not match {item_kind} in trait"]
52     pub span: Span,
53     #[label = "lifetimes in impl do not match this {item_kind} in trait"]
54     pub generics_span: Option<Span>,
55     pub item_kind: &'static str,
56     pub ident: Ident,
57 }
58
59 #[derive(SessionDiagnostic)]
60 #[error = "E0120"]
61 pub struct DropImplOnWrongItem {
62     #[message = "the `Drop` trait may only be implemented for structs, enums, and unions"]
63     #[label = "must be a struct, enum, or union"]
64     pub span: Span,
65 }
66
67 #[derive(SessionDiagnostic)]
68 #[error = "E0124"]
69 pub struct FieldAlreadyDeclared {
70     pub field_name: Ident,
71     #[message = "field `{field_name}` is already declared"]
72     #[label = "field already declared"]
73     pub span: Span,
74     #[label = "`{field_name}` first declared here"]
75     pub prev_span: Span,
76 }
77
78 #[derive(SessionDiagnostic)]
79 #[error = "E0184"]
80 pub struct CopyImplOnTypeWithDtor {
81     #[message = "the trait `Copy` may not be implemented for this type; the \
82                               type has a destructor"]
83     #[label = "Copy not allowed on types with destructors"]
84     pub span: Span,
85 }
86
87 #[derive(SessionDiagnostic)]
88 #[error = "E0203"]
89 pub struct MultipleRelaxedDefaultBounds {
90     #[message = "type parameter has more than one relaxed default bound, only one is supported"]
91     pub span: Span,
92 }
93
94 #[derive(SessionDiagnostic)]
95 #[error = "E0206"]
96 pub struct CopyImplOnNonAdt {
97     #[message = "the trait `Copy` may not be implemented for this type"]
98     #[label = "type is not a structure or enumeration"]
99     pub span: Span,
100 }
101
102 #[derive(SessionDiagnostic)]
103 #[error = "E0224"]
104 pub struct TraitObjectDeclaredWithNoTraits {
105     #[message = "at least one trait is required for an object type"]
106     pub span: Span,
107 }
108
109 #[derive(SessionDiagnostic)]
110 #[error = "E0227"]
111 pub struct AmbiguousLifetimeBound {
112     #[message = "ambiguous lifetime bound, explicit lifetime bound required"]
113     pub span: Span,
114 }
115
116 #[derive(SessionDiagnostic)]
117 #[error = "E0229"]
118 pub struct AssocTypeBindingNotAllowed {
119     #[message = "associated type bindings are not allowed here"]
120     #[label = "associated type not allowed here"]
121     pub span: Span,
122 }
123
124 #[derive(SessionDiagnostic)]
125 #[error = "E0439"]
126 pub struct SimdShuffleMissingLength {
127     #[message = "invalid `simd_shuffle`, needs length: `{name}`"]
128     pub span: Span,
129     pub name: Symbol,
130 }
131
132 #[derive(SessionDiagnostic)]
133 #[error = "E0436"]
134 pub struct FunctionalRecordUpdateOnNonStruct {
135     #[message = "functional record update syntax requires a struct"]
136     pub span: Span,
137 }
138
139 #[derive(SessionDiagnostic)]
140 #[error = "E0516"]
141 pub struct TypeofReservedKeywordUsed {
142     #[message = "`typeof` is a reserved keyword but unimplemented"]
143     #[label = "reserved keyword"]
144     pub span: Span,
145 }
146
147 #[derive(SessionDiagnostic)]
148 #[error = "E0572"]
149 pub struct ReturnStmtOutsideOfFnBody {
150     #[message = "return statement outside of function body"]
151     pub span: Span,
152     #[label = "the return is part of this body..."]
153     pub encl_body_span: Option<Span>,
154     #[label = "...not the enclosing function body"]
155     pub encl_fn_span: Option<Span>,
156 }
157
158 #[derive(SessionDiagnostic)]
159 #[error = "E0627"]
160 pub struct YieldExprOutsideOfGenerator {
161     #[message = "yield expression outside of generator literal"]
162     pub span: Span,
163 }
164
165 #[derive(SessionDiagnostic)]
166 #[error = "E0639"]
167 pub struct StructExprNonExhaustive {
168     #[message = "cannot create non-exhaustive {what} using struct expression"]
169     pub span: Span,
170     pub what: &'static str,
171 }
172
173 #[derive(SessionDiagnostic)]
174 #[error = "E0699"]
175 pub struct MethodCallOnUnknownType {
176     #[message = "the type of this value must be known to call a method on a raw pointer on it"]
177     pub span: Span,
178 }
179
180 #[derive(SessionDiagnostic)]
181 #[error = "E0719"]
182 pub struct ValueOfAssociatedStructAlreadySpecified {
183     #[message = "the value of the associated type `{item_name}` (from trait `{def_path}`) is already specified"]
184     #[label = "re-bound here"]
185     pub span: Span,
186     #[label = "`{item_name}` bound here first"]
187     pub prev_span: Span,
188     pub item_name: Ident,
189     pub def_path: String,
190 }
191
192 #[derive(SessionDiagnostic)]
193 #[error = "E0745"]
194 pub struct AddressOfTemporaryTaken {
195     #[message = "cannot take address of a temporary"]
196     #[label = "temporary value"]
197     pub span: Span,
198 }