1 //! Errors emitted by typeck.
2 use rustc_macros::SessionDiagnostic;
3 use rustc_span::{symbol::Ident, Span, Symbol};
5 #[derive(SessionDiagnostic)]
7 pub struct FieldMultiplySpecifiedInInitializer {
8 #[message = "field `{ident}` specified more than once"]
9 #[label = "used more than once"]
11 #[label = "first use of `{ident}`"]
16 #[derive(SessionDiagnostic)]
18 pub struct UnrecognizedAtomicOperation<'a> {
19 #[message = "unrecognized atomic operation function: `{op}`"]
20 #[label = "unrecognized atomic operation"]
25 #[derive(SessionDiagnostic)]
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}"]
34 pub expected_pluralize: &'a str,
38 #[derive(SessionDiagnostic)]
40 pub struct UnrecognizedIntrinsicFunction {
41 #[message = "unrecognized intrinsic function: `{name}`"]
42 #[label = "unrecognized intrinsic"]
47 #[derive(SessionDiagnostic)]
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"]
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,
59 #[derive(SessionDiagnostic)]
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"]
67 #[derive(SessionDiagnostic)]
69 pub struct FieldAlreadyDeclared {
70 pub field_name: Ident,
71 #[message = "field `{field_name}` is already declared"]
72 #[label = "field already declared"]
74 #[label = "`{field_name}` first declared here"]
78 #[derive(SessionDiagnostic)]
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"]
87 #[derive(SessionDiagnostic)]
89 pub struct MultipleRelaxedDefaultBounds {
90 #[message = "type parameter has more than one relaxed default bound, only one is supported"]
94 #[derive(SessionDiagnostic)]
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"]
102 #[derive(SessionDiagnostic)]
104 pub struct TraitObjectDeclaredWithNoTraits {
105 #[message = "at least one trait is required for an object type"]
109 #[derive(SessionDiagnostic)]
111 pub struct AmbiguousLifetimeBound {
112 #[message = "ambiguous lifetime bound, explicit lifetime bound required"]
116 #[derive(SessionDiagnostic)]
118 pub struct AssocTypeBindingNotAllowed {
119 #[message = "associated type bindings are not allowed here"]
120 #[label = "associated type not allowed here"]
124 #[derive(SessionDiagnostic)]
126 pub struct SimdShuffleMissingLength {
127 #[message = "invalid `simd_shuffle`, needs length: `{name}`"]
132 #[derive(SessionDiagnostic)]
134 pub struct FunctionalRecordUpdateOnNonStruct {
135 #[message = "functional record update syntax requires a struct"]
139 #[derive(SessionDiagnostic)]
141 pub struct TypeofReservedKeywordUsed {
142 #[message = "`typeof` is a reserved keyword but unimplemented"]
143 #[label = "reserved keyword"]
147 #[derive(SessionDiagnostic)]
149 pub struct ReturnStmtOutsideOfFnBody {
150 #[message = "return statement outside of function body"]
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>,
158 #[derive(SessionDiagnostic)]
160 pub struct YieldExprOutsideOfGenerator {
161 #[message = "yield expression outside of generator literal"]
165 #[derive(SessionDiagnostic)]
167 pub struct StructExprNonExhaustive {
168 #[message = "cannot create non-exhaustive {what} using struct expression"]
170 pub what: &'static str,
173 #[derive(SessionDiagnostic)]
175 pub struct MethodCallOnUnknownType {
176 #[message = "the type of this value must be known to call a method on a raw pointer on it"]
180 #[derive(SessionDiagnostic)]
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"]
186 #[label = "`{item_name}` bound here first"]
188 pub item_name: Ident,
189 pub def_path: String,
192 #[derive(SessionDiagnostic)]
194 pub struct AddressOfTemporaryTaken {
195 #[message = "cannot take address of a temporary"]
196 #[label = "temporary value"]