1 // ignore-tidy-filelength
3 syntax::register_diagnostics! {
6 A pattern used to match against an enum variant must provide a sub-pattern for
7 each field of the enum variant. This error indicates that a pattern attempted to
8 extract an incorrect number of fields from a variant.
12 Apple(String, String),
17 Here the `Apple` variant has two fields, and should be matched against like so:
21 Apple(String, String),
25 let x = Fruit::Apple(String::new(), String::new());
29 Fruit::Apple(a, b) => {},
34 Matching with the wrong number of fields has no sensible interpretation:
38 Apple(String, String),
42 let x = Fruit::Apple(String::new(), String::new());
46 Fruit::Apple(a) => {},
47 Fruit::Apple(a, b, c) => {},
51 Check how many fields the enum was declared with and ensure that your pattern
56 Each field of a struct can only be bound once in a pattern. Erroneous code
66 let x = Foo { a:1, b:2 };
68 let Foo { a: x, a: y } = x;
69 // error: field `a` bound multiple times in the pattern
73 Each occurrence of a field name binds the value of that field, so to fix this
74 error you will have to remove or alter the duplicate uses of the field name.
75 Perhaps you misspelled another field name? Example:
84 let x = Foo { a:1, b:2 };
86 let Foo { a: x, b: y } = x; // ok!
92 This error indicates that a struct pattern attempted to extract a non-existent
93 field from a struct. Struct fields are identified by the name used before the
94 colon `:` so struct patterns should resemble the declaration of the struct type
104 let thing = Thing { x: 1, y: 2 };
107 Thing { x: xfield, y: yfield } => {}
111 If you are using shorthand field patterns but want to refer to the struct field
112 by a different name, you should rename it explicitly.
116 ```compile_fail,E0026
122 let thing = Thing { x: 0, y: 0 };
137 let thing = Thing { x: 0, y: 0 };
140 Thing { x, y: z } => {}
146 This error indicates that a pattern for a struct fails to specify a sub-pattern
147 for every one of the struct's fields. Ensure that each field from the struct's
148 definition is mentioned in the pattern, or use `..` to ignore unwanted fields.
152 ```compile_fail,E0027
158 let d = Dog { name: "Rusty".to_string(), age: 8 };
160 // This is incorrect.
166 This is correct (explicit):
174 let d = Dog { name: "Rusty".to_string(), age: 8 };
177 Dog { name: ref n, age: x } => {}
180 // This is also correct (ignore unused fields).
182 Dog { age: x, .. } => {}
188 In a match expression, only numbers and characters can be matched against a
189 range. This is because the compiler checks that the range is non-empty at
190 compile-time, and is unable to evaluate arbitrary comparison functions. If you
191 want to capture values of an orderable type between two end-points, you can use
194 ```compile_fail,E0029
195 let string = "salutations !";
197 // The ordering relation for strings cannot be evaluated at compile time,
198 // so this doesn't work:
200 "hello" ..= "world" => {}
204 // This is a more general version, using a guard:
206 s if s >= "hello" && s <= "world" => {}
213 This error indicates that a pointer to a trait type cannot be implicitly
214 dereferenced by a pattern. Every trait defines a type, but because the
215 size of trait implementers isn't fixed, this type has no compile-time size.
216 Therefore, all accesses to trait types must be through pointers. If you
217 encounter this error you should try to avoid dereferencing the pointer.
219 ```compile_fail,E0033
220 # trait SomeTrait { fn method_one(&self){} fn method_two(&self){} }
221 # impl<T> SomeTrait for T {}
222 let trait_obj: &SomeTrait = &"some_value";
224 // This tries to implicitly dereference to create an unsized local variable.
225 let &invalid = trait_obj;
227 // You can call methods without binding to the value being pointed at.
228 trait_obj.method_one();
229 trait_obj.method_two();
232 You can read more about trait objects in the [Trait Objects] section of the
235 [Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects
239 The compiler doesn't know what method to call because more than one method
240 has the same prototype. Erroneous code example:
242 ```compile_fail,E0034
253 impl Trait1 for Test { fn foo() {} }
254 impl Trait2 for Test { fn foo() {} }
257 Test::foo() // error, which foo() to call?
261 To avoid this error, you have to keep only one of them and remove the others.
262 So let's take our example and fix it:
271 impl Trait1 for Test { fn foo() {} }
274 Test::foo() // and now that's good!
278 However, a better solution would be using fully explicit naming of type and
292 impl Trait1 for Test { fn foo() {} }
293 impl Trait2 for Test { fn foo() {} }
296 <Test as Trait1>::foo()
313 impl F for X { fn m(&self) { println!("I am F"); } }
314 impl G for X { fn m(&self) { println!("I am G"); } }
319 F::m(&f); // it displays "I am F"
320 G::m(&f); // it displays "I am G"
326 It is not allowed to manually call destructors in Rust. It is also not
327 necessary to do this since `drop` is called automatically whenever a value goes
330 Here's an example of this error:
332 ```compile_fail,E0040
344 let mut x = Foo { x: -7 };
345 x.drop(); // error: explicit use of destructor method
351 You cannot use type or const parameters on foreign items.
352 Example of erroneous code:
354 ```compile_fail,E0044
355 extern { fn some_func<T>(x: T); }
358 To fix this, replace the generic parameter with the specializations that you
362 extern { fn some_func_i32(x: i32); }
363 extern { fn some_func_i64(x: i64); }
368 Rust only supports variadic parameters for interoperability with C code in its
369 FFI. As such, variadic parameters can only be used with functions which are
370 using the C ABI. Examples of erroneous code:
373 #![feature(unboxed_closures)]
375 extern "rust-call" { fn foo(x: u8, ...); }
379 fn foo(x: u8, ...) {}
382 To fix such code, put them in an extern "C" block:
392 Items are missing in a trait implementation. Erroneous code example:
394 ```compile_fail,E0046
402 // error: not all trait items implemented, missing: `foo`
405 When trying to make some type implement a trait `Foo`, you must, at minimum,
406 provide implementations for all of `Foo`'s required methods (meaning the
407 methods that do not have default implementations), as well as any required
408 trait items like associated types or constants. Example:
424 This error indicates that an attempted implementation of a trait method
425 has the wrong number of type or const parameters.
427 For example, the trait below has a method `foo` with a type parameter `T`,
428 but the implementation of `foo` for the type `Bar` is missing this parameter:
430 ```compile_fail,E0049
432 fn foo<T: Default>(x: T) -> Self;
437 // error: method `foo` has 0 type parameters but its trait declaration has 1
440 fn foo(x: bool) -> Self { Bar }
446 This error indicates that an attempted implementation of a trait method
447 has the wrong number of function parameters.
449 For example, the trait below has a method `foo` with two function parameters
450 (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
453 ```compile_fail,E0050
455 fn foo(&self, x: u8) -> bool;
460 // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
463 fn foo(&self) -> bool { true }
469 The parameters of any trait method must match between a trait implementation
470 and the trait definition.
472 Here are a couple examples of this error:
474 ```compile_fail,E0053
483 // error, expected u16, found i16
486 // error, types differ in mutability
487 fn bar(&mut self) { }
493 It is not allowed to cast to a bool. If you are trying to cast a numeric type
494 to a bool, you can compare it with zero instead:
496 ```compile_fail,E0054
499 // Not allowed, won't compile
500 let x_is_nonzero = x as bool;
507 let x_is_nonzero = x != 0;
512 During a method call, a value is automatically dereferenced as many times as
513 needed to make the value's type match the method's receiver. The catch is that
514 the compiler will only attempt to dereference a number of times up to the
515 recursion limit (which can be set via the `recursion_limit` attribute).
517 For a somewhat artificial example:
519 ```compile_fail,E0055
520 #![recursion_limit="5"]
530 let ref_foo = &&&&&Foo;
532 // error, reached the recursion limit while auto-dereferencing `&&&&&Foo`
537 One fix may be to increase the recursion limit. Note that it is possible to
538 create an infinite recursion of dereferencing, in which case the only fix is to
539 somehow break the recursion.
543 When invoking closures or other implementations of the function traits `Fn`,
544 `FnMut` or `FnOnce` using call notation, the number of parameters passed to the
545 function must match its definition.
547 An example using a closure:
549 ```compile_fail,E0057
551 let a = f(); // invalid, too few parameters
552 let b = f(4); // this works!
553 let c = f(2, 3); // invalid, too many parameters
556 A generic function must be treated similarly:
559 fn foo<F: Fn()>(f: F) {
560 f(); // this is valid, but f(3) would not work
566 The built-in function traits are generic over a tuple of the function arguments.
567 If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
568 (`Fn(T) -> U`) to denote the function trait, the type parameter should be a
569 tuple. Otherwise function call notation cannot be used and the trait will not be
570 implemented by closures.
572 The most likely source of this error is using angle-bracket notation without
573 wrapping the function argument type into a tuple, for example:
575 ```compile_fail,E0059
576 #![feature(unboxed_closures)]
578 fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
581 It can be fixed by adjusting the trait bound like this:
584 #![feature(unboxed_closures)]
586 fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
589 Note that `(T,)` always denotes the type of a 1-tuple containing an element of
590 type `T`. The comma is necessary for syntactic disambiguation.
594 External C functions are allowed to be variadic. However, a variadic function
595 takes a minimum number of arguments. For example, consider C's variadic `printf`
599 use std::os::raw::{c_char, c_int};
602 fn printf(_: *const c_char, ...) -> c_int;
606 Using this declaration, it must be called with at least one argument, so
607 simply calling `printf()` is invalid. But the following uses are allowed:
610 # #![feature(static_nobundle)]
611 # use std::os::raw::{c_char, c_int};
612 # #[cfg_attr(all(windows, target_env = "msvc"),
613 # link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
614 # extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
617 use std::ffi::CString;
619 let fmt = CString::new("test\n").unwrap();
620 printf(fmt.as_ptr());
622 let fmt = CString::new("number = %d\n").unwrap();
623 printf(fmt.as_ptr(), 3);
625 let fmt = CString::new("%d, %d\n").unwrap();
626 printf(fmt.as_ptr(), 10, 5);
631 // ^ Note: On MSVC 2015, the `printf` function is "inlined" in the C code, and
632 // the C runtime does not contain the `printf` definition. This leads to linker
633 // error from the doc test (issue #42830).
634 // This can be fixed by linking to the static library
635 // `legacy_stdio_definitions.lib` (see https://stackoverflow.com/a/36504365/).
636 // If this compatibility library is removed in the future, consider changing
637 // `printf` in this example to another well-known variadic function.
640 The number of arguments passed to a function must match the number of arguments
641 specified in the function signature.
643 For example, a function like:
646 fn f(a: u16, b: &str) {}
649 Must always be called with exactly two arguments, e.g., `f(2, "test")`.
651 Note that Rust does not have a notion of optional function arguments or
652 variadic functions (except for its C-FFI).
656 This error indicates that during an attempt to build a struct or struct-like
657 enum variant, one of the fields was specified more than once. Erroneous code
660 ```compile_fail,E0062
668 x: 0, // error: field `x` specified more than once
673 Each field should be specified exactly one time. Example:
681 let x = Foo { x: 0 }; // ok!
687 This error indicates that during an attempt to build a struct or struct-like
688 enum variant, one of the fields was not provided. Erroneous code example:
690 ```compile_fail,E0063
697 let x = Foo { x: 0 }; // error: missing field: `y`
701 Each field should be specified exactly once. Example:
710 let x = Foo { x: 0, y: 0 }; // ok!
716 The left-hand side of a compound assignment expression must be a place
717 expression. A place expression represents a memory location and includes
718 item paths (ie, namespaced variables), dereferences, indexing expressions,
719 and field references.
721 Let's start with some erroneous code examples:
723 ```compile_fail,E0067
724 use std::collections::LinkedList;
726 // Bad: assignment to non-place expression
727 LinkedList::new() += 1;
731 fn some_func(i: &mut i32) {
732 i += 12; // Error : '+=' operation cannot be applied on a reference !
736 And now some working examples:
745 fn some_func(i: &mut i32) {
752 The compiler found a function whose body contains a `return;` statement but
753 whose return type is not `()`. An example of this is:
755 ```compile_fail,E0069
762 Since `return;` is just like `return ();`, there is a mismatch between the
763 function's return type and the value being returned.
767 The left-hand side of an assignment operator must be a place expression. A
768 place expression represents a memory location and can be a variable (with
769 optional namespacing), a dereference, an indexing expression or a field
772 More details can be found in the [Expressions] section of the Reference.
774 [Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
776 Now, we can go further. Here are some erroneous code examples:
778 ```compile_fail,E0070
784 const SOME_CONST : i32 = 12;
786 fn some_other_func() {}
789 SOME_CONST = 14; // error : a constant value cannot be changed!
790 1 = 3; // error : 1 isn't a valid place!
791 some_other_func() = 4; // error : we cannot assign value to a function!
792 SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
797 And now let's give working examples:
804 let mut s = SomeStruct {x: 0, y: 0};
806 s.x = 3; // that's good !
810 fn some_func(x: &mut i32) {
811 *x = 12; // that's good !
817 You tried to use structure-literal syntax to create an item that is
818 not a structure or enum variant.
820 Example of erroneous code:
822 ```compile_fail,E0071
824 let t = U32 { value: 4 }; // error: expected struct, variant or union type,
825 // found builtin type `u32`
828 To fix this, ensure that the name was correctly spelled, and that
829 the correct form of initializer was used.
831 For example, the code above can be fixed to:
839 let u = Foo::FirstValue(0i32);
847 #### Note: this error code is no longer emitted by the compiler.
849 You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
850 in order to make a new `Foo` value. This is because there would be no way a
851 first instance of `Foo` could be made to initialize another instance!
853 Here's an example of a struct that has this problem:
856 struct Foo { x: Box<Foo> } // error
859 One fix is to use `Option`, like so:
862 struct Foo { x: Option<Box<Foo>> }
865 Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
869 #### Note: this error code is no longer emitted by the compiler.
871 When using the `#[simd]` attribute on a tuple struct, the components of the
872 tuple struct must all be of a concrete, nongeneric type so the compiler can
873 reason about how to use SIMD with them. This error will occur if the types
876 This will cause an error:
879 #![feature(repr_simd)]
882 struct Bad<T>(T, T, T);
888 #![feature(repr_simd)]
891 struct Good(u32, u32, u32);
896 The `#[simd]` attribute can only be applied to non empty tuple structs, because
897 it doesn't make sense to try to use SIMD operations when there are no values to
900 This will cause an error:
902 ```compile_fail,E0075
903 #![feature(repr_simd)]
912 #![feature(repr_simd)]
920 When using the `#[simd]` attribute to automatically use SIMD operations in tuple
921 struct, the types in the struct must all be of the same type, or the compiler
922 will trigger this error.
924 This will cause an error:
926 ```compile_fail,E0076
927 #![feature(repr_simd)]
930 struct Bad(u16, u32, u32);
936 #![feature(repr_simd)]
939 struct Good(u32, u32, u32);
944 When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
945 must be machine types so SIMD operations can be applied to them.
947 This will cause an error:
949 ```compile_fail,E0077
950 #![feature(repr_simd)]
959 #![feature(repr_simd)]
962 struct Good(u32, u32, u32);
967 Enum discriminants are used to differentiate enum variants stored in memory.
968 This error indicates that the same value was used for two or more variants,
969 making them impossible to tell apart.
971 ```compile_fail,E0081
989 Note that variants without a manually specified discriminant are numbered from
990 top to bottom starting from 0, so clashes can occur with seemingly unrelated
993 ```compile_fail,E0081
1000 Here `X` will have already been specified the discriminant 0 by the time `Y` is
1001 encountered, so a conflict occurs.
1005 An unsupported representation was attempted on a zero-variant enum.
1007 Erroneous code example:
1009 ```compile_fail,E0084
1011 enum NightsWatch {} // error: unsupported representation for zero-variant enum
1014 It is impossible to define an integer type to be used to represent zero-variant
1015 enum values because there are no zero-variant enum values. There is no way to
1016 construct an instance of the following type using only safe code. So you have
1017 two solutions. Either you add variants in your enum:
1027 or you remove the integer represention of your enum:
1034 // FIXME(const_generics:docs): example of inferring const parameter.
1036 #### Note: this error code is no longer emitted by the compiler.
1038 Too many type arguments were supplied for a function. For example:
1040 ```compile_fail,E0107
1044 foo::<f64, bool>(); // error: wrong number of type arguments:
1045 // expected 1, found 2
1049 The number of supplied arguments must exactly match the number of defined type
1054 #### Note: this error code is no longer emitted by the compiler.
1056 You gave too many lifetime arguments. Erroneous code example:
1058 ```compile_fail,E0107
1062 f::<'static>() // error: wrong number of lifetime arguments:
1063 // expected 0, found 1
1067 Please check you give the right number of lifetime arguments. Example:
1077 It's also important to note that the Rust compiler can generally
1078 determine the lifetime by itself. Example:
1086 // it can be written like this
1087 fn get_value<'a>(&'a self) -> &'a str { &self.value }
1088 // but the compiler works fine with this too:
1089 fn without_lifetime(&self) -> &str { &self.value }
1093 let f = Foo { value: "hello".to_owned() };
1095 println!("{}", f.get_value());
1096 println!("{}", f.without_lifetime());
1102 #### Note: this error code is no longer emitted by the compiler.
1104 Too few type arguments were supplied for a function. For example:
1106 ```compile_fail,E0107
1110 foo::<f64>(); // error: wrong number of type arguments: expected 2, found 1
1114 Note that if a function takes multiple type arguments but you want the compiler
1115 to infer some of them, you can use type placeholders:
1117 ```compile_fail,E0107
1118 fn foo<T, U>(x: T) {}
1122 foo::<f64>(x); // error: wrong number of type arguments:
1123 // expected 2, found 1
1124 foo::<_, f64>(x); // same as `foo::<bool, f64>(x)`
1130 #### Note: this error code is no longer emitted by the compiler.
1132 You gave too few lifetime arguments. Example:
1134 ```compile_fail,E0107
1135 fn foo<'a: 'b, 'b: 'a>() {}
1138 foo::<'static>(); // error: wrong number of lifetime arguments:
1139 // expected 2, found 1
1143 Please check you give the right number of lifetime arguments. Example:
1146 fn foo<'a: 'b, 'b: 'a>() {}
1149 foo::<'static, 'static>();
1155 You gave an unnecessary type or const parameter in a type alias. Erroneous
1158 ```compile_fail,E0091
1159 type Foo<T> = u32; // error: type parameter `T` is unused
1161 type Foo<A,B> = Box<A>; // error: type parameter `B` is unused
1164 Please check you didn't write too many parameters. Example:
1167 type Foo = u32; // ok!
1168 type Foo2<A> = Box<A>; // ok!
1173 You tried to declare an undefined atomic operation function.
1174 Erroneous code example:
1176 ```compile_fail,E0092
1177 #![feature(intrinsics)]
1179 extern "rust-intrinsic" {
1180 fn atomic_foo(); // error: unrecognized atomic operation
1185 Please check you didn't make a mistake in the function's name. All intrinsic
1186 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1187 libcore/intrinsics.rs in the Rust source code. Example:
1190 #![feature(intrinsics)]
1192 extern "rust-intrinsic" {
1193 fn atomic_fence(); // ok!
1199 You declared an unknown intrinsic function. Erroneous code example:
1201 ```compile_fail,E0093
1202 #![feature(intrinsics)]
1204 extern "rust-intrinsic" {
1205 fn foo(); // error: unrecognized intrinsic function: `foo`
1215 Please check you didn't make a mistake in the function's name. All intrinsic
1216 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1217 libcore/intrinsics.rs in the Rust source code. Example:
1220 #![feature(intrinsics)]
1222 extern "rust-intrinsic" {
1223 fn atomic_fence(); // ok!
1235 You gave an invalid number of type parameters to an intrinsic function.
1236 Erroneous code example:
1238 ```compile_fail,E0094
1239 #![feature(intrinsics)]
1241 extern "rust-intrinsic" {
1242 fn size_of<T, U>() -> usize; // error: intrinsic has wrong number
1243 // of type parameters
1247 Please check that you provided the right number of type parameters
1248 and verify with the function declaration in the Rust source code.
1252 #![feature(intrinsics)]
1254 extern "rust-intrinsic" {
1255 fn size_of<T>() -> usize; // ok!
1261 This error means that an incorrect number of generic arguments were provided:
1263 ```compile_fail,E0107
1264 struct Foo<T> { x: T }
1266 struct Bar { x: Foo } // error: wrong number of type arguments:
1267 // expected 1, found 0
1268 struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
1269 // expected 1, found 2
1271 fn foo<T, U>(x: T, y: U) {}
1275 foo::<bool>(x); // error: wrong number of type arguments:
1276 // expected 2, found 1
1277 foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
1278 // expected 2, found 3
1284 f::<'static>(); // error: wrong number of lifetime arguments:
1285 // expected 0, found 1
1292 You tried to provide a generic argument to a type which doesn't need it.
1293 Erroneous code example:
1295 ```compile_fail,E0109
1296 type X = u32<i32>; // error: type arguments are not allowed for this type
1297 type Y = bool<'static>; // error: lifetime parameters are not allowed on
1301 Check that you used the correct argument and that the definition is correct.
1306 type X = u32; // ok!
1307 type Y = bool; // ok!
1310 Note that generic arguments for enum variant constructors go after the variant,
1311 not after the enum. For example, you would write `Option::None::<u32>`,
1312 rather than `Option::<u32>::None`.
1316 #### Note: this error code is no longer emitted by the compiler.
1318 You tried to provide a lifetime to a type which doesn't need it.
1319 See `E0109` for more details.
1323 You can only define an inherent implementation for a type in the same crate
1324 where the type was defined. For example, an `impl` block as below is not allowed
1325 since `Vec` is defined in the standard library:
1327 ```compile_fail,E0116
1328 impl Vec<u8> { } // error
1331 To fix this problem, you can do either of these things:
1333 - define a trait that has the desired associated functions/types/constants and
1334 implement the trait for the type in question
1335 - define a new type wrapping the type and define an implementation on the new
1338 Note that using the `type` keyword does not work here because `type` only
1339 introduces a type alias:
1341 ```compile_fail,E0116
1342 type Bytes = Vec<u8>;
1344 impl Bytes { } // error, same as above
1349 This error indicates a violation of one of Rust's orphan rules for trait
1350 implementations. The rule prohibits any implementation of a foreign trait (a
1351 trait defined in another crate) where
1353 - the type that is implementing the trait is foreign
1354 - all of the parameters being passed to the trait (if there are any) are also
1357 Here's one example of this error:
1359 ```compile_fail,E0117
1360 impl Drop for u32 {}
1363 To avoid this kind of error, ensure that at least one local type is referenced
1367 pub struct Foo; // you define your type in your crate
1369 impl Drop for Foo { // and you can implement the trait on it!
1370 // code of trait implementation here
1371 # fn drop(&mut self) { }
1374 impl From<Foo> for i32 { // or you use a type from your crate as
1376 fn from(i: Foo) -> i32 {
1382 Alternatively, define a trait locally and implement that instead:
1386 fn get(&self) -> usize;
1390 fn get(&self) -> usize { 0 }
1394 For information on the design of the orphan rules, see [RFC 1023].
1396 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
1400 You're trying to write an inherent implementation for something which isn't a
1401 struct nor an enum. Erroneous code example:
1403 ```compile_fail,E0118
1404 impl (u8, u8) { // error: no base type found for inherent implementation
1405 fn get_state(&self) -> String {
1411 To fix this error, please implement a trait on the type or wrap it in a struct.
1415 // we create a trait here
1416 trait LiveLongAndProsper {
1417 fn get_state(&self) -> String;
1420 // and now you can implement it on (u8, u8)
1421 impl LiveLongAndProsper for (u8, u8) {
1422 fn get_state(&self) -> String {
1423 "He's dead, Jim!".to_owned()
1428 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
1429 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
1433 struct TypeWrapper((u8, u8));
1436 fn get_state(&self) -> String {
1437 "Fascinating!".to_owned()
1444 An attempt was made to implement Drop on a trait, which is not allowed: only
1445 structs and enums can implement Drop. An example causing this error:
1447 ```compile_fail,E0120
1450 impl Drop for MyTrait {
1451 fn drop(&mut self) {}
1455 A workaround for this problem is to wrap the trait up in a struct, and implement
1456 Drop on that. An example is shown below:
1460 struct MyWrapper<T: MyTrait> { foo: T }
1462 impl <T: MyTrait> Drop for MyWrapper<T> {
1463 fn drop(&mut self) {}
1468 Alternatively, wrapping trait objects requires something like the following:
1473 //or Box<MyTrait>, if you wanted an owned trait object
1474 struct MyWrapper<'a> { foo: &'a MyTrait }
1476 impl <'a> Drop for MyWrapper<'a> {
1477 fn drop(&mut self) {}
1483 In order to be consistent with Rust's lack of global type inference,
1484 type and const placeholders are disallowed by design in item signatures.
1486 Examples of this error include:
1488 ```compile_fail,E0121
1489 fn foo() -> _ { 5 } // error, explicitly write out the return type instead
1491 static BAR: _ = "test"; // error, explicitly write out the type instead
1496 You declared two fields of a struct with the same name. Erroneous code
1499 ```compile_fail,E0124
1502 field1: i32, // error: field is already declared
1506 Please verify that the field names have been correctly spelled. Example:
1517 It is not possible to define `main` with generic parameters.
1518 When `main` is present, it must take no arguments and return `()`.
1519 Erroneous code example:
1521 ```compile_fail,E0131
1522 fn main<T>() { // error: main function is not allowed to have generic parameters
1528 A function with the `start` attribute was declared with type parameters.
1530 Erroneous code example:
1532 ```compile_fail,E0132
1539 It is not possible to declare type parameters on a function that has the `start`
1540 attribute. Such a function must have the following type signature (for more
1541 information, view [the unstable book][1]):
1543 [1]: https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib
1547 fn(isize, *const *const u8) -> isize;
1556 fn my_start(argc: isize, argv: *const *const u8) -> isize {
1563 This error means that an attempt was made to match a struct type enum
1564 variant as a non-struct type:
1566 ```compile_fail,E0164
1567 enum Foo { B { i: u32 } }
1569 fn bar(foo: Foo) -> u32 {
1571 Foo::B(i) => i, // error E0164
1576 Try using `{}` instead:
1579 enum Foo { B { i: u32 } }
1581 fn bar(foo: Foo) -> u32 {
1590 Explicitly implementing both Drop and Copy for a type is currently disallowed.
1591 This feature can make some sense in theory, but the current implementation is
1592 incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so
1593 it has been disabled for now.
1595 [iss20126]: https://github.com/rust-lang/rust/issues/20126
1599 An associated function for a trait was defined to be static, but an
1600 implementation of the trait declared the same function to be a method (i.e., to
1601 take a `self` parameter).
1603 Here's an example of this error:
1605 ```compile_fail,E0185
1613 // error, method `foo` has a `&self` declaration in the impl, but not in
1621 An associated function for a trait was defined to be a method (i.e., to take a
1622 `self` parameter), but an implementation of the trait declared the same function
1625 Here's an example of this error:
1627 ```compile_fail,E0186
1635 // error, method `foo` has a `&self` declaration in the trait, but not in
1643 Trait objects need to have all associated types specified. Erroneous code
1646 ```compile_fail,E0191
1651 type Foo = Trait; // error: the value of the associated type `Bar` (from
1652 // the trait `Trait`) must be specified
1655 Please verify you specified all associated types of the trait and that you
1656 used the right trait. Example:
1663 type Foo = Trait<Bar=i32>; // ok!
1668 Negative impls are only allowed for auto traits. For more
1669 information see the [opt-in builtin traits RFC][RFC 19].
1671 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
1675 #### Note: this error code is no longer emitted by the compiler.
1677 `where` clauses must use generic type parameters: it does not make sense to use
1678 them otherwise. An example causing this error:
1685 #[derive(Copy,Clone)]
1690 impl Foo for Wrapper<u32> where Wrapper<u32>: Clone {
1695 This use of a `where` clause is strange - a more common usage would look
1696 something like the following:
1703 #[derive(Copy,Clone)]
1707 impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone {
1712 Here, we're saying that the implementation exists on Wrapper only when the
1713 wrapped type `T` implements `Clone`. The `where` clause is important because
1714 some types will not implement `Clone`, and thus will not get this method.
1716 In our erroneous example, however, we're referencing a single concrete type.
1717 Since we know for certain that `Wrapper<u32>` implements `Clone`, there's no
1718 reason to also specify it in a `where` clause.
1722 Your method's lifetime parameters do not match the trait declaration.
1723 Erroneous code example:
1725 ```compile_fail,E0195
1727 fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
1732 impl Trait for Foo {
1733 fn bar<'a,'b>(x: &'a str, y: &'b str) {
1734 // error: lifetime parameters or bounds on method `bar`
1735 // do not match the trait declaration
1740 The lifetime constraint `'b` for bar() implementation does not match the
1741 trait declaration. Ensure lifetime declarations match exactly in both trait
1742 declaration and implementation. Example:
1746 fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1751 impl Trait for Foo {
1752 fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
1759 Safe traits should not have unsafe implementations, therefore marking an
1760 implementation for a safe trait unsafe will cause a compiler error. Removing
1761 the unsafe marker on the trait noted in the error will resolve this problem.
1763 ```compile_fail,E0199
1768 // this won't compile because Bar is safe
1769 unsafe impl Bar for Foo { }
1770 // this will compile
1771 impl Bar for Foo { }
1776 Unsafe traits must have unsafe implementations. This error occurs when an
1777 implementation for an unsafe trait isn't marked as unsafe. This may be resolved
1778 by marking the unsafe implementation as unsafe.
1780 ```compile_fail,E0200
1783 unsafe trait Bar { }
1785 // this won't compile because Bar is unsafe and impl isn't unsafe
1786 impl Bar for Foo { }
1787 // this will compile
1788 unsafe impl Bar for Foo { }
1793 It is an error to define two associated items (like methods, associated types,
1794 associated functions, etc.) with the same identifier.
1798 ```compile_fail,E0201
1802 fn bar(&self) -> bool { self.0 > 5 }
1803 fn bar() {} // error: duplicate associated function
1808 fn baz(&self) -> bool;
1814 fn baz(&self) -> bool { true }
1816 // error: duplicate method
1817 fn baz(&self) -> bool { self.0 > 5 }
1819 // error: duplicate associated type
1824 Note, however, that items with the same name are allowed for inherent `impl`
1825 blocks that don't overlap:
1831 fn bar(&self) -> bool { self.0 > 5 }
1835 fn bar(&self) -> bool { self.0 }
1841 Inherent associated types were part of [RFC 195] but are not yet implemented.
1842 See [the tracking issue][iss8995] for the status of this implementation.
1844 [RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
1845 [iss8995]: https://github.com/rust-lang/rust/issues/8995
1849 An attempt to implement the `Copy` trait for a struct failed because one of the
1850 fields does not implement `Copy`. To fix this, you must implement `Copy` for the
1851 mentioned field. Note that this may not be possible, as in the example of
1853 ```compile_fail,E0204
1858 impl Copy for Foo { }
1861 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1863 Here's another example that will fail:
1865 ```compile_fail,E0204
1872 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1873 differs from the behavior for `&T`, which is always `Copy`).
1877 #### Note: this error code is no longer emitted by the compiler.
1879 An attempt to implement the `Copy` trait for an enum failed because one of the
1880 variants does not implement `Copy`. To fix this, you must implement `Copy` for
1881 the mentioned variant. Note that this may not be possible, as in the example of
1883 ```compile_fail,E0204
1889 impl Copy for Foo { }
1892 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1894 Here's another example that will fail:
1896 ```compile_fail,E0204
1904 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1905 differs from the behavior for `&T`, which is always `Copy`).
1909 You can only implement `Copy` for a struct or enum. Both of the following
1910 examples will fail, because neither `[u8; 256]` nor `&'static mut Bar`
1911 (mutable reference to `Bar`) is a struct or enum:
1913 ```compile_fail,E0206
1914 type Foo = [u8; 256];
1915 impl Copy for Foo { } // error
1917 #[derive(Copy, Clone)]
1919 impl Copy for &'static mut Bar { } // error
1924 Any type parameter or lifetime parameter of an `impl` must meet at least one of
1925 the following criteria:
1927 - it appears in the _implementing type_ of the impl, e.g. `impl<T> Foo<T>`
1928 - for a trait impl, it appears in the _implemented trait_, e.g.
1929 `impl<T> SomeTrait<T> for Foo`
1930 - it is bound as an associated type, e.g. `impl<T, U> SomeTrait for T
1931 where T: AnotherTrait<AssocType=U>`
1935 Suppose we have a struct `Foo` and we would like to define some methods for it.
1936 The following definition leads to a compiler error:
1938 ```compile_fail,E0207
1941 impl<T: Default> Foo {
1942 // error: the type parameter `T` is not constrained by the impl trait, self
1943 // type, or predicates [E0207]
1944 fn get(&self) -> T {
1945 <T as Default>::default()
1950 The problem is that the parameter `T` does not appear in the implementing type
1951 (`Foo`) of the impl. In this case, we can fix the error by moving the type
1952 parameter from the `impl` to the method `get`:
1958 // Move the type parameter from the impl to the method
1960 fn get<T: Default>(&self) -> T {
1961 <T as Default>::default()
1968 As another example, suppose we have a `Maker` trait and want to establish a
1969 type `FooMaker` that makes `Foo`s:
1971 ```compile_fail,E0207
1974 fn make(&mut self) -> Self::Item;
1983 impl<T: Default> Maker for FooMaker {
1984 // error: the type parameter `T` is not constrained by the impl trait, self
1985 // type, or predicates [E0207]
1988 fn make(&mut self) -> Foo<T> {
1989 Foo { foo: <T as Default>::default() }
1994 This fails to compile because `T` does not appear in the trait or in the
1997 One way to work around this is to introduce a phantom type parameter into
1998 `FooMaker`, like so:
2001 use std::marker::PhantomData;
2005 fn make(&mut self) -> Self::Item;
2012 // Add a type parameter to `FooMaker`
2013 struct FooMaker<T> {
2014 phantom: PhantomData<T>,
2017 impl<T: Default> Maker for FooMaker<T> {
2020 fn make(&mut self) -> Foo<T> {
2022 foo: <T as Default>::default(),
2028 Another way is to do away with the associated type in `Maker` and use an input
2029 type parameter instead:
2032 // Use a type parameter instead of an associated type here
2034 fn make(&mut self) -> Item;
2043 impl<T: Default> Maker<Foo<T>> for FooMaker {
2044 fn make(&mut self) -> Foo<T> {
2045 Foo { foo: <T as Default>::default() }
2050 ### Additional information
2052 For more information, please see [RFC 447].
2054 [RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md
2058 This error indicates a violation of one of Rust's orphan rules for trait
2059 implementations. The rule concerns the use of type parameters in an
2060 implementation of a foreign trait (a trait defined in another crate), and
2061 states that type parameters must be "covered" by a local type. To understand
2062 what this means, it is perhaps easiest to consider a few examples.
2064 If `ForeignTrait` is a trait defined in some external crate `foo`, then the
2065 following trait `impl` is an error:
2067 ```compile_fail,E0210
2068 # #[cfg(for_demonstration_only)]
2070 # #[cfg(for_demonstration_only)]
2071 use foo::ForeignTrait;
2072 # use std::panic::UnwindSafe as ForeignTrait;
2074 impl<T> ForeignTrait for T { } // error
2078 To work around this, it can be covered with a local type, `MyType`:
2081 # use std::panic::UnwindSafe as ForeignTrait;
2082 struct MyType<T>(T);
2083 impl<T> ForeignTrait for MyType<T> { } // Ok
2086 Please note that a type alias is not sufficient.
2088 For another example of an error, suppose there's another trait defined in `foo`
2089 named `ForeignTrait2` that takes two type parameters. Then this `impl` results
2090 in the same rule violation:
2092 ```ignore (cannot-doctest-multicrate-project)
2094 impl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error
2097 The reason for this is that there are two appearances of type parameter `T` in
2098 the `impl` header, both as parameters for `ForeignTrait2`. The first appearance
2099 is uncovered, and so runs afoul of the orphan rule.
2101 Consider one more example:
2103 ```ignore (cannot-doctest-multicrate-project)
2104 impl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok
2107 This only differs from the previous `impl` in that the parameters `T` and
2108 `MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*
2109 violate the orphan rule; it is permitted.
2111 To see why that last example was allowed, you need to understand the general
2112 rule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:
2114 ```ignore (only-for-syntax-highlight)
2115 impl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }
2118 where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`
2119 are types. One of the types `T0, ..., Tn` must be a local type (this is another
2120 orphan rule, see the explanation for E0117). Let `i` be the smallest integer
2121 such that `Ti` is a local type. Then no type parameter can appear in any of the
2124 For information on the design of the orphan rules, see [RFC 1023].
2126 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
2130 #### Note: this error code is no longer emitted by the compiler.
2132 You used a function or type which doesn't fit the requirements for where it was
2133 used. Erroneous code examples:
2136 #![feature(intrinsics)]
2138 extern "rust-intrinsic" {
2139 fn size_of<T>(); // error: intrinsic has wrong type
2144 fn main() -> i32 { 0 }
2145 // error: main function expects type: `fn() {main}`: expected (), found i32
2152 // error: mismatched types in range: expected u8, found i8
2162 fn x(self: Rc<Foo>) {}
2163 // error: mismatched self type: expected `Foo`: expected struct
2164 // `Foo`, found struct `alloc::rc::Rc`
2168 For the first code example, please check the function definition. Example:
2171 #![feature(intrinsics)]
2173 extern "rust-intrinsic" {
2174 fn size_of<T>() -> usize; // ok!
2178 The second case example is a bit particular: the main function must always
2179 have this definition:
2185 They never take parameters and never return types.
2187 For the third example, when you match, all patterns must have the same type
2188 as the type you're matching on. Example:
2194 0u8..=3u8 => (), // ok!
2199 And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
2200 or `&mut Self` work as explicit self parameters. Example:
2206 fn x(self: Box<Foo>) {} // ok!
2212 You used an associated type which isn't defined in the trait.
2213 Erroneous code example:
2215 ```compile_fail,E0220
2220 type Foo = T1<F=i32>; // error: associated type `F` not found for `T1`
2227 // error: Baz is used but not declared
2228 fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2232 Make sure that you have defined the associated type in the trait body.
2233 Also, verify that you used the right trait or you didn't misspell the
2234 associated type name. Example:
2241 type Foo = T1<Bar=i32>; // ok!
2247 type Baz; // we declare `Baz` in our trait.
2249 // and now we can use it here:
2250 fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2256 An attempt was made to retrieve an associated type, but the type was ambiguous.
2259 ```compile_fail,E0221
2275 In this example, `Foo` defines an associated type `A`. `Bar` inherits that type
2276 from `Foo`, and defines another associated type of the same name. As a result,
2277 when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined
2278 by `Foo` or the one defined by `Bar`.
2280 There are two options to work around this issue. The first is simply to rename
2281 one of the types. Alternatively, one can specify the intended type using the
2295 let _: <Self as Bar>::A;
2302 An attempt was made to retrieve an associated type, but the type was ambiguous.
2305 ```compile_fail,E0223
2306 trait MyTrait {type X; }
2309 let foo: MyTrait::X;
2313 The problem here is that we're attempting to take the type of X from MyTrait.
2314 Unfortunately, the type of X is not defined, because it's only made concrete in
2315 implementations of the trait. A working version of this code might look like:
2318 trait MyTrait {type X; }
2321 impl MyTrait for MyStruct {
2326 let foo: <MyStruct as MyTrait>::X;
2330 This syntax specifies that we want the X type from MyTrait, as made concrete in
2331 MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
2332 might implement two different traits with identically-named associated types.
2333 This syntax allows disambiguation between the two.
2337 You attempted to use multiple types as bounds for a closure or trait object.
2338 Rust does not currently support this. A simple example that causes this error:
2340 ```compile_fail,E0225
2342 let _: Box<dyn std::io::Read + std::io::Write>;
2346 Auto traits such as Send and Sync are an exception to this rule:
2347 It's possible to have bounds of one non-builtin trait, plus any number of
2348 auto traits. For example, the following compiles correctly:
2352 let _: Box<dyn std::io::Read + Send + Sync>;
2358 An associated type binding was done outside of the type parameter declaration
2359 and `where` clause. Erroneous code example:
2361 ```compile_fail,E0229
2364 fn boo(&self) -> <Self as Foo>::A;
2369 impl Foo for isize {
2371 fn boo(&self) -> usize { 42 }
2374 fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
2375 // error: associated type bindings are not allowed here
2378 To solve this error, please move the type bindings in the type parameter
2383 # trait Foo { type A; }
2384 fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok!
2387 Or in the `where` clause:
2391 # trait Foo { type A; }
2392 fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
2397 #### Note: this error code is no longer emitted by the compiler.
2399 This error indicates that not enough type parameters were found in a type or
2402 For example, the `Foo` struct below is defined to be generic in `T`, but the
2403 type parameter is missing in the definition of `Bar`:
2405 ```compile_fail,E0107
2406 struct Foo<T> { x: T }
2408 struct Bar { x: Foo }
2413 #### Note: this error code is no longer emitted by the compiler.
2415 This error indicates that too many type parameters were found in a type or
2418 For example, the `Foo` struct below has no type parameters, but is supplied
2419 with two in the definition of `Bar`:
2421 ```compile_fail,E0107
2422 struct Foo { x: bool }
2424 struct Bar<S, T> { x: Foo<S, T> }
2429 This error indicates that the `self` parameter in a method has an invalid
2432 Methods take a special first parameter, of which there are three variants:
2433 `self`, `&self`, and `&mut self`. These are syntactic sugar for
2434 `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
2440 // ^^^^^ `self` here is a reference to the receiver object
2443 impl Trait for Foo {
2445 // ^^^^^ the receiver type is `&Foo`
2449 The type `Self` acts as an alias to the type of the current trait
2450 implementer, or "receiver type". Besides the already mentioned `Self`,
2451 `&Self` and `&mut Self` valid receiver types, the following are also valid:
2452 `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
2453 (where P is one of the previous types except `Self`). Note that `Self` can
2454 also be the underlying implementing type, like `Foo` in the following
2462 impl Trait for Foo {
2463 fn foo(self: &Foo) {}
2467 E0307 will be emitted by the compiler when using an invalid reciver type,
2468 like in the following example:
2470 ```compile_fail,E0307
2476 impl Trait for Foo {
2477 fn foo(self: &Bar) {}
2481 The nightly feature [Arbintrary self types][AST] extends the accepted
2482 set of receiver types to also include any type that can dereference to
2486 #![feature(arbitrary_self_types)]
2491 // Because you can dereference `Bar` into `Foo`...
2492 impl std::ops::Deref for Bar {
2495 fn deref(&self) -> &Foo {
2501 fn foo(self: Bar) {}
2502 // ^^^^^^^^^ ...it can be used as the receiver type
2506 [AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html
2510 A cross-crate opt-out trait was implemented on something which wasn't a struct
2511 or enum type. Erroneous code example:
2513 ```compile_fail,E0321
2514 #![feature(optin_builtin_traits)]
2518 impl !Sync for Foo {}
2520 unsafe impl Send for &'static Foo {}
2521 // error: cross-crate traits with a default impl, like `core::marker::Send`,
2522 // can only be implemented for a struct/enum type, not
2526 Only structs and enums are permitted to impl Send, Sync, and other opt-out
2527 trait, and the struct or enum must be local to the current crate. So, for
2528 example, `unsafe impl Send for Rc<Foo>` is not allowed.
2532 The `Sized` trait is a special trait built-in to the compiler for types with a
2533 constant size known at compile-time. This trait is automatically implemented
2534 for types as needed by the compiler, and it is currently disallowed to
2535 explicitly implement it for a type.
2539 An associated const was implemented when another trait item was expected.
2540 Erroneous code example:
2542 ```compile_fail,E0323
2551 // error: item `N` is an associated const, which doesn't match its
2552 // trait `<Bar as Foo>`
2556 Please verify that the associated const wasn't misspelled and the correct trait
2557 was implemented. Example:
2567 type N = u32; // ok!
2581 const N : u32 = 0; // ok!
2587 A method was implemented when another trait item was expected. Erroneous
2590 ```compile_fail,E0324
2601 // error: item `N` is an associated method, which doesn't match its
2602 // trait `<Bar as Foo>`
2606 To fix this error, please verify that the method name wasn't misspelled and
2607 verify that you are indeed implementing the correct trait items. Example:
2627 An associated type was implemented when another trait item was expected.
2628 Erroneous code example:
2630 ```compile_fail,E0325
2639 // error: item `N` is an associated type, which doesn't match its
2640 // trait `<Bar as Foo>`
2644 Please verify that the associated type name wasn't misspelled and your
2645 implementation corresponds to the trait definition. Example:
2655 type N = u32; // ok!
2669 const N : u32 = 0; // ok!
2675 The types of any associated constants in a trait implementation must match the
2676 types in the trait definition. This error indicates that there was a mismatch.
2678 Here's an example of this error:
2680 ```compile_fail,E0326
2688 const BAR: u32 = 5; // error, expected bool, found u32
2694 The Unsize trait should not be implemented directly. All implementations of
2695 Unsize are provided automatically by the compiler.
2697 Erroneous code example:
2699 ```compile_fail,E0328
2702 use std::marker::Unsize;
2706 impl<T> Unsize<T> for MyType {}
2709 If you are defining your own smart pointer type and would like to enable
2710 conversion from a sized to an unsized type with the
2711 [DST coercion system][RFC 982], use [`CoerceUnsized`] instead.
2714 #![feature(coerce_unsized)]
2716 use std::ops::CoerceUnsized;
2718 pub struct MyType<T: ?Sized> {
2719 field_with_unsized_type: T,
2722 impl<T, U> CoerceUnsized<MyType<U>> for MyType<T>
2723 where T: CoerceUnsized<U> {}
2726 [RFC 982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
2727 [`CoerceUnsized`]: https://doc.rust-lang.org/std/ops/trait.CoerceUnsized.html
2731 #### Note: this error code is no longer emitted by the compiler.
2733 An attempt was made to access an associated constant through either a generic
2734 type parameter or `Self`. This is not supported yet. An example causing this
2735 error is shown below:
2744 impl Foo for MyStruct {
2745 const BAR: f64 = 0f64;
2748 fn get_bar_bad<F: Foo>(t: F) -> f64 {
2753 Currently, the value of `BAR` for a particular type can only be accessed
2754 through a concrete type, as shown below:
2763 impl Foo for MyStruct {
2764 const BAR: f64 = 0f64;
2767 fn get_bar_good() -> f64 {
2768 <MyStruct as Foo>::BAR
2774 An attempt was made to implement `Drop` on a concrete specialization of a
2775 generic type. An example is shown below:
2777 ```compile_fail,E0366
2782 impl Drop for Foo<u32> {
2783 fn drop(&mut self) {}
2787 This code is not legal: it is not possible to specialize `Drop` to a subset of
2788 implementations of a generic type. One workaround for this is to wrap the
2789 generic type, as shown below:
2801 fn drop(&mut self) {}
2807 An attempt was made to implement `Drop` on a specialization of a generic type.
2808 An example is shown below:
2810 ```compile_fail,E0367
2813 struct MyStruct<T> {
2817 impl<T: Foo> Drop for MyStruct<T> {
2818 fn drop(&mut self) {}
2822 This code is not legal: it is not possible to specialize `Drop` to a subset of
2823 implementations of a generic type. In order for this code to work, `MyStruct`
2824 must also require that `T` implements `Foo`. Alternatively, another option is
2825 to wrap the generic type in another that specializes appropriately:
2830 struct MyStruct<T> {
2834 struct MyStructWrapper<T: Foo> {
2838 impl <T: Foo> Drop for MyStructWrapper<T> {
2839 fn drop(&mut self) {}
2845 This error indicates that a binary assignment operator like `+=` or `^=` was
2846 applied to a type that doesn't support it. For example:
2848 ```compile_fail,E0368
2849 let mut x = 12f32; // error: binary operation `<<` cannot be applied to
2855 To fix this error, please check that this type implements this binary
2859 let mut x = 12u32; // the `u32` type does implement the `ShlAssign` trait
2864 It is also possible to overload most operators for your own type by
2865 implementing the `[OP]Assign` traits from `std::ops`.
2867 Another problem you might be facing is this: suppose you've overloaded the `+`
2868 operator for some type `Foo` by implementing the `std::ops::Add` trait for
2869 `Foo`, but you find that using `+=` does not work, as in this example:
2871 ```compile_fail,E0368
2879 fn add(self, rhs: Foo) -> Foo {
2885 let mut x: Foo = Foo(5);
2886 x += Foo(7); // error, `+= cannot be applied to the type `Foo`
2890 This is because `AddAssign` is not automatically implemented, so you need to
2891 manually implement it for your type.
2895 A binary operation was attempted on a type which doesn't support it.
2896 Erroneous code example:
2898 ```compile_fail,E0369
2899 let x = 12f32; // error: binary operation `<<` cannot be applied to
2905 To fix this error, please check that this type implements this binary
2909 let x = 12u32; // the `u32` type does implement it:
2910 // https://doc.rust-lang.org/stable/std/ops/trait.Shl.html
2915 It is also possible to overload most operators for your own type by
2916 implementing traits from `std::ops`.
2918 String concatenation appends the string on the right to the string on the
2919 left and may require reallocation. This requires ownership of the string
2920 on the left. If something should be added to a string literal, move the
2921 literal to the heap by allocating it with `to_owned()` like in
2922 `"Your text".to_owned()`.
2927 The maximum value of an enum was reached, so it cannot be automatically
2928 set in the next enum value. Erroneous code example:
2930 ```compile_fail,E0370
2933 X = 0x7fffffffffffffff,
2934 Y, // error: enum discriminant overflowed on value after
2935 // 9223372036854775807: i64; set explicitly via
2936 // Y = -9223372036854775808 if that is desired outcome
2940 To fix this, please set manually the next enum value or put the enum variant
2941 with the maximum value at the end of the enum. Examples:
2946 X = 0x7fffffffffffffff,
2957 X = 0x7fffffffffffffff,
2963 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
2964 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
2965 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
2966 definition, so it is not useful to do this.
2970 ```compile_fail,E0371
2971 trait Foo { fn foo(&self) { } }
2975 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
2976 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
2977 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
2978 impl Baz for Bar { } // Note: This is OK
2983 A struct without a field containing an unsized type cannot implement
2984 `CoerceUnsized`. An [unsized type][1] is any type that the compiler
2985 doesn't know the length or alignment of at compile time. Any struct
2986 containing an unsized type is also unsized.
2988 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
2990 Example of erroneous code:
2992 ```compile_fail,E0374
2993 #![feature(coerce_unsized)]
2994 use std::ops::CoerceUnsized;
2996 struct Foo<T: ?Sized> {
3000 // error: Struct `Foo` has no unsized fields that need `CoerceUnsized`.
3001 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T>
3002 where T: CoerceUnsized<U> {}
3005 `CoerceUnsized` is used to coerce one struct containing an unsized type
3006 into another struct containing a different unsized type. If the struct
3007 doesn't have any fields of unsized types then you don't need explicit
3008 coercion to get the types you want. To fix this you can either
3009 not try to implement `CoerceUnsized` or you can add a field that is
3010 unsized to the struct.
3015 #![feature(coerce_unsized)]
3016 use std::ops::CoerceUnsized;
3018 // We don't need to impl `CoerceUnsized` here.
3023 // We add the unsized type field to the struct.
3024 struct Bar<T: ?Sized> {
3029 // The struct has an unsized field so we can implement
3030 // `CoerceUnsized` for it.
3031 impl<T, U> CoerceUnsized<Bar<U>> for Bar<T>
3032 where T: CoerceUnsized<U> {}
3035 Note that `CoerceUnsized` is mainly used by smart pointers like `Box`, `Rc`
3036 and `Arc` to be able to mark that they can coerce unsized types that they
3041 A struct with more than one field containing an unsized type cannot implement
3042 `CoerceUnsized`. This only occurs when you are trying to coerce one of the
3043 types in your struct to another type in the struct. In this case we try to
3044 impl `CoerceUnsized` from `T` to `U` which are both types that the struct
3045 takes. An [unsized type][1] is any type that the compiler doesn't know the
3046 length or alignment of at compile time. Any struct containing an unsized type
3049 Example of erroneous code:
3051 ```compile_fail,E0375
3052 #![feature(coerce_unsized)]
3053 use std::ops::CoerceUnsized;
3055 struct Foo<T: ?Sized, U: ?Sized> {
3061 // error: Struct `Foo` has more than one unsized field.
3062 impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
3065 `CoerceUnsized` only allows for coercion from a structure with a single
3066 unsized type field to another struct with a single unsized type field.
3067 In fact Rust only allows for a struct to have one unsized type in a struct
3068 and that unsized type must be the last field in the struct. So having two
3069 unsized types in a single struct is not allowed by the compiler. To fix this
3070 use only one field containing an unsized type in the struct and then use
3071 multiple structs to manage each unsized type field you need.
3076 #![feature(coerce_unsized)]
3077 use std::ops::CoerceUnsized;
3079 struct Foo<T: ?Sized> {
3084 impl <T, U> CoerceUnsized<Foo<U>> for Foo<T>
3085 where T: CoerceUnsized<U> {}
3087 fn coerce_foo<T: CoerceUnsized<U>, U>(t: T) -> Foo<U> {
3088 Foo { a: 12i32, b: t } // we use coercion to get the `Foo<U>` type we need
3092 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3096 The type you are trying to impl `CoerceUnsized` for is not a struct.
3097 `CoerceUnsized` can only be implemented for a struct. Unsized types are
3098 already able to be coerced without an implementation of `CoerceUnsized`
3099 whereas a struct containing an unsized type needs to know the unsized type
3100 field it's containing is able to be coerced. An [unsized type][1]
3101 is any type that the compiler doesn't know the length or alignment of at
3102 compile time. Any struct containing an unsized type is also unsized.
3104 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3106 Example of erroneous code:
3108 ```compile_fail,E0376
3109 #![feature(coerce_unsized)]
3110 use std::ops::CoerceUnsized;
3112 struct Foo<T: ?Sized> {
3116 // error: The type `U` is not a struct
3117 impl<T, U> CoerceUnsized<U> for Foo<T> {}
3120 The `CoerceUnsized` trait takes a struct type. Make sure the type you are
3121 providing to `CoerceUnsized` is a struct with only the last field containing an
3127 #![feature(coerce_unsized)]
3128 use std::ops::CoerceUnsized;
3134 // The `Foo<U>` is a struct so `CoerceUnsized` can be implemented
3135 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
3138 Note that in Rust, structs can only contain an unsized type if the field
3139 containing the unsized type is the last and only unsized type field in the
3144 The `DispatchFromDyn` trait currently can only be implemented for
3145 builtin pointer types and structs that are newtype wrappers around them
3146 — that is, the struct must have only one field (except for`PhantomData`),
3147 and that field must itself implement `DispatchFromDyn`.
3152 #![feature(dispatch_from_dyn, unsize)]
3155 ops::DispatchFromDyn,
3158 struct Ptr<T: ?Sized>(*const T);
3160 impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
3167 #![feature(dispatch_from_dyn)]
3169 ops::DispatchFromDyn,
3170 marker::PhantomData,
3175 _phantom: PhantomData<()>,
3178 impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
3180 T: DispatchFromDyn<U>,
3184 Example of illegal `DispatchFromDyn` implementation
3185 (illegal because of extra field)
3187 ```compile-fail,E0378
3188 #![feature(dispatch_from_dyn)]
3189 use std::ops::DispatchFromDyn;
3191 struct WrapperExtraField<T> {
3196 impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
3198 T: DispatchFromDyn<U>,
3204 You tried to implement methods for a primitive type. Erroneous code example:
3206 ```compile_fail,E0390
3212 // error: only a single inherent implementation marked with
3213 // `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive
3216 This isn't allowed, but using a trait to implement a method is a good solution.
3228 impl Bar for *mut Foo {
3235 This error indicates that a type or lifetime parameter has been declared
3236 but not actually used. Here is an example that demonstrates the error:
3238 ```compile_fail,E0392
3244 If the type parameter was included by mistake, this error can be fixed
3245 by simply removing the type parameter, as shown below:
3253 Alternatively, if the type parameter was intentionally inserted, it must be
3254 used. A simple fix is shown below:
3262 This error may also commonly be found when working with unsafe code. For
3263 example, when using raw pointers one may wish to specify the lifetime for
3264 which the pointed-at data is valid. An initial attempt (below) causes this
3267 ```compile_fail,E0392
3273 We want to express the constraint that Foo should not outlive `'a`, because
3274 the data pointed to by `T` is only valid for that lifetime. The problem is
3275 that there are no actual uses of `'a`. It's possible to work around this
3276 by adding a PhantomData type to the struct, using it to tell the compiler
3277 to act as if the struct contained a borrowed reference `&'a T`:
3280 use std::marker::PhantomData;
3282 struct Foo<'a, T: 'a> {
3284 phantom: PhantomData<&'a T>
3288 [PhantomData] can also be used to express information about unused type
3291 [PhantomData]: https://doc.rust-lang.org/std/marker/struct.PhantomData.html
3295 A type parameter which references `Self` in its default value was not specified.
3296 Example of erroneous code:
3298 ```compile_fail,E0393
3301 fn together_we_will_rule_the_galaxy(son: &A) {}
3302 // error: the type parameter `T` must be explicitly specified in an
3303 // object type because its default value `Self` references the
3307 A trait object is defined over a single, fully-defined trait. With a regular
3308 default parameter, this parameter can just be substituted in. However, if the
3309 default parameter is `Self`, the trait changes for each concrete type; i.e.
3310 `i32` will be expected to implement `A<i32>`, `bool` will be expected to
3311 implement `A<bool>`, etc... These types will not share an implementation of a
3312 fully-defined trait; instead they share implementations of a trait with
3313 different parameters substituted in for each implementation. This is
3314 irreconcilable with what we need to make a trait object work, and is thus
3315 disallowed. Making the trait concrete by explicitly specifying the value of the
3316 defaulted parameter will fix this issue. Fixed example:
3321 fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
3326 You implemented a trait, overriding one or more of its associated types but did
3327 not reimplement its default methods.
3329 Example of erroneous code:
3331 ```compile_fail,E0399
3332 #![feature(associated_type_defaults)]
3340 // error - the following trait items need to be reimplemented as
3341 // `Assoc` was overridden: `bar`
3346 To fix this, add an implementation for each default method from the trait:
3349 #![feature(associated_type_defaults)]
3358 fn bar(&self) {} // ok!
3364 The functional record update syntax is only allowed for structs. (Struct-like
3365 enum variants don't qualify, for example.)
3367 Erroneous code example:
3369 ```compile_fail,E0436
3370 enum PublicationFrequency {
3372 SemiMonthly { days: (u8, u8), annual_special: bool },
3375 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3376 -> PublicationFrequency {
3377 match competitor_frequency {
3378 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3379 days: (1, 15), annual_special: false
3381 c @ PublicationFrequency::SemiMonthly{ .. } =>
3382 PublicationFrequency::SemiMonthly {
3383 annual_special: true, ..c // error: functional record update
3384 // syntax requires a struct
3390 Rewrite the expression without functional record update syntax:
3393 enum PublicationFrequency {
3395 SemiMonthly { days: (u8, u8), annual_special: bool },
3398 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3399 -> PublicationFrequency {
3400 match competitor_frequency {
3401 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3402 days: (1, 15), annual_special: false
3404 PublicationFrequency::SemiMonthly{ days, .. } =>
3405 PublicationFrequency::SemiMonthly {
3406 days, annual_special: true // ok!
3414 The length of the platform-intrinsic function `simd_shuffle`
3415 wasn't specified. Erroneous code example:
3417 ```compile_fail,E0439
3418 #![feature(platform_intrinsics)]
3420 extern "platform-intrinsic" {
3421 fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3422 // error: invalid `simd_shuffle`, needs length: `simd_shuffle`
3426 The `simd_shuffle` function needs the length of the array passed as
3427 last parameter in its name. Example:
3430 #![feature(platform_intrinsics)]
3432 extern "platform-intrinsic" {
3433 fn simd_shuffle8<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3439 The `typeof` keyword is currently reserved but unimplemented.
3440 Erroneous code example:
3442 ```compile_fail,E0516
3444 let x: typeof(92) = 92;
3448 Try using type inference instead. Example:
3458 A non-default implementation was already made on this type so it cannot be
3459 specialized further. Erroneous code example:
3461 ```compile_fail,E0520
3462 #![feature(specialization)]
3469 impl<T> SpaceLlama for T {
3470 default fn fly(&self) {}
3474 // applies to all `Clone` T and overrides the previous impl
3475 impl<T: Clone> SpaceLlama for T {
3479 // since `i32` is clone, this conflicts with the previous implementation
3480 impl SpaceLlama for i32 {
3481 default fn fly(&self) {}
3482 // error: item `fly` is provided by an `impl` that specializes
3483 // another, but the item in the parent `impl` is not marked
3484 // `default` and so it cannot be specialized.
3488 Specialization only allows you to override `default` functions in
3491 To fix this error, you need to mark all the parent implementations as default.
3495 #![feature(specialization)]
3502 impl<T> SpaceLlama for T {
3503 default fn fly(&self) {} // This is a parent implementation.
3506 // applies to all `Clone` T; overrides the previous impl
3507 impl<T: Clone> SpaceLlama for T {
3508 default fn fly(&self) {} // This is a parent implementation but was
3509 // previously not a default one, causing the error
3512 // applies to i32, overrides the previous two impls
3513 impl SpaceLlama for i32 {
3514 fn fly(&self) {} // And now that's ok!
3520 The number of elements in an array or slice pattern differed from the number of
3521 elements in the array being matched.
3523 Example of erroneous code:
3525 ```compile_fail,E0527
3526 let r = &[1, 2, 3, 4];
3528 &[a, b] => { // error: pattern requires 2 elements but array
3530 println!("a={}, b={}", a, b);
3535 Ensure that the pattern is consistent with the size of the matched
3536 array. Additional elements can be matched with `..`:
3539 #![feature(slice_patterns)]
3541 let r = &[1, 2, 3, 4];
3543 &[a, b, ..] => { // ok!
3544 println!("a={}, b={}", a, b);
3551 An array or slice pattern required more elements than were present in the
3554 Example of erroneous code:
3556 ```compile_fail,E0528
3557 #![feature(slice_patterns)]
3561 &[a, b, c, rest @ ..] => { // error: pattern requires at least 3
3562 // elements but array has 2
3563 println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3568 Ensure that the matched array has at least as many elements as the pattern
3569 requires. You can match an arbitrary number of remaining elements with `..`:
3572 #![feature(slice_patterns)]
3574 let r = &[1, 2, 3, 4, 5];
3576 &[a, b, c, rest @ ..] => { // ok!
3577 // prints `a=1, b=2, c=3 rest=[4, 5]`
3578 println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3585 An array or slice pattern was matched against some other type.
3587 Example of erroneous code:
3589 ```compile_fail,E0529
3592 [a, b] => { // error: expected an array or slice, found `f32`
3593 println!("a={}, b={}", a, b);
3598 Ensure that the pattern and the expression being matched on are of consistent
3605 println!("a={}, b={}", a, b);
3612 An item which isn't a unit struct, a variant, nor a constant has been used as a
3615 Erroneous code example:
3617 ```compile_fail,E0533
3621 fn turtle(&self) -> u32 { 0 }
3625 Tortoise::turtle => {} // Error!
3628 if let Tortoise::turtle = 0u32 {} // Same error!
3631 If you want to match against a value returned by a method, you need to bind the
3638 fn turtle(&self) -> u32 { 0 }
3642 x if x == Tortoise.turtle() => {} // Bound into `x` then we compare it!
3649 The `inline` attribute was malformed.
3651 Erroneous code example:
3653 ```ignore (compile_fail not working here; see Issue #43707)
3654 #[inline()] // error: expected one argument
3655 pub fn something() {}
3660 The parenthesized `inline` attribute requires the parameter to be specified:
3674 Alternatively, a paren-less version of the attribute may be used to hint the
3675 compiler about inlining opportunity:
3682 For more information about the inline attribute, read:
3683 https://doc.rust-lang.org/reference.html#inline-attributes
3687 An unknown argument was given to the `inline` attribute.
3689 Erroneous code example:
3691 ```ignore (compile_fail not working here; see Issue #43707)
3692 #[inline(unknown)] // error: invalid argument
3693 pub fn something() {}
3698 The `inline` attribute only supports two arguments:
3703 All other arguments given to the `inline` attribute will return this error.
3707 #[inline(never)] // ok!
3708 pub fn something() {}
3713 For more information about the inline attribute, https:
3714 read://doc.rust-lang.org/reference.html#inline-attributes
3718 An unknown field was specified into an enum's structure variant.
3720 Erroneous code example:
3722 ```compile_fail,E0559
3727 let s = Field::Fool { joke: 0 };
3728 // error: struct variant `Field::Fool` has no field named `joke`
3731 Verify you didn't misspell the field's name or that the field exists. Example:
3738 let s = Field::Fool { joke: 0 }; // ok!
3743 An unknown field was specified into a structure.
3745 Erroneous code example:
3747 ```compile_fail,E0560
3752 let s = Simba { mother: 1, father: 0 };
3753 // error: structure `Simba` has no field named `father`
3756 Verify you didn't misspell the field's name or that the field exists. Example:
3764 let s = Simba { mother: 1, father: 0 }; // ok!
3769 If an impl has a generic parameter with the `#[may_dangle]` attribute, then
3770 that impl must be declared as an `unsafe impl.
3772 Erroneous code example:
3774 ```compile_fail,E0569
3775 #![feature(dropck_eyepatch)]
3778 impl<#[may_dangle] X> Drop for Foo<X> {
3779 fn drop(&mut self) { }
3783 In this example, we are asserting that the destructor for `Foo` will not
3784 access any data of type `X`, and require this assertion to be true for
3785 overall safety in our program. The compiler does not currently attempt to
3786 verify this assertion; therefore we must tag this `impl` as unsafe.
3790 The requested ABI is unsupported by the current target.
3792 The rust compiler maintains for each target a blacklist of ABIs unsupported on
3793 that target. If an ABI is present in such a list this usually means that the
3794 target / ABI combination is currently unsupported by llvm.
3796 If necessary, you can circumvent this check using custom target specifications.
3800 A return statement was found outside of a function body.
3802 Erroneous code example:
3804 ```compile_fail,E0572
3805 const FOO: u32 = return 0; // error: return statement outside of function body
3810 To fix this issue, just remove the return keyword or move the expression into a
3816 fn some_fn() -> u32 {
3827 In a `fn` type, a lifetime appears only in the return type,
3828 and not in the arguments types.
3830 Erroneous code example:
3832 ```compile_fail,E0581
3834 // Here, `'a` appears only in the return type:
3835 let x: for<'a> fn() -> &'a i32;
3839 To fix this issue, either use the lifetime in the arguments, or use
3844 // Here, `'a` appears only in the return type:
3845 let x: for<'a> fn(&'a i32) -> &'a i32;
3846 let y: fn() -> &'static i32;
3850 Note: The examples above used to be (erroneously) accepted by the
3851 compiler, but this was since corrected. See [issue #33685] for more
3854 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3858 A lifetime appears only in an associated-type binding,
3859 and not in the input types to the trait.
3861 Erroneous code example:
3863 ```compile_fail,E0582
3865 // No type can satisfy this requirement, since `'a` does not
3866 // appear in any of the input types (here, `i32`):
3867 where F: for<'a> Fn(i32) -> Option<&'a i32>
3874 To fix this issue, either use the lifetime in the inputs, or use
3878 fn bar<F, G>(t: F, u: G)
3879 where F: for<'a> Fn(&'a i32) -> Option<&'a i32>,
3880 G: Fn(i32) -> Option<&'static i32>,
3887 Note: The examples above used to be (erroneously) accepted by the
3888 compiler, but this was since corrected. See [issue #33685] for more
3891 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3895 A type with `packed` representation hint has a field with `align`
3896 representation hint.
3898 Erroneous code example:
3900 ```compile_fail,E0588
3902 struct Aligned(i32);
3904 #[repr(packed)] // error!
3905 struct Packed(Aligned);
3908 Just like you cannot have both `align` and `packed` representation hints on a
3909 same type, a `packed` type cannot contain another type with the `align`
3910 representation hint. However, you can do the opposite:
3916 #[repr(align(16))] // ok!
3917 struct Aligned(Packed);
3922 This error occurs when you defined methods or associated functions with same
3925 Erroneous code example:
3927 ```compile_fail,E0592
3931 fn bar() {} // previous definition here
3935 fn bar() {} // duplicate definition here
3939 A similar error is E0201. The difference is whether there is one declaration
3940 block or not. To avoid this error, you must give each `fn` a unique name.
3950 fn baz() {} // define with different name
3956 This error occurs when a method is used on a type which doesn't implement it:
3958 Erroneous code example:
3960 ```compile_fail,E0599
3964 x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
3965 // in the current scope
3970 An unary operator was used on a type which doesn't implement it.
3972 Example of erroneous code:
3974 ```compile_fail,E0600
3980 !Question::Yes; // error: cannot apply unary operator `!` to type `Question`
3983 In this case, `Question` would need to implement the `std::ops::Not` trait in
3984 order to be able to use `!` on it. Let's implement it:
3994 // We implement the `Not` trait on the enum.
3995 impl Not for Question {
3998 fn not(self) -> bool {
4000 Question::Yes => false, // If the `Answer` is `Yes`, then it
4002 Question::No => true, // And here we do the opposite.
4007 assert_eq!(!Question::Yes, false);
4008 assert_eq!(!Question::No, true);
4013 An attempt to index into a type which doesn't implement the `std::ops::Index`
4014 trait was performed.
4016 Erroneous code example:
4018 ```compile_fail,E0608
4019 0u8[2]; // error: cannot index into a value of type `u8`
4022 To be able to index into a type it needs to implement the `std::ops::Index`
4026 let v: Vec<u8> = vec![0, 1, 2, 3];
4028 // The `Vec` type implements the `Index` trait so you can do:
4029 println!("{}", v[2]);
4034 A cast to `char` was attempted on a type other than `u8`.
4036 Erroneous code example:
4038 ```compile_fail,E0604
4039 0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
4042 As the error message indicates, only `u8` can be cast into `char`. Example:
4045 let c = 86u8 as char; // ok!
4049 For more information about casts, take a look at the Type cast section in
4050 [The Reference Book][1].
4052 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4056 An invalid cast was attempted.
4058 Erroneous code examples:
4060 ```compile_fail,E0605
4062 x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
4066 let v = core::ptr::null::<u8>(); // So here, `v` is a `*const u8`.
4067 v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
4070 Only primitive types can be cast into each other. Examples:
4076 let v = core::ptr::null::<u8>();
4077 v as *const i8; // ok!
4080 For more information about casts, take a look at the Type cast section in
4081 [The Reference Book][1].
4083 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4087 An incompatible cast was attempted.
4089 Erroneous code example:
4091 ```compile_fail,E0606
4092 let x = &0u8; // Here, `x` is a `&u8`.
4093 let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid
4096 When casting, keep in mind that only primitive types can be cast into each
4101 let y: u32 = *x as u32; // We dereference it first and then cast it.
4104 For more information about casts, take a look at the Type cast section in
4105 [The Reference Book][1].
4107 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4111 A cast between a thin and a fat pointer was attempted.
4113 Erroneous code example:
4115 ```compile_fail,E0607
4116 let v = core::ptr::null::<u8>();
4120 First: what are thin and fat pointers?
4122 Thin pointers are "simple" pointers: they are purely a reference to a memory
4125 Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
4126 DST don't have a statically known size, therefore they can only exist behind
4127 some kind of pointers that contain additional information. Slices and trait
4128 objects are DSTs. In the case of slices, the additional information the fat
4129 pointer holds is their size.
4131 To fix this error, don't try to cast directly between thin and fat pointers.
4133 For more information about casts, take a look at the Type cast section in
4134 [The Reference Book][1].
4136 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4140 Attempted to access a non-existent field in a struct.
4142 Erroneous code example:
4144 ```compile_fail,E0609
4145 struct StructWithFields {
4149 let s = StructWithFields { x: 0 };
4150 println!("{}", s.foo); // error: no field `foo` on type `StructWithFields`
4153 To fix this error, check that you didn't misspell the field's name or that the
4154 field actually exists. Example:
4157 struct StructWithFields {
4161 let s = StructWithFields { x: 0 };
4162 println!("{}", s.x); // ok!
4167 Attempted to access a field on a primitive type.
4169 Erroneous code example:
4171 ```compile_fail,E0610
4173 println!("{}", x.foo); // error: `{integer}` is a primitive type, therefore
4174 // doesn't have fields
4177 Primitive types are the most basic types available in Rust and don't have
4178 fields. To access data via named fields, struct types are used. Example:
4181 // We declare struct called `Foo` containing two fields:
4187 // We create an instance of this struct:
4188 let variable = Foo { x: 0, y: -12 };
4189 // And we can now access its fields:
4190 println!("x: {}, y: {}", variable.x, variable.y);
4193 For more information about primitives and structs, take a look at The Book:
4194 https://doc.rust-lang.org/book/ch03-02-data-types.html
4195 https://doc.rust-lang.org/book/ch05-00-structs.html
4199 Attempted to dereference a variable which cannot be dereferenced.
4201 Erroneous code example:
4203 ```compile_fail,E0614
4205 *y; // error: type `u32` cannot be dereferenced
4208 Only types implementing `std::ops::Deref` can be dereferenced (such as `&T`).
4214 // So here, `x` is a `&u32`, so we can dereference it:
4220 Attempted to access a method like a field.
4222 Erroneous code example:
4224 ```compile_fail,E0615
4233 let f = Foo { x: 0 };
4234 f.method; // error: attempted to take value of method `method` on type `Foo`
4237 If you want to use a method, add `()` after it:
4240 # struct Foo { x: u32 }
4241 # impl Foo { fn method(&self) {} }
4242 # let f = Foo { x: 0 };
4246 However, if you wanted to access a field of a struct check that the field name
4247 is spelled correctly. Example:
4250 # struct Foo { x: u32 }
4251 # impl Foo { fn method(&self) {} }
4252 # let f = Foo { x: 0 };
4253 println!("{}", f.x);
4258 Attempted to access a private field on a struct.
4260 Erroneous code example:
4262 ```compile_fail,E0616
4265 x: u32, // So `x` is private in here.
4269 pub fn new() -> Foo { Foo { x: 0 } }
4273 let f = some_module::Foo::new();
4274 println!("{}", f.x); // error: field `x` of struct `some_module::Foo` is private
4277 If you want to access this field, you have two options:
4279 1) Set the field public:
4284 pub x: u32, // `x` is now public.
4288 pub fn new() -> Foo { Foo { x: 0 } }
4292 let f = some_module::Foo::new();
4293 println!("{}", f.x); // ok!
4296 2) Add a getter function:
4301 x: u32, // So `x` is still private in here.
4305 pub fn new() -> Foo { Foo { x: 0 } }
4307 // We create the getter function here:
4308 pub fn get_x(&self) -> &u32 { &self.x }
4312 let f = some_module::Foo::new();
4313 println!("{}", f.get_x()); // ok!
4318 Attempted to pass an invalid type of variable into a variadic function.
4320 Erroneous code example:
4322 ```compile_fail,E0617
4324 fn printf(c: *const i8, ...);
4328 printf(::std::ptr::null(), 0f32);
4329 // error: cannot pass an `f32` to variadic function, cast to `c_double`
4333 Certain Rust types must be cast before passing them to a variadic function,
4334 because of arcane ABI rules dictated by the C standard. To fix the error,
4335 cast the value to the type specified by the error message (which you may need
4336 to import from `std::os::raw`).
4340 Attempted to call something which isn't a function nor a method.
4342 Erroneous code examples:
4344 ```compile_fail,E0618
4349 X::Entry(); // error: expected function, found `X::Entry`
4353 x(); // error: expected function, found `i32`
4356 Only functions and methods can be called using `()`. Example:
4359 // We declare a function:
4360 fn i_am_a_function() {}
4368 #### Note: this error code is no longer emitted by the compiler.
4369 The type-checker needed to know the type of an expression, but that type had not
4372 Erroneous code example:
4378 // Here, the type of `v` is not (yet) known, so we
4379 // cannot resolve this method call:
4380 v.to_uppercase(); // error: the type of this value must be known in
4387 Type inference typically proceeds from the top of the function to the bottom,
4388 figuring out types as it goes. In some cases -- notably method calls and
4389 overloadable operators like `*` -- the type checker may not have enough
4390 information *yet* to make progress. This can be true even if the rest of the
4391 function provides enough context (because the type-checker hasn't looked that
4392 far ahead yet). In this case, type annotations can be used to help it along.
4394 To fix this error, just specify the type of the variable. Example:
4397 let mut x: Vec<String> = vec![]; // We precise the type of the vec elements.
4400 v.to_uppercase(); // Since rustc now knows the type of the vec elements,
4401 // we can use `v`'s methods.
4409 A cast to an unsized type was attempted.
4411 Erroneous code example:
4413 ```compile_fail,E0620
4414 let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]`
4418 In Rust, some types don't have a known size at compile-time. For example, in a
4419 slice type like `[u32]`, the number of elements is not known at compile-time and
4420 hence the overall size cannot be computed. As a result, such types can only be
4421 manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type
4422 (e.g., `Box` or `Rc`). Try casting to a reference instead:
4425 let x = &[1_usize, 2] as &[usize]; // ok!
4430 An intrinsic was declared without being a function.
4432 Erroneous code example:
4434 ```compile_fail,E0622
4435 #![feature(intrinsics)]
4436 extern "rust-intrinsic" {
4437 pub static breakpoint : unsafe extern "rust-intrinsic" fn();
4438 // error: intrinsic must be a function
4441 fn main() { unsafe { breakpoint(); } }
4444 An intrinsic is a function available for use in a given programming language
4445 whose implementation is handled specially by the compiler. In order to fix this
4446 error, just declare a function.
4450 A private item was used outside of its scope.
4452 Erroneous code example:
4454 ```compile_fail,E0624
4463 let foo = inner::Foo;
4464 foo.method(); // error: method `method` is private
4467 Two possibilities are available to solve this issue:
4469 1. Only use the item in the scope it has been defined:
4479 pub fn call_method(foo: &Foo) { // We create a public function.
4480 foo.method(); // Which calls the item.
4484 let foo = inner::Foo;
4485 inner::call_method(&foo); // And since the function is public, we can call the
4486 // method through it.
4489 2. Make the item public:
4496 pub fn method(&self) {} // It's now public.
4500 let foo = inner::Foo;
4501 foo.method(); // Ok!
4506 This error indicates that the struct, enum or enum variant must be matched
4507 non-exhaustively as it has been marked as `non_exhaustive`.
4509 When applied within a crate, downstream users of the crate will need to use the
4510 `_` pattern when matching enums and use the `..` pattern when matching structs.
4511 Downstream crates cannot match against non-exhaustive enum variants.
4513 For example, in the below example, since the enum is marked as
4514 `non_exhaustive`, it is required that downstream crates match non-exhaustively
4517 ```rust,ignore (pseudo-Rust)
4518 use std::error::Error as StdError;
4520 #[non_exhaustive] pub enum Error {
4525 impl StdError for Error {
4526 fn description(&self) -> &str {
4527 // This will not error, despite being marked as non_exhaustive, as this
4528 // enum is defined within the current crate, it can be matched
4531 Message(ref s) => s,
4532 Other => "other or unknown error",
4538 An example of matching non-exhaustively on the above enum is provided below:
4540 ```rust,ignore (pseudo-Rust)
4543 // This will not error as the non_exhaustive Error enum has been matched with a
4546 Message(ref s) => ...,
4552 Similarly, for structs, match with `..` to avoid this error.
4556 This error indicates that the struct, enum or enum variant cannot be
4557 instantiated from outside of the defining crate as it has been marked
4558 as `non_exhaustive` and as such more fields/variants may be added in
4559 future that could cause adverse side effects for this code.
4561 It is recommended that you look for a `new` function or equivalent in the
4562 crate's documentation.
4566 This error indicates that there is a mismatch between generic parameters and
4567 impl Trait parameters in a trait declaration versus its impl.
4569 ```compile_fail,E0643
4571 fn foo(&self, _: &impl Iterator);
4574 fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible
4575 // signature for trait
4581 It is not possible to define `main` with a where clause.
4582 Erroneous code example:
4584 ```compile_fail,E0646
4585 fn main() where i32: Copy { // error: main function is not allowed to have
4592 It is not possible to define `start` with a where clause.
4593 Erroneous code example:
4595 ```compile_fail,E0647
4599 fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
4600 //^ error: start function is not allowed to have a where clause
4607 `export_name` attributes may not contain null characters (`\0`).
4609 ```compile_fail,E0648
4610 #[export_name="\0foo"] // error: `export_name` may not contain null characters
4616 This error indicates that the numeric value for the method being passed exists
4617 but the type of the numeric value or binding could not be identified.
4619 The error happens on numeric literals:
4621 ```compile_fail,E0689
4625 and on numeric bindings without an identified concrete type:
4627 ```compile_fail,E0689
4629 x.neg(); // same error as above
4632 Because of this, you must give the numeric literal or binding a type:
4637 let _ = 2.0_f32.neg();
4640 let _ = (2.0 as f32).neg();
4645 A struct with the representation hint `repr(transparent)` had zero or more than
4646 one fields that were not guaranteed to be zero-sized.
4648 Erroneous code example:
4650 ```compile_fail,E0690
4651 #[repr(transparent)]
4652 struct LengthWithUnit<U> { // error: transparent struct needs exactly one
4653 value: f32, // non-zero-sized field, but has 2
4658 Because transparent structs are represented exactly like one of their fields at
4659 run time, said field must be uniquely determined. If there is no field, or if
4660 there are multiple fields, it is not clear how the struct should be represented.
4661 Note that fields of zero-typed types (e.g., `PhantomData`) can also exist
4662 alongside the field that contains the actual data, they do not count for this
4663 error. When generic types are involved (as in the above example), an error is
4664 reported because the type parameter could be non-zero-sized.
4666 To combine `repr(transparent)` with type parameters, `PhantomData` may be
4670 use std::marker::PhantomData;
4672 #[repr(transparent)]
4673 struct LengthWithUnit<U> {
4675 unit: PhantomData<U>,
4681 A struct, enum, or union with the `repr(transparent)` representation hint
4682 contains a zero-sized field that requires non-trivial alignment.
4684 Erroneous code example:
4686 ```compile_fail,E0691
4687 #![feature(repr_align)]
4690 struct ForceAlign32;
4692 #[repr(transparent)]
4693 struct Wrapper(f32, ForceAlign32); // error: zero-sized field in transparent
4694 // struct has alignment larger than 1
4697 A transparent struct, enum, or union is supposed to be represented exactly like
4698 the piece of data it contains. Zero-sized fields with different alignment
4699 requirements potentially conflict with this property. In the example above,
4700 `Wrapper` would have to be aligned to 32 bytes even though `f32` has a smaller
4701 alignment requirement.
4703 Consider removing the over-aligned zero-sized field:
4706 #[repr(transparent)]
4707 struct Wrapper(f32);
4710 Alternatively, `PhantomData<T>` has alignment 1 for all `T`, so you can use it
4711 if you need to keep the field for some reason:
4714 #![feature(repr_align)]
4716 use std::marker::PhantomData;
4719 struct ForceAlign32;
4721 #[repr(transparent)]
4722 struct Wrapper(f32, PhantomData<ForceAlign32>);
4725 Note that empty arrays `[T; 0]` have the same alignment requirement as the
4726 element type `T`. Also note that the error is conservatively reported even when
4727 the alignment of the zero-sized type is less than or equal to the data field's
4732 A method was called on a raw pointer whose inner type wasn't completely known.
4734 For example, you may have done something like:
4737 # #![deny(warnings)]
4739 let bar = foo as *const _;
4745 Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
4746 specify a type for the pointer (preferably something that makes sense for the
4747 thing you're pointing to):
4751 let bar = foo as *const i32;
4757 Even though `is_null()` exists as a method on any raw pointer, Rust shows this
4758 error because Rust allows for `self` to have arbitrary types (behind the
4759 arbitrary_self_types feature flag).
4761 This means that someone can specify such a function:
4763 ```ignore (cannot-doctest-feature-doesnt-exist-yet)
4765 fn is_null(self: *const Self) -> bool {
4766 // do something else
4771 and now when you call `.is_null()` on a raw pointer to `Foo`, there's ambiguity.
4773 Given that we don't know what type the pointer is, and there's potential
4774 ambiguity for some types, we disallow calling methods on raw pointers when
4775 the type is unknown.
4779 A `#[marker]` trait contained an associated item.
4781 The items of marker traits cannot be overridden, so there's no need to have them
4782 when they cannot be changed per-type anyway. If you wanted them for ergonomic
4783 reasons, consider making an extension trait instead.
4787 An `impl` for a `#[marker]` trait tried to override an associated item.
4789 Because marker traits are allowed to have multiple implementations for the same
4790 type, it's not allowed to override anything in those implementations, as it
4791 would be ambiguous which override should actually be used.
4796 An `impl Trait` type expands to a recursive type.
4798 An `impl Trait` type must be expandable to a concrete type that contains no
4799 `impl Trait` types. For example the following example tries to create an
4800 `impl Trait` type `T` that is equal to `[T, T]`:
4802 ```compile_fail,E0720
4803 fn make_recursive_type() -> impl Sized {
4804 [make_recursive_type(), make_recursive_type()]
4810 An array without a fixed length was pattern-matched.
4812 Example of erroneous code:
4814 ```compile_fail,E0730
4815 #![feature(const_generics)]
4817 fn is_123<const N: usize>(x: [u32; N]) -> bool {
4819 [1, 2, 3] => true, // error: cannot pattern-match on an
4820 // array without a fixed length
4826 Ensure that the pattern is consistent with the size of the matched
4827 array. Additional elements can be matched with `..`:
4830 #![feature(slice_patterns)]
4832 let r = &[1, 2, 3, 4];
4834 &[a, b, ..] => { // ok!
4835 println!("a={}, b={}", a, b);
4842 An enum with the representation hint `repr(transparent)` had zero or more than
4845 Erroneous code example:
4847 ```compile_fail,E0731
4848 #[repr(transparent)]
4849 enum Status { // error: transparent enum needs exactly one variant, but has 2
4855 Because transparent enums are represented exactly like one of their variants at
4856 run time, said variant must be uniquely determined. If there is no variant, or
4857 if there are multiple variants, it is not clear how the enum should be
4862 An `enum` with a discriminant must specify a `#[repr(inttype)]`.
4864 A `#[repr(inttype)]` must be provided on an `enum` if it has a non-unit
4865 variant with a discriminant, or where there are both unit variants with
4866 discriminants and non-unit variants. This restriction ensures that there
4867 is a well-defined way to extract a variant's discriminant from a value;
4871 #![feature(arbitrary_enum_discriminant)]
4883 fn discriminant(v : &Enum) -> u8 {
4884 unsafe { *(v as *const Enum as *const u8) }
4887 assert_eq!(3, discriminant(&Enum::Unit));
4888 assert_eq!(2, discriminant(&Enum::Tuple(5)));
4889 assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
4894 A `union` cannot have fields with destructors.
4898 Recursion in an `async fn` requires boxing. For example, this will not compile:
4900 ```edition2018,compile_fail,E0733
4901 async fn foo(n: usize) {
4908 To achieve async recursion, the `async fn` needs to be desugared
4909 such that the `Future` is explicit in the return type:
4911 ```edition2018,compile_fail,E0720
4912 use std::future::Future;
4913 fn foo_desugared(n: usize) -> impl Future<Output = ()> {
4916 foo_desugared(n - 1).await;
4922 Finally, the future is wrapped in a pinned box:
4925 use std::future::Future;
4927 fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
4928 Box::pin(async move {
4930 foo_recursive(n - 1).await;
4936 The `Box<...>` ensures that the result is of known size,
4937 and the pin is required to keep it in the same place in memory.
4941 #[track_caller] requires functions to have the "Rust" ABI for implicitly
4942 receiving caller location. See [RFC 2091] for details on this and other
4945 Erroneous code example:
4947 ```compile_fail,E0737
4948 #![feature(track_caller)]
4951 extern "C" fn foo() {}
4954 [RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
4958 #[track_caller] cannot be used in traits yet. This is due to limitations in the
4959 compiler which are likely to be temporary. See [RFC 2091] for details on this
4960 and other restrictions.
4962 Erroneous example with a trait method implementation:
4964 ```compile_fail,E0738
4965 #![feature(track_caller)]
4977 Erroneous example with a blanket trait method implementation:
4979 ```compile_fail,E0738
4980 #![feature(track_caller)]
4989 Erroneous example with a trait method declaration:
4991 ```compile_fail,E0738
4992 #![feature(track_caller)]
5002 Note that while the compiler may be able to support the attribute in traits in
5003 the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
5005 [RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
5009 Only `structural_match` types (that is, types that derive `PartialEq` and `Eq`)
5010 may be used as the types of const generic parameters.
5012 ```compile_fail,E0741
5013 #![feature(const_generics)]
5017 struct B<const X: A>; // error!
5020 To fix this example, we derive `PartialEq` and `Eq`.
5023 #![feature(const_generics)]
5025 #[derive(PartialEq, Eq)]
5028 struct B<const X: A>; // ok!
5033 // E0035, merged into E0087/E0089
5034 // E0036, merged into E0087/E0089
5040 // E0122, // bounds in type aliases are ignored, turned into proper lint
5045 // E0159, // use of trait `{}` as struct constructor
5046 // E0163, // merged into E0071
5049 // E0172, // non-trait found in a type sum, moved to resolve
5050 // E0173, // manual implementations of unboxed closure traits are experimental
5052 // E0182, // merged into E0229
5054 // E0187, // cannot infer the kind of the closure
5055 // E0188, // can not cast an immutable reference to a mutable pointer
5056 // E0189, // deprecated: can only cast a boxed pointer to a boxed object
5057 // E0190, // deprecated: can only cast a &-pointer to an &-object
5058 // E0194, // merged into E0403
5059 // E0196, // cannot determine a type for this closure
5060 E0203, // type parameter has more than one relaxed default bound,
5061 // and only one is supported
5063 // E0209, // builtin traits can only be implemented on structs or enums
5064 E0212, // cannot extract an associated type from a higher-ranked trait bound
5065 // E0213, // associated types are not accepted in this context
5066 // E0215, // angle-bracket notation is not stable with `Fn`
5067 // E0216, // parenthetical notation is only stable with `Fn`
5068 // E0217, // ambiguous associated type, defined in multiple supertraits
5069 // E0218, // no associated type defined
5070 // E0219, // associated type defined in higher-ranked supertrait
5071 // E0222, // Error code E0045 (variadic function must have C or cdecl calling
5072 // convention) duplicate
5073 E0224, // at least one non-builtin train is required for an object type
5074 E0227, // ambiguous lifetime bound, explicit lifetime bound required
5075 E0228, // explicit lifetime bound required
5078 // E0235, // structure constructor specifies a structure of type but
5079 // E0236, // no lang item for range syntax
5080 // E0237, // no lang item for range syntax
5081 // E0238, // parenthesized parameters may only be used with a trait
5082 // E0239, // `next` method of `Iterator` trait has unexpected type
5086 // E0245, // not a trait
5087 // E0246, // invalid recursive type
5089 // E0248, // value used as a type, now reported earlier during resolution
5092 // E0319, // trait impls for defaulted traits allowed just for structs/enums
5093 // E0372, // coherence not object safe
5094 E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
5095 // between structures with the same definition
5096 // E0558, // replaced with a generic attribute input check
5097 // E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
5098 // E0564, // only named lifetimes are allowed in `impl Trait`,
5099 // but `{}` was found in the type `{}`
5100 E0587, // type has conflicting packed and align representation hints
5101 // E0611, // merged into E0616
5102 // E0612, // merged into E0609
5103 // E0613, // Removed (merged with E0609)
5104 E0627, // yield statement outside of generator literal
5105 E0632, // cannot provide explicit generic arguments when `impl Trait` is
5106 // used in argument position
5107 E0634, // type has conflicting packed representaton hints
5108 E0640, // infer outlives requirements
5109 E0641, // cannot cast to/from a pointer with an unknown kind
5110 // E0645, // trait aliases not finished
5111 E0719, // duplicate values for associated type binding
5112 E0722, // Malformed `#[optimize]` attribute
5113 E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions