1 // ignore-tidy-filelength
3 syntax::register_diagnostics! {
6 A pattern attempted to extract an incorrect number of fields from a variant.
8 Erroneous code example:
12 Apple(String, String),
17 A pattern used to match against an enum variant must provide a sub-pattern for
18 each field of the enum variant.
20 Here the `Apple` variant has two fields, and should be matched against like so:
24 Apple(String, String),
28 let x = Fruit::Apple(String::new(), String::new());
32 Fruit::Apple(a, b) => {},
37 Matching with the wrong number of fields has no sensible interpretation:
41 Apple(String, String),
45 let x = Fruit::Apple(String::new(), String::new());
49 Fruit::Apple(a) => {},
50 Fruit::Apple(a, b, c) => {},
54 Check how many fields the enum was declared with and ensure that your pattern
59 Each field of a struct can only be bound once in a pattern.
61 Erroneous code example:
70 let x = Foo { a:1, b:2 };
72 let Foo { a: x, a: y } = x;
73 // error: field `a` bound multiple times in the pattern
77 Each occurrence of a field name binds the value of that field, so to fix this
78 error you will have to remove or alter the duplicate uses of the field name.
79 Perhaps you misspelled another field name? Example:
88 let x = Foo { a:1, b:2 };
90 let Foo { a: x, b: y } = x; // ok!
96 A struct pattern attempted to extract a non-existent field from a struct.
98 Erroneous code example:
100 ```compile_fail,E0026
106 let thing = Thing { x: 0, y: 0 };
109 Thing { x, z } => {} // error: `Thing::z` field doesn't exist
113 If you are using shorthand field patterns but want to refer to the struct field
114 by a different name, you should rename it explicitly. Struct fields are
115 identified by the name used before the colon `:` so struct patterns should
116 resemble the declaration of the struct type being matched.
124 let thing = Thing { x: 0, y: 0 };
127 Thing { x, y: z } => {} // we renamed `y` to `z`
133 A pattern for a struct fails to specify a sub-pattern for every one of the
136 Erroneous code example:
138 ```compile_fail,E0027
144 let d = Dog { name: "Rusty".to_string(), age: 8 };
146 // This is incorrect.
152 To fix this error, ensure that each field from the struct's definition is
153 mentioned in the pattern, or use `..` to ignore unwanted fields. Example:
161 let d = Dog { name: "Rusty".to_string(), age: 8 };
164 Dog { name: ref n, age: x } => {}
167 // This is also correct (ignore unused fields).
169 Dog { age: x, .. } => {}
175 Something other than numbers and characters has been used for a range.
177 Erroneous code example:
179 ```compile_fail,E0029
180 let string = "salutations !";
182 // The ordering relation for strings cannot be evaluated at compile time,
183 // so this doesn't work:
185 "hello" ..= "world" => {}
189 // This is a more general version, using a guard:
191 s if s >= "hello" && s <= "world" => {}
196 In a match expression, only numbers and characters can be matched against a
197 range. This is because the compiler checks that the range is non-empty at
198 compile-time, and is unable to evaluate arbitrary comparison functions. If you
199 want to capture values of an orderable type between two end-points, you can use
204 A trait type has been dereferenced.
206 Erroneous code example:
208 ```compile_fail,E0033
209 # trait SomeTrait { fn method_one(&self){} fn method_two(&self){} }
210 # impl<T> SomeTrait for T {}
211 let trait_obj: &SomeTrait = &"some_value";
213 // This tries to implicitly dereference to create an unsized local variable.
214 let &invalid = trait_obj;
216 // You can call methods without binding to the value being pointed at.
217 trait_obj.method_one();
218 trait_obj.method_two();
221 A pointer to a trait type cannot be implicitly dereferenced by a pattern. Every
222 trait defines a type, but because the size of trait implementers isn't fixed,
223 this type has no compile-time size. Therefore, all accesses to trait types must
224 be through pointers. If you encounter this error you should try to avoid
225 dereferencing the pointer.
227 You can read more about trait objects in the [Trait Objects] section of the
230 [Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects
234 The compiler doesn't know what method to call because more than one method
235 has the same prototype.
237 Erroneous code example:
239 ```compile_fail,E0034
250 impl Trait1 for Test { fn foo() {} }
251 impl Trait2 for Test { fn foo() {} }
254 Test::foo() // error, which foo() to call?
258 To avoid this error, you have to keep only one of them and remove the others.
259 So let's take our example and fix it:
268 impl Trait1 for Test { fn foo() {} }
271 Test::foo() // and now that's good!
275 However, a better solution would be using fully explicit naming of type and
289 impl Trait1 for Test { fn foo() {} }
290 impl Trait2 for Test { fn foo() {} }
293 <Test as Trait1>::foo()
310 impl F for X { fn m(&self) { println!("I am F"); } }
311 impl G for X { fn m(&self) { println!("I am G"); } }
316 F::m(&f); // it displays "I am F"
317 G::m(&f); // it displays "I am G"
323 It is not allowed to manually call destructors in Rust.
325 Erroneous code example:
327 ```compile_fail,E0040
339 let mut x = Foo { x: -7 };
340 x.drop(); // error: explicit use of destructor method
344 It is unnecessary to do this since `drop` is called automatically whenever a
345 value goes out of scope. However, if you really need to drop a value by hand,
346 you can use the `std::mem::drop` function:
360 let mut x = Foo { x: -7 };
367 You cannot use type or const parameters on foreign items.
369 Erroneous code example:
371 ```compile_fail,E0044
372 extern { fn some_func<T>(x: T); }
375 To fix this, replace the generic parameter with the specializations that you
379 extern { fn some_func_i32(x: i32); }
380 extern { fn some_func_i64(x: i64); }
385 Variadic parameters have been used on a non-C ABI function.
387 Erroneous code example:
389 ```compile_fail,E0045
390 #![feature(unboxed_closures)]
393 fn foo(x: u8, ...); // error!
397 Rust only supports variadic parameters for interoperability with C code in its
398 FFI. As such, variadic parameters can only be used with functions which are
399 using the C ABI. To fix such code, put them in an extern "C" block:
409 Items are missing in a trait implementation.
411 Erroneous code example:
413 ```compile_fail,E0046
421 // error: not all trait items implemented, missing: `foo`
424 When trying to make some type implement a trait `Foo`, you must, at minimum,
425 provide implementations for all of `Foo`'s required methods (meaning the
426 methods that do not have default implementations), as well as any required
427 trait items like associated types or constants. Example:
443 An attempted implementation of a trait method has the wrong number of type or
446 Erroneous code example:
448 ```compile_fail,E0049
450 fn foo<T: Default>(x: T) -> Self;
455 // error: method `foo` has 0 type parameters but its trait declaration has 1
458 fn foo(x: bool) -> Self { Bar }
462 For example, the `Foo` trait has a method `foo` with a type parameter `T`,
463 but the implementation of `foo` for the type `Bar` is missing this parameter.
464 To fix this error, they must have the same type parameters:
468 fn foo<T: Default>(x: T) -> Self;
474 fn foo<T: Default>(x: T) -> Self { // ok!
482 An attempted implementation of a trait method has the wrong number of function
485 Erroneous code example:
487 ```compile_fail,E0050
489 fn foo(&self, x: u8) -> bool;
494 // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
497 fn foo(&self) -> bool { true }
501 For example, the `Foo` trait has a method `foo` with two function parameters
502 (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
503 the `u8` parameter. To fix this error, they must have the same parameters:
507 fn foo(&self, x: u8) -> bool;
513 fn foo(&self, x: u8) -> bool { // ok!
521 The parameters of any trait method must match between a trait implementation
522 and the trait definition.
524 Erroneous code example:
526 ```compile_fail,E0053
535 // error, expected u16, found i16
538 // error, types differ in mutability
539 fn bar(&mut self) { }
545 It is not allowed to cast to a bool.
547 Erroneous code example:
549 ```compile_fail,E0054
552 // Not allowed, won't compile
553 let x_is_nonzero = x as bool;
556 If you are trying to cast a numeric type to a bool, you can compare it with
563 let x_is_nonzero = x != 0;
568 During a method call, a value is automatically dereferenced as many times as
569 needed to make the value's type match the method's receiver. The catch is that
570 the compiler will only attempt to dereference a number of times up to the
571 recursion limit (which can be set via the `recursion_limit` attribute).
573 For a somewhat artificial example:
575 ```compile_fail,E0055
576 #![recursion_limit="5"]
586 let ref_foo = &&&&&Foo;
588 // error, reached the recursion limit while auto-dereferencing `&&&&&Foo`
593 One fix may be to increase the recursion limit. Note that it is possible to
594 create an infinite recursion of dereferencing, in which case the only fix is to
595 somehow break the recursion.
599 When invoking closures or other implementations of the function traits `Fn`,
600 `FnMut` or `FnOnce` using call notation, the number of parameters passed to the
601 function must match its definition.
603 An example using a closure:
605 ```compile_fail,E0057
607 let a = f(); // invalid, too few parameters
608 let b = f(4); // this works!
609 let c = f(2, 3); // invalid, too many parameters
612 A generic function must be treated similarly:
615 fn foo<F: Fn()>(f: F) {
616 f(); // this is valid, but f(3) would not work
622 The built-in function traits are generic over a tuple of the function arguments.
623 If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
624 (`Fn(T) -> U`) to denote the function trait, the type parameter should be a
625 tuple. Otherwise function call notation cannot be used and the trait will not be
626 implemented by closures.
628 The most likely source of this error is using angle-bracket notation without
629 wrapping the function argument type into a tuple, for example:
631 ```compile_fail,E0059
632 #![feature(unboxed_closures)]
634 fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
637 It can be fixed by adjusting the trait bound like this:
640 #![feature(unboxed_closures)]
642 fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
645 Note that `(T,)` always denotes the type of a 1-tuple containing an element of
646 type `T`. The comma is necessary for syntactic disambiguation.
650 External C functions are allowed to be variadic. However, a variadic function
651 takes a minimum number of arguments. For example, consider C's variadic `printf`
655 use std::os::raw::{c_char, c_int};
658 fn printf(_: *const c_char, ...) -> c_int;
662 Using this declaration, it must be called with at least one argument, so
663 simply calling `printf()` is invalid. But the following uses are allowed:
666 # #![feature(static_nobundle)]
667 # use std::os::raw::{c_char, c_int};
668 # #[cfg_attr(all(windows, target_env = "msvc"),
669 # link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
670 # extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
673 use std::ffi::CString;
675 let fmt = CString::new("test\n").unwrap();
676 printf(fmt.as_ptr());
678 let fmt = CString::new("number = %d\n").unwrap();
679 printf(fmt.as_ptr(), 3);
681 let fmt = CString::new("%d, %d\n").unwrap();
682 printf(fmt.as_ptr(), 10, 5);
687 // ^ Note: On MSVC 2015, the `printf` function is "inlined" in the C code, and
688 // the C runtime does not contain the `printf` definition. This leads to linker
689 // error from the doc test (issue #42830).
690 // This can be fixed by linking to the static library
691 // `legacy_stdio_definitions.lib` (see https://stackoverflow.com/a/36504365/).
692 // If this compatibility library is removed in the future, consider changing
693 // `printf` in this example to another well-known variadic function.
696 The number of arguments passed to a function must match the number of arguments
697 specified in the function signature.
699 For example, a function like:
702 fn f(a: u16, b: &str) {}
705 Must always be called with exactly two arguments, e.g., `f(2, "test")`.
707 Note that Rust does not have a notion of optional function arguments or
708 variadic functions (except for its C-FFI).
712 This error indicates that during an attempt to build a struct or struct-like
713 enum variant, one of the fields was specified more than once. Erroneous code
716 ```compile_fail,E0062
724 x: 0, // error: field `x` specified more than once
729 Each field should be specified exactly one time. Example:
737 let x = Foo { x: 0 }; // ok!
743 This error indicates that during an attempt to build a struct or struct-like
744 enum variant, one of the fields was not provided. Erroneous code example:
746 ```compile_fail,E0063
753 let x = Foo { x: 0 }; // error: missing field: `y`
757 Each field should be specified exactly once. Example:
766 let x = Foo { x: 0, y: 0 }; // ok!
772 The left-hand side of a compound assignment expression must be a place
773 expression. A place expression represents a memory location and includes
774 item paths (ie, namespaced variables), dereferences, indexing expressions,
775 and field references.
777 Let's start with some erroneous code examples:
779 ```compile_fail,E0067
780 use std::collections::LinkedList;
782 // Bad: assignment to non-place expression
783 LinkedList::new() += 1;
787 fn some_func(i: &mut i32) {
788 i += 12; // Error : '+=' operation cannot be applied on a reference !
792 And now some working examples:
801 fn some_func(i: &mut i32) {
808 The compiler found a function whose body contains a `return;` statement but
809 whose return type is not `()`. An example of this is:
811 ```compile_fail,E0069
818 Since `return;` is just like `return ();`, there is a mismatch between the
819 function's return type and the value being returned.
823 The left-hand side of an assignment operator must be a place expression. A
824 place expression represents a memory location and can be a variable (with
825 optional namespacing), a dereference, an indexing expression or a field
828 More details can be found in the [Expressions] section of the Reference.
830 [Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
832 Now, we can go further. Here are some erroneous code examples:
834 ```compile_fail,E0070
840 const SOME_CONST : i32 = 12;
842 fn some_other_func() {}
845 SOME_CONST = 14; // error : a constant value cannot be changed!
846 1 = 3; // error : 1 isn't a valid place!
847 some_other_func() = 4; // error : we cannot assign value to a function!
848 SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
853 And now let's give working examples:
860 let mut s = SomeStruct {x: 0, y: 0};
862 s.x = 3; // that's good !
866 fn some_func(x: &mut i32) {
867 *x = 12; // that's good !
873 You tried to use structure-literal syntax to create an item that is
874 not a structure or enum variant.
876 Example of erroneous code:
878 ```compile_fail,E0071
880 let t = U32 { value: 4 }; // error: expected struct, variant or union type,
881 // found builtin type `u32`
884 To fix this, ensure that the name was correctly spelled, and that
885 the correct form of initializer was used.
887 For example, the code above can be fixed to:
895 let u = Foo::FirstValue(0i32);
903 #### Note: this error code is no longer emitted by the compiler.
905 You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
906 in order to make a new `Foo` value. This is because there would be no way a
907 first instance of `Foo` could be made to initialize another instance!
909 Here's an example of a struct that has this problem:
912 struct Foo { x: Box<Foo> } // error
915 One fix is to use `Option`, like so:
918 struct Foo { x: Option<Box<Foo>> }
921 Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
925 #### Note: this error code is no longer emitted by the compiler.
927 When using the `#[simd]` attribute on a tuple struct, the components of the
928 tuple struct must all be of a concrete, nongeneric type so the compiler can
929 reason about how to use SIMD with them. This error will occur if the types
932 This will cause an error:
935 #![feature(repr_simd)]
938 struct Bad<T>(T, T, T);
944 #![feature(repr_simd)]
947 struct Good(u32, u32, u32);
952 The `#[simd]` attribute can only be applied to non empty tuple structs, because
953 it doesn't make sense to try to use SIMD operations when there are no values to
956 This will cause an error:
958 ```compile_fail,E0075
959 #![feature(repr_simd)]
968 #![feature(repr_simd)]
976 When using the `#[simd]` attribute to automatically use SIMD operations in tuple
977 struct, the types in the struct must all be of the same type, or the compiler
978 will trigger this error.
980 This will cause an error:
982 ```compile_fail,E0076
983 #![feature(repr_simd)]
986 struct Bad(u16, u32, u32);
992 #![feature(repr_simd)]
995 struct Good(u32, u32, u32);
1000 When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
1001 must be machine types so SIMD operations can be applied to them.
1003 This will cause an error:
1005 ```compile_fail,E0077
1006 #![feature(repr_simd)]
1015 #![feature(repr_simd)]
1018 struct Good(u32, u32, u32);
1023 Enum discriminants are used to differentiate enum variants stored in memory.
1024 This error indicates that the same value was used for two or more variants,
1025 making them impossible to tell apart.
1027 ```compile_fail,E0081
1045 Note that variants without a manually specified discriminant are numbered from
1046 top to bottom starting from 0, so clashes can occur with seemingly unrelated
1049 ```compile_fail,E0081
1056 Here `X` will have already been specified the discriminant 0 by the time `Y` is
1057 encountered, so a conflict occurs.
1061 An unsupported representation was attempted on a zero-variant enum.
1063 Erroneous code example:
1065 ```compile_fail,E0084
1067 enum NightsWatch {} // error: unsupported representation for zero-variant enum
1070 It is impossible to define an integer type to be used to represent zero-variant
1071 enum values because there are no zero-variant enum values. There is no way to
1072 construct an instance of the following type using only safe code. So you have
1073 two solutions. Either you add variants in your enum:
1083 or you remove the integer represention of your enum:
1090 // FIXME(const_generics:docs): example of inferring const parameter.
1092 #### Note: this error code is no longer emitted by the compiler.
1094 Too many type arguments were supplied for a function. For example:
1096 ```compile_fail,E0107
1100 foo::<f64, bool>(); // error: wrong number of type arguments:
1101 // expected 1, found 2
1105 The number of supplied arguments must exactly match the number of defined type
1110 #### Note: this error code is no longer emitted by the compiler.
1112 You gave too many lifetime arguments. Erroneous code example:
1114 ```compile_fail,E0107
1118 f::<'static>() // error: wrong number of lifetime arguments:
1119 // expected 0, found 1
1123 Please check you give the right number of lifetime arguments. Example:
1133 It's also important to note that the Rust compiler can generally
1134 determine the lifetime by itself. Example:
1142 // it can be written like this
1143 fn get_value<'a>(&'a self) -> &'a str { &self.value }
1144 // but the compiler works fine with this too:
1145 fn without_lifetime(&self) -> &str { &self.value }
1149 let f = Foo { value: "hello".to_owned() };
1151 println!("{}", f.get_value());
1152 println!("{}", f.without_lifetime());
1158 #### Note: this error code is no longer emitted by the compiler.
1160 Too few type arguments were supplied for a function. For example:
1162 ```compile_fail,E0107
1166 foo::<f64>(); // error: wrong number of type arguments: expected 2, found 1
1170 Note that if a function takes multiple type arguments but you want the compiler
1171 to infer some of them, you can use type placeholders:
1173 ```compile_fail,E0107
1174 fn foo<T, U>(x: T) {}
1178 foo::<f64>(x); // error: wrong number of type arguments:
1179 // expected 2, found 1
1180 foo::<_, f64>(x); // same as `foo::<bool, f64>(x)`
1186 #### Note: this error code is no longer emitted by the compiler.
1188 You gave too few lifetime arguments. Example:
1190 ```compile_fail,E0107
1191 fn foo<'a: 'b, 'b: 'a>() {}
1194 foo::<'static>(); // error: wrong number of lifetime arguments:
1195 // expected 2, found 1
1199 Please check you give the right number of lifetime arguments. Example:
1202 fn foo<'a: 'b, 'b: 'a>() {}
1205 foo::<'static, 'static>();
1211 You gave an unnecessary type or const parameter in a type alias. Erroneous
1214 ```compile_fail,E0091
1215 type Foo<T> = u32; // error: type parameter `T` is unused
1217 type Foo<A,B> = Box<A>; // error: type parameter `B` is unused
1220 Please check you didn't write too many parameters. Example:
1223 type Foo = u32; // ok!
1224 type Foo2<A> = Box<A>; // ok!
1229 You tried to declare an undefined atomic operation function.
1230 Erroneous code example:
1232 ```compile_fail,E0092
1233 #![feature(intrinsics)]
1235 extern "rust-intrinsic" {
1236 fn atomic_foo(); // error: unrecognized atomic operation
1241 Please check you didn't make a mistake in the function's name. All intrinsic
1242 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1243 libcore/intrinsics.rs in the Rust source code. Example:
1246 #![feature(intrinsics)]
1248 extern "rust-intrinsic" {
1249 fn atomic_fence(); // ok!
1255 You declared an unknown intrinsic function. Erroneous code example:
1257 ```compile_fail,E0093
1258 #![feature(intrinsics)]
1260 extern "rust-intrinsic" {
1261 fn foo(); // error: unrecognized intrinsic function: `foo`
1271 Please check you didn't make a mistake in the function's name. All intrinsic
1272 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1273 libcore/intrinsics.rs in the Rust source code. Example:
1276 #![feature(intrinsics)]
1278 extern "rust-intrinsic" {
1279 fn atomic_fence(); // ok!
1291 You gave an invalid number of type parameters to an intrinsic function.
1292 Erroneous code example:
1294 ```compile_fail,E0094
1295 #![feature(intrinsics)]
1297 extern "rust-intrinsic" {
1298 fn size_of<T, U>() -> usize; // error: intrinsic has wrong number
1299 // of type parameters
1303 Please check that you provided the right number of type parameters
1304 and verify with the function declaration in the Rust source code.
1308 #![feature(intrinsics)]
1310 extern "rust-intrinsic" {
1311 fn size_of<T>() -> usize; // ok!
1317 This error means that an incorrect number of generic arguments were provided:
1319 ```compile_fail,E0107
1320 struct Foo<T> { x: T }
1322 struct Bar { x: Foo } // error: wrong number of type arguments:
1323 // expected 1, found 0
1324 struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
1325 // expected 1, found 2
1327 fn foo<T, U>(x: T, y: U) {}
1331 foo::<bool>(x); // error: wrong number of type arguments:
1332 // expected 2, found 1
1333 foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
1334 // expected 2, found 3
1340 f::<'static>(); // error: wrong number of lifetime arguments:
1341 // expected 0, found 1
1348 You tried to provide a generic argument to a type which doesn't need it.
1349 Erroneous code example:
1351 ```compile_fail,E0109
1352 type X = u32<i32>; // error: type arguments are not allowed for this type
1353 type Y = bool<'static>; // error: lifetime parameters are not allowed on
1357 Check that you used the correct argument and that the definition is correct.
1362 type X = u32; // ok!
1363 type Y = bool; // ok!
1366 Note that generic arguments for enum variant constructors go after the variant,
1367 not after the enum. For example, you would write `Option::None::<u32>`,
1368 rather than `Option::<u32>::None`.
1372 #### Note: this error code is no longer emitted by the compiler.
1374 You tried to provide a lifetime to a type which doesn't need it.
1375 See `E0109` for more details.
1379 You can only define an inherent implementation for a type in the same crate
1380 where the type was defined. For example, an `impl` block as below is not allowed
1381 since `Vec` is defined in the standard library:
1383 ```compile_fail,E0116
1384 impl Vec<u8> { } // error
1387 To fix this problem, you can do either of these things:
1389 - define a trait that has the desired associated functions/types/constants and
1390 implement the trait for the type in question
1391 - define a new type wrapping the type and define an implementation on the new
1394 Note that using the `type` keyword does not work here because `type` only
1395 introduces a type alias:
1397 ```compile_fail,E0116
1398 type Bytes = Vec<u8>;
1400 impl Bytes { } // error, same as above
1405 This error indicates a violation of one of Rust's orphan rules for trait
1406 implementations. The rule prohibits any implementation of a foreign trait (a
1407 trait defined in another crate) where
1409 - the type that is implementing the trait is foreign
1410 - all of the parameters being passed to the trait (if there are any) are also
1413 Here's one example of this error:
1415 ```compile_fail,E0117
1416 impl Drop for u32 {}
1419 To avoid this kind of error, ensure that at least one local type is referenced
1423 pub struct Foo; // you define your type in your crate
1425 impl Drop for Foo { // and you can implement the trait on it!
1426 // code of trait implementation here
1427 # fn drop(&mut self) { }
1430 impl From<Foo> for i32 { // or you use a type from your crate as
1432 fn from(i: Foo) -> i32 {
1438 Alternatively, define a trait locally and implement that instead:
1442 fn get(&self) -> usize;
1446 fn get(&self) -> usize { 0 }
1450 For information on the design of the orphan rules, see [RFC 1023].
1452 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
1456 You're trying to write an inherent implementation for something which isn't a
1457 struct nor an enum. Erroneous code example:
1459 ```compile_fail,E0118
1460 impl (u8, u8) { // error: no base type found for inherent implementation
1461 fn get_state(&self) -> String {
1467 To fix this error, please implement a trait on the type or wrap it in a struct.
1471 // we create a trait here
1472 trait LiveLongAndProsper {
1473 fn get_state(&self) -> String;
1476 // and now you can implement it on (u8, u8)
1477 impl LiveLongAndProsper for (u8, u8) {
1478 fn get_state(&self) -> String {
1479 "He's dead, Jim!".to_owned()
1484 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
1485 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
1489 struct TypeWrapper((u8, u8));
1492 fn get_state(&self) -> String {
1493 "Fascinating!".to_owned()
1500 An attempt was made to implement Drop on a trait, which is not allowed: only
1501 structs and enums can implement Drop. An example causing this error:
1503 ```compile_fail,E0120
1506 impl Drop for MyTrait {
1507 fn drop(&mut self) {}
1511 A workaround for this problem is to wrap the trait up in a struct, and implement
1512 Drop on that. An example is shown below:
1516 struct MyWrapper<T: MyTrait> { foo: T }
1518 impl <T: MyTrait> Drop for MyWrapper<T> {
1519 fn drop(&mut self) {}
1524 Alternatively, wrapping trait objects requires something like the following:
1529 //or Box<MyTrait>, if you wanted an owned trait object
1530 struct MyWrapper<'a> { foo: &'a MyTrait }
1532 impl <'a> Drop for MyWrapper<'a> {
1533 fn drop(&mut self) {}
1539 In order to be consistent with Rust's lack of global type inference,
1540 type and const placeholders are disallowed by design in item signatures.
1542 Examples of this error include:
1544 ```compile_fail,E0121
1545 fn foo() -> _ { 5 } // error, explicitly write out the return type instead
1547 static BAR: _ = "test"; // error, explicitly write out the type instead
1552 You declared two fields of a struct with the same name. Erroneous code
1555 ```compile_fail,E0124
1558 field1: i32, // error: field is already declared
1562 Please verify that the field names have been correctly spelled. Example:
1573 It is not possible to define `main` with generic parameters.
1574 When `main` is present, it must take no arguments and return `()`.
1575 Erroneous code example:
1577 ```compile_fail,E0131
1578 fn main<T>() { // error: main function is not allowed to have generic parameters
1584 A function with the `start` attribute was declared with type parameters.
1586 Erroneous code example:
1588 ```compile_fail,E0132
1595 It is not possible to declare type parameters on a function that has the `start`
1596 attribute. Such a function must have the following type signature (for more
1597 information, view [the unstable book][1]):
1599 [1]: https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib
1603 fn(isize, *const *const u8) -> isize;
1612 fn my_start(argc: isize, argv: *const *const u8) -> isize {
1619 This error means that an attempt was made to match a struct type enum
1620 variant as a non-struct type:
1622 ```compile_fail,E0164
1623 enum Foo { B { i: u32 } }
1625 fn bar(foo: Foo) -> u32 {
1627 Foo::B(i) => i, // error E0164
1632 Try using `{}` instead:
1635 enum Foo { B { i: u32 } }
1637 fn bar(foo: Foo) -> u32 {
1646 Explicitly implementing both Drop and Copy for a type is currently disallowed.
1647 This feature can make some sense in theory, but the current implementation is
1648 incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so
1649 it has been disabled for now.
1651 [iss20126]: https://github.com/rust-lang/rust/issues/20126
1655 An associated function for a trait was defined to be static, but an
1656 implementation of the trait declared the same function to be a method (i.e., to
1657 take a `self` parameter).
1659 Here's an example of this error:
1661 ```compile_fail,E0185
1669 // error, method `foo` has a `&self` declaration in the impl, but not in
1677 An associated function for a trait was defined to be a method (i.e., to take a
1678 `self` parameter), but an implementation of the trait declared the same function
1681 Here's an example of this error:
1683 ```compile_fail,E0186
1691 // error, method `foo` has a `&self` declaration in the trait, but not in
1699 Trait objects need to have all associated types specified. Erroneous code
1702 ```compile_fail,E0191
1707 type Foo = Trait; // error: the value of the associated type `Bar` (from
1708 // the trait `Trait`) must be specified
1711 Please verify you specified all associated types of the trait and that you
1712 used the right trait. Example:
1719 type Foo = Trait<Bar=i32>; // ok!
1724 Negative impls are only allowed for auto traits. For more
1725 information see the [opt-in builtin traits RFC][RFC 19].
1727 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
1731 #### Note: this error code is no longer emitted by the compiler.
1733 `where` clauses must use generic type parameters: it does not make sense to use
1734 them otherwise. An example causing this error:
1741 #[derive(Copy,Clone)]
1746 impl Foo for Wrapper<u32> where Wrapper<u32>: Clone {
1751 This use of a `where` clause is strange - a more common usage would look
1752 something like the following:
1759 #[derive(Copy,Clone)]
1763 impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone {
1768 Here, we're saying that the implementation exists on Wrapper only when the
1769 wrapped type `T` implements `Clone`. The `where` clause is important because
1770 some types will not implement `Clone`, and thus will not get this method.
1772 In our erroneous example, however, we're referencing a single concrete type.
1773 Since we know for certain that `Wrapper<u32>` implements `Clone`, there's no
1774 reason to also specify it in a `where` clause.
1778 Your method's lifetime parameters do not match the trait declaration.
1779 Erroneous code example:
1781 ```compile_fail,E0195
1783 fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
1788 impl Trait for Foo {
1789 fn bar<'a,'b>(x: &'a str, y: &'b str) {
1790 // error: lifetime parameters or bounds on method `bar`
1791 // do not match the trait declaration
1796 The lifetime constraint `'b` for bar() implementation does not match the
1797 trait declaration. Ensure lifetime declarations match exactly in both trait
1798 declaration and implementation. Example:
1802 fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1807 impl Trait for Foo {
1808 fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
1815 Safe traits should not have unsafe implementations, therefore marking an
1816 implementation for a safe trait unsafe will cause a compiler error. Removing
1817 the unsafe marker on the trait noted in the error will resolve this problem.
1819 ```compile_fail,E0199
1824 // this won't compile because Bar is safe
1825 unsafe impl Bar for Foo { }
1826 // this will compile
1827 impl Bar for Foo { }
1832 Unsafe traits must have unsafe implementations. This error occurs when an
1833 implementation for an unsafe trait isn't marked as unsafe. This may be resolved
1834 by marking the unsafe implementation as unsafe.
1836 ```compile_fail,E0200
1839 unsafe trait Bar { }
1841 // this won't compile because Bar is unsafe and impl isn't unsafe
1842 impl Bar for Foo { }
1843 // this will compile
1844 unsafe impl Bar for Foo { }
1849 It is an error to define two associated items (like methods, associated types,
1850 associated functions, etc.) with the same identifier.
1854 ```compile_fail,E0201
1858 fn bar(&self) -> bool { self.0 > 5 }
1859 fn bar() {} // error: duplicate associated function
1864 fn baz(&self) -> bool;
1870 fn baz(&self) -> bool { true }
1872 // error: duplicate method
1873 fn baz(&self) -> bool { self.0 > 5 }
1875 // error: duplicate associated type
1880 Note, however, that items with the same name are allowed for inherent `impl`
1881 blocks that don't overlap:
1887 fn bar(&self) -> bool { self.0 > 5 }
1891 fn bar(&self) -> bool { self.0 }
1897 Inherent associated types were part of [RFC 195] but are not yet implemented.
1898 See [the tracking issue][iss8995] for the status of this implementation.
1900 [RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
1901 [iss8995]: https://github.com/rust-lang/rust/issues/8995
1905 An attempt to implement the `Copy` trait for a struct failed because one of the
1906 fields does not implement `Copy`. To fix this, you must implement `Copy` for the
1907 mentioned field. Note that this may not be possible, as in the example of
1909 ```compile_fail,E0204
1914 impl Copy for Foo { }
1917 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1919 Here's another example that will fail:
1921 ```compile_fail,E0204
1928 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1929 differs from the behavior for `&T`, which is always `Copy`).
1933 #### Note: this error code is no longer emitted by the compiler.
1935 An attempt to implement the `Copy` trait for an enum failed because one of the
1936 variants does not implement `Copy`. To fix this, you must implement `Copy` for
1937 the mentioned variant. Note that this may not be possible, as in the example of
1939 ```compile_fail,E0204
1945 impl Copy for Foo { }
1948 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1950 Here's another example that will fail:
1952 ```compile_fail,E0204
1960 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1961 differs from the behavior for `&T`, which is always `Copy`).
1965 You can only implement `Copy` for a struct or enum. Both of the following
1966 examples will fail, because neither `[u8; 256]` nor `&'static mut Bar`
1967 (mutable reference to `Bar`) is a struct or enum:
1969 ```compile_fail,E0206
1970 type Foo = [u8; 256];
1971 impl Copy for Foo { } // error
1973 #[derive(Copy, Clone)]
1975 impl Copy for &'static mut Bar { } // error
1980 Any type parameter or lifetime parameter of an `impl` must meet at least one of
1981 the following criteria:
1983 - it appears in the _implementing type_ of the impl, e.g. `impl<T> Foo<T>`
1984 - for a trait impl, it appears in the _implemented trait_, e.g.
1985 `impl<T> SomeTrait<T> for Foo`
1986 - it is bound as an associated type, e.g. `impl<T, U> SomeTrait for T
1987 where T: AnotherTrait<AssocType=U>`
1991 Suppose we have a struct `Foo` and we would like to define some methods for it.
1992 The following definition leads to a compiler error:
1994 ```compile_fail,E0207
1997 impl<T: Default> Foo {
1998 // error: the type parameter `T` is not constrained by the impl trait, self
1999 // type, or predicates [E0207]
2000 fn get(&self) -> T {
2001 <T as Default>::default()
2006 The problem is that the parameter `T` does not appear in the implementing type
2007 (`Foo`) of the impl. In this case, we can fix the error by moving the type
2008 parameter from the `impl` to the method `get`:
2014 // Move the type parameter from the impl to the method
2016 fn get<T: Default>(&self) -> T {
2017 <T as Default>::default()
2024 As another example, suppose we have a `Maker` trait and want to establish a
2025 type `FooMaker` that makes `Foo`s:
2027 ```compile_fail,E0207
2030 fn make(&mut self) -> Self::Item;
2039 impl<T: Default> Maker for FooMaker {
2040 // error: the type parameter `T` is not constrained by the impl trait, self
2041 // type, or predicates [E0207]
2044 fn make(&mut self) -> Foo<T> {
2045 Foo { foo: <T as Default>::default() }
2050 This fails to compile because `T` does not appear in the trait or in the
2053 One way to work around this is to introduce a phantom type parameter into
2054 `FooMaker`, like so:
2057 use std::marker::PhantomData;
2061 fn make(&mut self) -> Self::Item;
2068 // Add a type parameter to `FooMaker`
2069 struct FooMaker<T> {
2070 phantom: PhantomData<T>,
2073 impl<T: Default> Maker for FooMaker<T> {
2076 fn make(&mut self) -> Foo<T> {
2078 foo: <T as Default>::default(),
2084 Another way is to do away with the associated type in `Maker` and use an input
2085 type parameter instead:
2088 // Use a type parameter instead of an associated type here
2090 fn make(&mut self) -> Item;
2099 impl<T: Default> Maker<Foo<T>> for FooMaker {
2100 fn make(&mut self) -> Foo<T> {
2101 Foo { foo: <T as Default>::default() }
2106 ### Additional information
2108 For more information, please see [RFC 447].
2110 [RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md
2114 This error indicates a violation of one of Rust's orphan rules for trait
2115 implementations. The rule concerns the use of type parameters in an
2116 implementation of a foreign trait (a trait defined in another crate), and
2117 states that type parameters must be "covered" by a local type. To understand
2118 what this means, it is perhaps easiest to consider a few examples.
2120 If `ForeignTrait` is a trait defined in some external crate `foo`, then the
2121 following trait `impl` is an error:
2123 ```compile_fail,E0210
2124 # #[cfg(for_demonstration_only)]
2126 # #[cfg(for_demonstration_only)]
2127 use foo::ForeignTrait;
2128 # use std::panic::UnwindSafe as ForeignTrait;
2130 impl<T> ForeignTrait for T { } // error
2134 To work around this, it can be covered with a local type, `MyType`:
2137 # use std::panic::UnwindSafe as ForeignTrait;
2138 struct MyType<T>(T);
2139 impl<T> ForeignTrait for MyType<T> { } // Ok
2142 Please note that a type alias is not sufficient.
2144 For another example of an error, suppose there's another trait defined in `foo`
2145 named `ForeignTrait2` that takes two type parameters. Then this `impl` results
2146 in the same rule violation:
2148 ```ignore (cannot-doctest-multicrate-project)
2150 impl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error
2153 The reason for this is that there are two appearances of type parameter `T` in
2154 the `impl` header, both as parameters for `ForeignTrait2`. The first appearance
2155 is uncovered, and so runs afoul of the orphan rule.
2157 Consider one more example:
2159 ```ignore (cannot-doctest-multicrate-project)
2160 impl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok
2163 This only differs from the previous `impl` in that the parameters `T` and
2164 `MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*
2165 violate the orphan rule; it is permitted.
2167 To see why that last example was allowed, you need to understand the general
2168 rule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:
2170 ```ignore (only-for-syntax-highlight)
2171 impl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }
2174 where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`
2175 are types. One of the types `T0, ..., Tn` must be a local type (this is another
2176 orphan rule, see the explanation for E0117). Let `i` be the smallest integer
2177 such that `Ti` is a local type. Then no type parameter can appear in any of the
2180 For information on the design of the orphan rules, see [RFC 1023].
2182 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
2186 #### Note: this error code is no longer emitted by the compiler.
2188 You used a function or type which doesn't fit the requirements for where it was
2189 used. Erroneous code examples:
2192 #![feature(intrinsics)]
2194 extern "rust-intrinsic" {
2195 fn size_of<T>(); // error: intrinsic has wrong type
2200 fn main() -> i32 { 0 }
2201 // error: main function expects type: `fn() {main}`: expected (), found i32
2208 // error: mismatched types in range: expected u8, found i8
2218 fn x(self: Rc<Foo>) {}
2219 // error: mismatched self type: expected `Foo`: expected struct
2220 // `Foo`, found struct `alloc::rc::Rc`
2224 For the first code example, please check the function definition. Example:
2227 #![feature(intrinsics)]
2229 extern "rust-intrinsic" {
2230 fn size_of<T>() -> usize; // ok!
2234 The second case example is a bit particular: the main function must always
2235 have this definition:
2241 They never take parameters and never return types.
2243 For the third example, when you match, all patterns must have the same type
2244 as the type you're matching on. Example:
2250 0u8..=3u8 => (), // ok!
2255 And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
2256 or `&mut Self` work as explicit self parameters. Example:
2262 fn x(self: Box<Foo>) {} // ok!
2268 You used an associated type which isn't defined in the trait.
2269 Erroneous code example:
2271 ```compile_fail,E0220
2276 type Foo = T1<F=i32>; // error: associated type `F` not found for `T1`
2283 // error: Baz is used but not declared
2284 fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2288 Make sure that you have defined the associated type in the trait body.
2289 Also, verify that you used the right trait or you didn't misspell the
2290 associated type name. Example:
2297 type Foo = T1<Bar=i32>; // ok!
2303 type Baz; // we declare `Baz` in our trait.
2305 // and now we can use it here:
2306 fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2312 An attempt was made to retrieve an associated type, but the type was ambiguous.
2315 ```compile_fail,E0221
2331 In this example, `Foo` defines an associated type `A`. `Bar` inherits that type
2332 from `Foo`, and defines another associated type of the same name. As a result,
2333 when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined
2334 by `Foo` or the one defined by `Bar`.
2336 There are two options to work around this issue. The first is simply to rename
2337 one of the types. Alternatively, one can specify the intended type using the
2351 let _: <Self as Bar>::A;
2358 An attempt was made to retrieve an associated type, but the type was ambiguous.
2361 ```compile_fail,E0223
2362 trait MyTrait {type X; }
2365 let foo: MyTrait::X;
2369 The problem here is that we're attempting to take the type of X from MyTrait.
2370 Unfortunately, the type of X is not defined, because it's only made concrete in
2371 implementations of the trait. A working version of this code might look like:
2374 trait MyTrait {type X; }
2377 impl MyTrait for MyStruct {
2382 let foo: <MyStruct as MyTrait>::X;
2386 This syntax specifies that we want the X type from MyTrait, as made concrete in
2387 MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
2388 might implement two different traits with identically-named associated types.
2389 This syntax allows disambiguation between the two.
2393 You attempted to use multiple types as bounds for a closure or trait object.
2394 Rust does not currently support this. A simple example that causes this error:
2396 ```compile_fail,E0225
2398 let _: Box<dyn std::io::Read + std::io::Write>;
2402 Auto traits such as Send and Sync are an exception to this rule:
2403 It's possible to have bounds of one non-builtin trait, plus any number of
2404 auto traits. For example, the following compiles correctly:
2408 let _: Box<dyn std::io::Read + Send + Sync>;
2414 An associated type binding was done outside of the type parameter declaration
2415 and `where` clause. Erroneous code example:
2417 ```compile_fail,E0229
2420 fn boo(&self) -> <Self as Foo>::A;
2425 impl Foo for isize {
2427 fn boo(&self) -> usize { 42 }
2430 fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
2431 // error: associated type bindings are not allowed here
2434 To solve this error, please move the type bindings in the type parameter
2439 # trait Foo { type A; }
2440 fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok!
2443 Or in the `where` clause:
2447 # trait Foo { type A; }
2448 fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
2453 #### Note: this error code is no longer emitted by the compiler.
2455 This error indicates that not enough type parameters were found in a type or
2458 For example, the `Foo` struct below is defined to be generic in `T`, but the
2459 type parameter is missing in the definition of `Bar`:
2461 ```compile_fail,E0107
2462 struct Foo<T> { x: T }
2464 struct Bar { x: Foo }
2469 #### Note: this error code is no longer emitted by the compiler.
2471 This error indicates that too many type parameters were found in a type or
2474 For example, the `Foo` struct below has no type parameters, but is supplied
2475 with two in the definition of `Bar`:
2477 ```compile_fail,E0107
2478 struct Foo { x: bool }
2480 struct Bar<S, T> { x: Foo<S, T> }
2485 This error indicates that the `self` parameter in a method has an invalid
2488 Methods take a special first parameter, of which there are three variants:
2489 `self`, `&self`, and `&mut self`. These are syntactic sugar for
2490 `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
2496 // ^^^^^ `self` here is a reference to the receiver object
2499 impl Trait for Foo {
2501 // ^^^^^ the receiver type is `&Foo`
2505 The type `Self` acts as an alias to the type of the current trait
2506 implementer, or "receiver type". Besides the already mentioned `Self`,
2507 `&Self` and `&mut Self` valid receiver types, the following are also valid:
2508 `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
2509 (where P is one of the previous types except `Self`). Note that `Self` can
2510 also be the underlying implementing type, like `Foo` in the following
2518 impl Trait for Foo {
2519 fn foo(self: &Foo) {}
2523 E0307 will be emitted by the compiler when using an invalid reciver type,
2524 like in the following example:
2526 ```compile_fail,E0307
2532 impl Trait for Foo {
2533 fn foo(self: &Bar) {}
2537 The nightly feature [Arbintrary self types][AST] extends the accepted
2538 set of receiver types to also include any type that can dereference to
2542 #![feature(arbitrary_self_types)]
2547 // Because you can dereference `Bar` into `Foo`...
2548 impl std::ops::Deref for Bar {
2551 fn deref(&self) -> &Foo {
2557 fn foo(self: Bar) {}
2558 // ^^^^^^^^^ ...it can be used as the receiver type
2562 [AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html
2566 A cross-crate opt-out trait was implemented on something which wasn't a struct
2567 or enum type. Erroneous code example:
2569 ```compile_fail,E0321
2570 #![feature(optin_builtin_traits)]
2574 impl !Sync for Foo {}
2576 unsafe impl Send for &'static Foo {}
2577 // error: cross-crate traits with a default impl, like `core::marker::Send`,
2578 // can only be implemented for a struct/enum type, not
2582 Only structs and enums are permitted to impl Send, Sync, and other opt-out
2583 trait, and the struct or enum must be local to the current crate. So, for
2584 example, `unsafe impl Send for Rc<Foo>` is not allowed.
2588 The `Sized` trait is a special trait built-in to the compiler for types with a
2589 constant size known at compile-time. This trait is automatically implemented
2590 for types as needed by the compiler, and it is currently disallowed to
2591 explicitly implement it for a type.
2595 An associated const was implemented when another trait item was expected.
2596 Erroneous code example:
2598 ```compile_fail,E0323
2607 // error: item `N` is an associated const, which doesn't match its
2608 // trait `<Bar as Foo>`
2612 Please verify that the associated const wasn't misspelled and the correct trait
2613 was implemented. Example:
2623 type N = u32; // ok!
2637 const N : u32 = 0; // ok!
2643 A method was implemented when another trait item was expected. Erroneous
2646 ```compile_fail,E0324
2657 // error: item `N` is an associated method, which doesn't match its
2658 // trait `<Bar as Foo>`
2662 To fix this error, please verify that the method name wasn't misspelled and
2663 verify that you are indeed implementing the correct trait items. Example:
2683 An associated type was implemented when another trait item was expected.
2684 Erroneous code example:
2686 ```compile_fail,E0325
2695 // error: item `N` is an associated type, which doesn't match its
2696 // trait `<Bar as Foo>`
2700 Please verify that the associated type name wasn't misspelled and your
2701 implementation corresponds to the trait definition. Example:
2711 type N = u32; // ok!
2725 const N : u32 = 0; // ok!
2731 The types of any associated constants in a trait implementation must match the
2732 types in the trait definition. This error indicates that there was a mismatch.
2734 Here's an example of this error:
2736 ```compile_fail,E0326
2744 const BAR: u32 = 5; // error, expected bool, found u32
2750 The Unsize trait should not be implemented directly. All implementations of
2751 Unsize are provided automatically by the compiler.
2753 Erroneous code example:
2755 ```compile_fail,E0328
2758 use std::marker::Unsize;
2762 impl<T> Unsize<T> for MyType {}
2765 If you are defining your own smart pointer type and would like to enable
2766 conversion from a sized to an unsized type with the
2767 [DST coercion system][RFC 982], use [`CoerceUnsized`] instead.
2770 #![feature(coerce_unsized)]
2772 use std::ops::CoerceUnsized;
2774 pub struct MyType<T: ?Sized> {
2775 field_with_unsized_type: T,
2778 impl<T, U> CoerceUnsized<MyType<U>> for MyType<T>
2779 where T: CoerceUnsized<U> {}
2782 [RFC 982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
2783 [`CoerceUnsized`]: https://doc.rust-lang.org/std/ops/trait.CoerceUnsized.html
2787 #### Note: this error code is no longer emitted by the compiler.
2789 An attempt was made to access an associated constant through either a generic
2790 type parameter or `Self`. This is not supported yet. An example causing this
2791 error is shown below:
2800 impl Foo for MyStruct {
2801 const BAR: f64 = 0f64;
2804 fn get_bar_bad<F: Foo>(t: F) -> f64 {
2809 Currently, the value of `BAR` for a particular type can only be accessed
2810 through a concrete type, as shown below:
2819 impl Foo for MyStruct {
2820 const BAR: f64 = 0f64;
2823 fn get_bar_good() -> f64 {
2824 <MyStruct as Foo>::BAR
2830 An attempt was made to implement `Drop` on a concrete specialization of a
2831 generic type. An example is shown below:
2833 ```compile_fail,E0366
2838 impl Drop for Foo<u32> {
2839 fn drop(&mut self) {}
2843 This code is not legal: it is not possible to specialize `Drop` to a subset of
2844 implementations of a generic type. One workaround for this is to wrap the
2845 generic type, as shown below:
2857 fn drop(&mut self) {}
2863 An attempt was made to implement `Drop` on a specialization of a generic type.
2864 An example is shown below:
2866 ```compile_fail,E0367
2869 struct MyStruct<T> {
2873 impl<T: Foo> Drop for MyStruct<T> {
2874 fn drop(&mut self) {}
2878 This code is not legal: it is not possible to specialize `Drop` to a subset of
2879 implementations of a generic type. In order for this code to work, `MyStruct`
2880 must also require that `T` implements `Foo`. Alternatively, another option is
2881 to wrap the generic type in another that specializes appropriately:
2886 struct MyStruct<T> {
2890 struct MyStructWrapper<T: Foo> {
2894 impl <T: Foo> Drop for MyStructWrapper<T> {
2895 fn drop(&mut self) {}
2901 This error indicates that a binary assignment operator like `+=` or `^=` was
2902 applied to a type that doesn't support it. For example:
2904 ```compile_fail,E0368
2905 let mut x = 12f32; // error: binary operation `<<` cannot be applied to
2911 To fix this error, please check that this type implements this binary
2915 let mut x = 12u32; // the `u32` type does implement the `ShlAssign` trait
2920 It is also possible to overload most operators for your own type by
2921 implementing the `[OP]Assign` traits from `std::ops`.
2923 Another problem you might be facing is this: suppose you've overloaded the `+`
2924 operator for some type `Foo` by implementing the `std::ops::Add` trait for
2925 `Foo`, but you find that using `+=` does not work, as in this example:
2927 ```compile_fail,E0368
2935 fn add(self, rhs: Foo) -> Foo {
2941 let mut x: Foo = Foo(5);
2942 x += Foo(7); // error, `+= cannot be applied to the type `Foo`
2946 This is because `AddAssign` is not automatically implemented, so you need to
2947 manually implement it for your type.
2951 A binary operation was attempted on a type which doesn't support it.
2952 Erroneous code example:
2954 ```compile_fail,E0369
2955 let x = 12f32; // error: binary operation `<<` cannot be applied to
2961 To fix this error, please check that this type implements this binary
2965 let x = 12u32; // the `u32` type does implement it:
2966 // https://doc.rust-lang.org/stable/std/ops/trait.Shl.html
2971 It is also possible to overload most operators for your own type by
2972 implementing traits from `std::ops`.
2974 String concatenation appends the string on the right to the string on the
2975 left and may require reallocation. This requires ownership of the string
2976 on the left. If something should be added to a string literal, move the
2977 literal to the heap by allocating it with `to_owned()` like in
2978 `"Your text".to_owned()`.
2983 The maximum value of an enum was reached, so it cannot be automatically
2984 set in the next enum value. Erroneous code example:
2986 ```compile_fail,E0370
2989 X = 0x7fffffffffffffff,
2990 Y, // error: enum discriminant overflowed on value after
2991 // 9223372036854775807: i64; set explicitly via
2992 // Y = -9223372036854775808 if that is desired outcome
2996 To fix this, please set manually the next enum value or put the enum variant
2997 with the maximum value at the end of the enum. Examples:
3002 X = 0x7fffffffffffffff,
3013 X = 0x7fffffffffffffff,
3019 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
3020 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
3021 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
3022 definition, so it is not useful to do this.
3026 ```compile_fail,E0371
3027 trait Foo { fn foo(&self) { } }
3031 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
3032 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
3033 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
3034 impl Baz for Bar { } // Note: This is OK
3039 A struct without a field containing an unsized type cannot implement
3040 `CoerceUnsized`. An [unsized type][1] is any type that the compiler
3041 doesn't know the length or alignment of at compile time. Any struct
3042 containing an unsized type is also unsized.
3044 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3046 Example of erroneous code:
3048 ```compile_fail,E0374
3049 #![feature(coerce_unsized)]
3050 use std::ops::CoerceUnsized;
3052 struct Foo<T: ?Sized> {
3056 // error: Struct `Foo` has no unsized fields that need `CoerceUnsized`.
3057 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T>
3058 where T: CoerceUnsized<U> {}
3061 `CoerceUnsized` is used to coerce one struct containing an unsized type
3062 into another struct containing a different unsized type. If the struct
3063 doesn't have any fields of unsized types then you don't need explicit
3064 coercion to get the types you want. To fix this you can either
3065 not try to implement `CoerceUnsized` or you can add a field that is
3066 unsized to the struct.
3071 #![feature(coerce_unsized)]
3072 use std::ops::CoerceUnsized;
3074 // We don't need to impl `CoerceUnsized` here.
3079 // We add the unsized type field to the struct.
3080 struct Bar<T: ?Sized> {
3085 // The struct has an unsized field so we can implement
3086 // `CoerceUnsized` for it.
3087 impl<T, U> CoerceUnsized<Bar<U>> for Bar<T>
3088 where T: CoerceUnsized<U> {}
3091 Note that `CoerceUnsized` is mainly used by smart pointers like `Box`, `Rc`
3092 and `Arc` to be able to mark that they can coerce unsized types that they
3097 A struct with more than one field containing an unsized type cannot implement
3098 `CoerceUnsized`. This only occurs when you are trying to coerce one of the
3099 types in your struct to another type in the struct. In this case we try to
3100 impl `CoerceUnsized` from `T` to `U` which are both types that the struct
3101 takes. An [unsized type][1] is any type that the compiler doesn't know the
3102 length or alignment of at compile time. Any struct containing an unsized type
3105 Example of erroneous code:
3107 ```compile_fail,E0375
3108 #![feature(coerce_unsized)]
3109 use std::ops::CoerceUnsized;
3111 struct Foo<T: ?Sized, U: ?Sized> {
3117 // error: Struct `Foo` has more than one unsized field.
3118 impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
3121 `CoerceUnsized` only allows for coercion from a structure with a single
3122 unsized type field to another struct with a single unsized type field.
3123 In fact Rust only allows for a struct to have one unsized type in a struct
3124 and that unsized type must be the last field in the struct. So having two
3125 unsized types in a single struct is not allowed by the compiler. To fix this
3126 use only one field containing an unsized type in the struct and then use
3127 multiple structs to manage each unsized type field you need.
3132 #![feature(coerce_unsized)]
3133 use std::ops::CoerceUnsized;
3135 struct Foo<T: ?Sized> {
3140 impl <T, U> CoerceUnsized<Foo<U>> for Foo<T>
3141 where T: CoerceUnsized<U> {}
3143 fn coerce_foo<T: CoerceUnsized<U>, U>(t: T) -> Foo<U> {
3144 Foo { a: 12i32, b: t } // we use coercion to get the `Foo<U>` type we need
3148 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3152 The type you are trying to impl `CoerceUnsized` for is not a struct.
3153 `CoerceUnsized` can only be implemented for a struct. Unsized types are
3154 already able to be coerced without an implementation of `CoerceUnsized`
3155 whereas a struct containing an unsized type needs to know the unsized type
3156 field it's containing is able to be coerced. An [unsized type][1]
3157 is any type that the compiler doesn't know the length or alignment of at
3158 compile time. Any struct containing an unsized type is also unsized.
3160 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3162 Example of erroneous code:
3164 ```compile_fail,E0376
3165 #![feature(coerce_unsized)]
3166 use std::ops::CoerceUnsized;
3168 struct Foo<T: ?Sized> {
3172 // error: The type `U` is not a struct
3173 impl<T, U> CoerceUnsized<U> for Foo<T> {}
3176 The `CoerceUnsized` trait takes a struct type. Make sure the type you are
3177 providing to `CoerceUnsized` is a struct with only the last field containing an
3183 #![feature(coerce_unsized)]
3184 use std::ops::CoerceUnsized;
3190 // The `Foo<U>` is a struct so `CoerceUnsized` can be implemented
3191 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
3194 Note that in Rust, structs can only contain an unsized type if the field
3195 containing the unsized type is the last and only unsized type field in the
3200 The `DispatchFromDyn` trait currently can only be implemented for
3201 builtin pointer types and structs that are newtype wrappers around them
3202 — that is, the struct must have only one field (except for`PhantomData`),
3203 and that field must itself implement `DispatchFromDyn`.
3208 #![feature(dispatch_from_dyn, unsize)]
3211 ops::DispatchFromDyn,
3214 struct Ptr<T: ?Sized>(*const T);
3216 impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
3223 #![feature(dispatch_from_dyn)]
3225 ops::DispatchFromDyn,
3226 marker::PhantomData,
3231 _phantom: PhantomData<()>,
3234 impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
3236 T: DispatchFromDyn<U>,
3240 Example of illegal `DispatchFromDyn` implementation
3241 (illegal because of extra field)
3243 ```compile-fail,E0378
3244 #![feature(dispatch_from_dyn)]
3245 use std::ops::DispatchFromDyn;
3247 struct WrapperExtraField<T> {
3252 impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
3254 T: DispatchFromDyn<U>,
3260 You tried to implement methods for a primitive type. Erroneous code example:
3262 ```compile_fail,E0390
3268 // error: only a single inherent implementation marked with
3269 // `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive
3272 This isn't allowed, but using a trait to implement a method is a good solution.
3284 impl Bar for *mut Foo {
3291 This error indicates that a type or lifetime parameter has been declared
3292 but not actually used. Here is an example that demonstrates the error:
3294 ```compile_fail,E0392
3300 If the type parameter was included by mistake, this error can be fixed
3301 by simply removing the type parameter, as shown below:
3309 Alternatively, if the type parameter was intentionally inserted, it must be
3310 used. A simple fix is shown below:
3318 This error may also commonly be found when working with unsafe code. For
3319 example, when using raw pointers one may wish to specify the lifetime for
3320 which the pointed-at data is valid. An initial attempt (below) causes this
3323 ```compile_fail,E0392
3329 We want to express the constraint that Foo should not outlive `'a`, because
3330 the data pointed to by `T` is only valid for that lifetime. The problem is
3331 that there are no actual uses of `'a`. It's possible to work around this
3332 by adding a PhantomData type to the struct, using it to tell the compiler
3333 to act as if the struct contained a borrowed reference `&'a T`:
3336 use std::marker::PhantomData;
3338 struct Foo<'a, T: 'a> {
3340 phantom: PhantomData<&'a T>
3344 [PhantomData] can also be used to express information about unused type
3347 [PhantomData]: https://doc.rust-lang.org/std/marker/struct.PhantomData.html
3351 A type parameter which references `Self` in its default value was not specified.
3352 Example of erroneous code:
3354 ```compile_fail,E0393
3357 fn together_we_will_rule_the_galaxy(son: &A) {}
3358 // error: the type parameter `T` must be explicitly specified in an
3359 // object type because its default value `Self` references the
3363 A trait object is defined over a single, fully-defined trait. With a regular
3364 default parameter, this parameter can just be substituted in. However, if the
3365 default parameter is `Self`, the trait changes for each concrete type; i.e.
3366 `i32` will be expected to implement `A<i32>`, `bool` will be expected to
3367 implement `A<bool>`, etc... These types will not share an implementation of a
3368 fully-defined trait; instead they share implementations of a trait with
3369 different parameters substituted in for each implementation. This is
3370 irreconcilable with what we need to make a trait object work, and is thus
3371 disallowed. Making the trait concrete by explicitly specifying the value of the
3372 defaulted parameter will fix this issue. Fixed example:
3377 fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
3382 You implemented a trait, overriding one or more of its associated types but did
3383 not reimplement its default methods.
3385 Example of erroneous code:
3387 ```compile_fail,E0399
3388 #![feature(associated_type_defaults)]
3396 // error - the following trait items need to be reimplemented as
3397 // `Assoc` was overridden: `bar`
3402 To fix this, add an implementation for each default method from the trait:
3405 #![feature(associated_type_defaults)]
3414 fn bar(&self) {} // ok!
3420 The functional record update syntax is only allowed for structs. (Struct-like
3421 enum variants don't qualify, for example.)
3423 Erroneous code example:
3425 ```compile_fail,E0436
3426 enum PublicationFrequency {
3428 SemiMonthly { days: (u8, u8), annual_special: bool },
3431 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3432 -> PublicationFrequency {
3433 match competitor_frequency {
3434 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3435 days: (1, 15), annual_special: false
3437 c @ PublicationFrequency::SemiMonthly{ .. } =>
3438 PublicationFrequency::SemiMonthly {
3439 annual_special: true, ..c // error: functional record update
3440 // syntax requires a struct
3446 Rewrite the expression without functional record update syntax:
3449 enum PublicationFrequency {
3451 SemiMonthly { days: (u8, u8), annual_special: bool },
3454 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3455 -> PublicationFrequency {
3456 match competitor_frequency {
3457 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3458 days: (1, 15), annual_special: false
3460 PublicationFrequency::SemiMonthly{ days, .. } =>
3461 PublicationFrequency::SemiMonthly {
3462 days, annual_special: true // ok!
3470 The length of the platform-intrinsic function `simd_shuffle`
3471 wasn't specified. Erroneous code example:
3473 ```compile_fail,E0439
3474 #![feature(platform_intrinsics)]
3476 extern "platform-intrinsic" {
3477 fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3478 // error: invalid `simd_shuffle`, needs length: `simd_shuffle`
3482 The `simd_shuffle` function needs the length of the array passed as
3483 last parameter in its name. Example:
3486 #![feature(platform_intrinsics)]
3488 extern "platform-intrinsic" {
3489 fn simd_shuffle8<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3495 The `typeof` keyword is currently reserved but unimplemented.
3496 Erroneous code example:
3498 ```compile_fail,E0516
3500 let x: typeof(92) = 92;
3504 Try using type inference instead. Example:
3514 A non-default implementation was already made on this type so it cannot be
3515 specialized further. Erroneous code example:
3517 ```compile_fail,E0520
3518 #![feature(specialization)]
3525 impl<T> SpaceLlama for T {
3526 default fn fly(&self) {}
3530 // applies to all `Clone` T and overrides the previous impl
3531 impl<T: Clone> SpaceLlama for T {
3535 // since `i32` is clone, this conflicts with the previous implementation
3536 impl SpaceLlama for i32 {
3537 default fn fly(&self) {}
3538 // error: item `fly` is provided by an `impl` that specializes
3539 // another, but the item in the parent `impl` is not marked
3540 // `default` and so it cannot be specialized.
3544 Specialization only allows you to override `default` functions in
3547 To fix this error, you need to mark all the parent implementations as default.
3551 #![feature(specialization)]
3558 impl<T> SpaceLlama for T {
3559 default fn fly(&self) {} // This is a parent implementation.
3562 // applies to all `Clone` T; overrides the previous impl
3563 impl<T: Clone> SpaceLlama for T {
3564 default fn fly(&self) {} // This is a parent implementation but was
3565 // previously not a default one, causing the error
3568 // applies to i32, overrides the previous two impls
3569 impl SpaceLlama for i32 {
3570 fn fly(&self) {} // And now that's ok!
3576 The number of elements in an array or slice pattern differed from the number of
3577 elements in the array being matched.
3579 Example of erroneous code:
3581 ```compile_fail,E0527
3582 let r = &[1, 2, 3, 4];
3584 &[a, b] => { // error: pattern requires 2 elements but array
3586 println!("a={}, b={}", a, b);
3591 Ensure that the pattern is consistent with the size of the matched
3592 array. Additional elements can be matched with `..`:
3595 #![feature(slice_patterns)]
3597 let r = &[1, 2, 3, 4];
3599 &[a, b, ..] => { // ok!
3600 println!("a={}, b={}", a, b);
3607 An array or slice pattern required more elements than were present in the
3610 Example of erroneous code:
3612 ```compile_fail,E0528
3613 #![feature(slice_patterns)]
3617 &[a, b, c, rest @ ..] => { // error: pattern requires at least 3
3618 // elements but array has 2
3619 println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3624 Ensure that the matched array has at least as many elements as the pattern
3625 requires. You can match an arbitrary number of remaining elements with `..`:
3628 #![feature(slice_patterns)]
3630 let r = &[1, 2, 3, 4, 5];
3632 &[a, b, c, rest @ ..] => { // ok!
3633 // prints `a=1, b=2, c=3 rest=[4, 5]`
3634 println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3641 An array or slice pattern was matched against some other type.
3643 Example of erroneous code:
3645 ```compile_fail,E0529
3648 [a, b] => { // error: expected an array or slice, found `f32`
3649 println!("a={}, b={}", a, b);
3654 Ensure that the pattern and the expression being matched on are of consistent
3661 println!("a={}, b={}", a, b);
3668 An item which isn't a unit struct, a variant, nor a constant has been used as a
3671 Erroneous code example:
3673 ```compile_fail,E0533
3677 fn turtle(&self) -> u32 { 0 }
3681 Tortoise::turtle => {} // Error!
3684 if let Tortoise::turtle = 0u32 {} // Same error!
3687 If you want to match against a value returned by a method, you need to bind the
3694 fn turtle(&self) -> u32 { 0 }
3698 x if x == Tortoise.turtle() => {} // Bound into `x` then we compare it!
3705 The `inline` attribute was malformed.
3707 Erroneous code example:
3709 ```ignore (compile_fail not working here; see Issue #43707)
3710 #[inline()] // error: expected one argument
3711 pub fn something() {}
3716 The parenthesized `inline` attribute requires the parameter to be specified:
3730 Alternatively, a paren-less version of the attribute may be used to hint the
3731 compiler about inlining opportunity:
3738 For more information about the inline attribute, read:
3739 https://doc.rust-lang.org/reference.html#inline-attributes
3743 An unknown argument was given to the `inline` attribute.
3745 Erroneous code example:
3747 ```ignore (compile_fail not working here; see Issue #43707)
3748 #[inline(unknown)] // error: invalid argument
3749 pub fn something() {}
3754 The `inline` attribute only supports two arguments:
3759 All other arguments given to the `inline` attribute will return this error.
3763 #[inline(never)] // ok!
3764 pub fn something() {}
3769 For more information about the inline attribute, https:
3770 read://doc.rust-lang.org/reference.html#inline-attributes
3774 An unknown field was specified into an enum's structure variant.
3776 Erroneous code example:
3778 ```compile_fail,E0559
3783 let s = Field::Fool { joke: 0 };
3784 // error: struct variant `Field::Fool` has no field named `joke`
3787 Verify you didn't misspell the field's name or that the field exists. Example:
3794 let s = Field::Fool { joke: 0 }; // ok!
3799 An unknown field was specified into a structure.
3801 Erroneous code example:
3803 ```compile_fail,E0560
3808 let s = Simba { mother: 1, father: 0 };
3809 // error: structure `Simba` has no field named `father`
3812 Verify you didn't misspell the field's name or that the field exists. Example:
3820 let s = Simba { mother: 1, father: 0 }; // ok!
3825 If an impl has a generic parameter with the `#[may_dangle]` attribute, then
3826 that impl must be declared as an `unsafe impl.
3828 Erroneous code example:
3830 ```compile_fail,E0569
3831 #![feature(dropck_eyepatch)]
3834 impl<#[may_dangle] X> Drop for Foo<X> {
3835 fn drop(&mut self) { }
3839 In this example, we are asserting that the destructor for `Foo` will not
3840 access any data of type `X`, and require this assertion to be true for
3841 overall safety in our program. The compiler does not currently attempt to
3842 verify this assertion; therefore we must tag this `impl` as unsafe.
3846 The requested ABI is unsupported by the current target.
3848 The rust compiler maintains for each target a blacklist of ABIs unsupported on
3849 that target. If an ABI is present in such a list this usually means that the
3850 target / ABI combination is currently unsupported by llvm.
3852 If necessary, you can circumvent this check using custom target specifications.
3856 A return statement was found outside of a function body.
3858 Erroneous code example:
3860 ```compile_fail,E0572
3861 const FOO: u32 = return 0; // error: return statement outside of function body
3866 To fix this issue, just remove the return keyword or move the expression into a
3872 fn some_fn() -> u32 {
3883 In a `fn` type, a lifetime appears only in the return type,
3884 and not in the arguments types.
3886 Erroneous code example:
3888 ```compile_fail,E0581
3890 // Here, `'a` appears only in the return type:
3891 let x: for<'a> fn() -> &'a i32;
3895 To fix this issue, either use the lifetime in the arguments, or use
3900 // Here, `'a` appears only in the return type:
3901 let x: for<'a> fn(&'a i32) -> &'a i32;
3902 let y: fn() -> &'static i32;
3906 Note: The examples above used to be (erroneously) accepted by the
3907 compiler, but this was since corrected. See [issue #33685] for more
3910 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3914 A lifetime appears only in an associated-type binding,
3915 and not in the input types to the trait.
3917 Erroneous code example:
3919 ```compile_fail,E0582
3921 // No type can satisfy this requirement, since `'a` does not
3922 // appear in any of the input types (here, `i32`):
3923 where F: for<'a> Fn(i32) -> Option<&'a i32>
3930 To fix this issue, either use the lifetime in the inputs, or use
3934 fn bar<F, G>(t: F, u: G)
3935 where F: for<'a> Fn(&'a i32) -> Option<&'a i32>,
3936 G: Fn(i32) -> Option<&'static i32>,
3943 Note: The examples above used to be (erroneously) accepted by the
3944 compiler, but this was since corrected. See [issue #33685] for more
3947 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3951 A type has both `packed` and `align` representation hints.
3953 Erroneous code example:
3955 ```compile_fail,E0587
3956 #[repr(packed, align(8))] // error!
3957 struct Umbrella(i32);
3960 You cannot use `packed` and `align` hints on a same type. If you want to pack a
3961 type to a given size, you should provide a size to packed:
3964 #[repr(packed)] // ok!
3965 struct Umbrella(i32);
3970 A type with `packed` representation hint has a field with `align`
3971 representation hint.
3973 Erroneous code example:
3975 ```compile_fail,E0588
3977 struct Aligned(i32);
3979 #[repr(packed)] // error!
3980 struct Packed(Aligned);
3983 Just like you cannot have both `align` and `packed` representation hints on a
3984 same type, a `packed` type cannot contain another type with the `align`
3985 representation hint. However, you can do the opposite:
3991 #[repr(align(16))] // ok!
3992 struct Aligned(Packed);
3997 This error occurs when you defined methods or associated functions with same
4000 Erroneous code example:
4002 ```compile_fail,E0592
4006 fn bar() {} // previous definition here
4010 fn bar() {} // duplicate definition here
4014 A similar error is E0201. The difference is whether there is one declaration
4015 block or not. To avoid this error, you must give each `fn` a unique name.
4025 fn baz() {} // define with different name
4031 This error occurs when a method is used on a type which doesn't implement it:
4033 Erroneous code example:
4035 ```compile_fail,E0599
4039 x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
4040 // in the current scope
4045 An unary operator was used on a type which doesn't implement it.
4047 Example of erroneous code:
4049 ```compile_fail,E0600
4055 !Question::Yes; // error: cannot apply unary operator `!` to type `Question`
4058 In this case, `Question` would need to implement the `std::ops::Not` trait in
4059 order to be able to use `!` on it. Let's implement it:
4069 // We implement the `Not` trait on the enum.
4070 impl Not for Question {
4073 fn not(self) -> bool {
4075 Question::Yes => false, // If the `Answer` is `Yes`, then it
4077 Question::No => true, // And here we do the opposite.
4082 assert_eq!(!Question::Yes, false);
4083 assert_eq!(!Question::No, true);
4088 An attempt to index into a type which doesn't implement the `std::ops::Index`
4089 trait was performed.
4091 Erroneous code example:
4093 ```compile_fail,E0608
4094 0u8[2]; // error: cannot index into a value of type `u8`
4097 To be able to index into a type it needs to implement the `std::ops::Index`
4101 let v: Vec<u8> = vec![0, 1, 2, 3];
4103 // The `Vec` type implements the `Index` trait so you can do:
4104 println!("{}", v[2]);
4109 A cast to `char` was attempted on a type other than `u8`.
4111 Erroneous code example:
4113 ```compile_fail,E0604
4114 0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
4117 As the error message indicates, only `u8` can be cast into `char`. Example:
4120 let c = 86u8 as char; // ok!
4124 For more information about casts, take a look at the Type cast section in
4125 [The Reference Book][1].
4127 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4131 An invalid cast was attempted.
4133 Erroneous code examples:
4135 ```compile_fail,E0605
4137 x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
4141 let v = core::ptr::null::<u8>(); // So here, `v` is a `*const u8`.
4142 v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
4145 Only primitive types can be cast into each other. Examples:
4151 let v = core::ptr::null::<u8>();
4152 v as *const i8; // ok!
4155 For more information about casts, take a look at the Type cast section in
4156 [The Reference Book][1].
4158 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4162 An incompatible cast was attempted.
4164 Erroneous code example:
4166 ```compile_fail,E0606
4167 let x = &0u8; // Here, `x` is a `&u8`.
4168 let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid
4171 When casting, keep in mind that only primitive types can be cast into each
4176 let y: u32 = *x as u32; // We dereference it first and then cast it.
4179 For more information about casts, take a look at the Type cast section in
4180 [The Reference Book][1].
4182 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4186 A cast between a thin and a fat pointer was attempted.
4188 Erroneous code example:
4190 ```compile_fail,E0607
4191 let v = core::ptr::null::<u8>();
4195 First: what are thin and fat pointers?
4197 Thin pointers are "simple" pointers: they are purely a reference to a memory
4200 Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
4201 DST don't have a statically known size, therefore they can only exist behind
4202 some kind of pointers that contain additional information. Slices and trait
4203 objects are DSTs. In the case of slices, the additional information the fat
4204 pointer holds is their size.
4206 To fix this error, don't try to cast directly between thin and fat pointers.
4208 For more information about casts, take a look at the Type cast section in
4209 [The Reference Book][1].
4211 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4215 Attempted to access a non-existent field in a struct.
4217 Erroneous code example:
4219 ```compile_fail,E0609
4220 struct StructWithFields {
4224 let s = StructWithFields { x: 0 };
4225 println!("{}", s.foo); // error: no field `foo` on type `StructWithFields`
4228 To fix this error, check that you didn't misspell the field's name or that the
4229 field actually exists. Example:
4232 struct StructWithFields {
4236 let s = StructWithFields { x: 0 };
4237 println!("{}", s.x); // ok!
4242 Attempted to access a field on a primitive type.
4244 Erroneous code example:
4246 ```compile_fail,E0610
4248 println!("{}", x.foo); // error: `{integer}` is a primitive type, therefore
4249 // doesn't have fields
4252 Primitive types are the most basic types available in Rust and don't have
4253 fields. To access data via named fields, struct types are used. Example:
4256 // We declare struct called `Foo` containing two fields:
4262 // We create an instance of this struct:
4263 let variable = Foo { x: 0, y: -12 };
4264 // And we can now access its fields:
4265 println!("x: {}, y: {}", variable.x, variable.y);
4268 For more information about primitives and structs, take a look at The Book:
4269 https://doc.rust-lang.org/book/ch03-02-data-types.html
4270 https://doc.rust-lang.org/book/ch05-00-structs.html
4274 Attempted to dereference a variable which cannot be dereferenced.
4276 Erroneous code example:
4278 ```compile_fail,E0614
4280 *y; // error: type `u32` cannot be dereferenced
4283 Only types implementing `std::ops::Deref` can be dereferenced (such as `&T`).
4289 // So here, `x` is a `&u32`, so we can dereference it:
4295 Attempted to access a method like a field.
4297 Erroneous code example:
4299 ```compile_fail,E0615
4308 let f = Foo { x: 0 };
4309 f.method; // error: attempted to take value of method `method` on type `Foo`
4312 If you want to use a method, add `()` after it:
4315 # struct Foo { x: u32 }
4316 # impl Foo { fn method(&self) {} }
4317 # let f = Foo { x: 0 };
4321 However, if you wanted to access a field of a struct check that the field name
4322 is spelled correctly. Example:
4325 # struct Foo { x: u32 }
4326 # impl Foo { fn method(&self) {} }
4327 # let f = Foo { x: 0 };
4328 println!("{}", f.x);
4333 Attempted to access a private field on a struct.
4335 Erroneous code example:
4337 ```compile_fail,E0616
4340 x: u32, // So `x` is private in here.
4344 pub fn new() -> Foo { Foo { x: 0 } }
4348 let f = some_module::Foo::new();
4349 println!("{}", f.x); // error: field `x` of struct `some_module::Foo` is private
4352 If you want to access this field, you have two options:
4354 1) Set the field public:
4359 pub x: u32, // `x` is now public.
4363 pub fn new() -> Foo { Foo { x: 0 } }
4367 let f = some_module::Foo::new();
4368 println!("{}", f.x); // ok!
4371 2) Add a getter function:
4376 x: u32, // So `x` is still private in here.
4380 pub fn new() -> Foo { Foo { x: 0 } }
4382 // We create the getter function here:
4383 pub fn get_x(&self) -> &u32 { &self.x }
4387 let f = some_module::Foo::new();
4388 println!("{}", f.get_x()); // ok!
4393 Attempted to pass an invalid type of variable into a variadic function.
4395 Erroneous code example:
4397 ```compile_fail,E0617
4399 fn printf(c: *const i8, ...);
4403 printf(::std::ptr::null(), 0f32);
4404 // error: cannot pass an `f32` to variadic function, cast to `c_double`
4408 Certain Rust types must be cast before passing them to a variadic function,
4409 because of arcane ABI rules dictated by the C standard. To fix the error,
4410 cast the value to the type specified by the error message (which you may need
4411 to import from `std::os::raw`).
4415 Attempted to call something which isn't a function nor a method.
4417 Erroneous code examples:
4419 ```compile_fail,E0618
4424 X::Entry(); // error: expected function, tuple struct or tuple variant,
4429 x(); // error: expected function, tuple struct or tuple variant, found `i32`
4432 Only functions and methods can be called using `()`. Example:
4435 // We declare a function:
4436 fn i_am_a_function() {}
4444 #### Note: this error code is no longer emitted by the compiler.
4445 The type-checker needed to know the type of an expression, but that type had not
4448 Erroneous code example:
4454 // Here, the type of `v` is not (yet) known, so we
4455 // cannot resolve this method call:
4456 v.to_uppercase(); // error: the type of this value must be known in
4463 Type inference typically proceeds from the top of the function to the bottom,
4464 figuring out types as it goes. In some cases -- notably method calls and
4465 overloadable operators like `*` -- the type checker may not have enough
4466 information *yet* to make progress. This can be true even if the rest of the
4467 function provides enough context (because the type-checker hasn't looked that
4468 far ahead yet). In this case, type annotations can be used to help it along.
4470 To fix this error, just specify the type of the variable. Example:
4473 let mut x: Vec<String> = vec![]; // We precise the type of the vec elements.
4476 v.to_uppercase(); // Since rustc now knows the type of the vec elements,
4477 // we can use `v`'s methods.
4485 A cast to an unsized type was attempted.
4487 Erroneous code example:
4489 ```compile_fail,E0620
4490 let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]`
4494 In Rust, some types don't have a known size at compile-time. For example, in a
4495 slice type like `[u32]`, the number of elements is not known at compile-time and
4496 hence the overall size cannot be computed. As a result, such types can only be
4497 manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type
4498 (e.g., `Box` or `Rc`). Try casting to a reference instead:
4501 let x = &[1_usize, 2] as &[usize]; // ok!
4506 An intrinsic was declared without being a function.
4508 Erroneous code example:
4510 ```compile_fail,E0622
4511 #![feature(intrinsics)]
4512 extern "rust-intrinsic" {
4513 pub static breakpoint : unsafe extern "rust-intrinsic" fn();
4514 // error: intrinsic must be a function
4517 fn main() { unsafe { breakpoint(); } }
4520 An intrinsic is a function available for use in a given programming language
4521 whose implementation is handled specially by the compiler. In order to fix this
4522 error, just declare a function.
4526 A private item was used outside of its scope.
4528 Erroneous code example:
4530 ```compile_fail,E0624
4539 let foo = inner::Foo;
4540 foo.method(); // error: method `method` is private
4543 Two possibilities are available to solve this issue:
4545 1. Only use the item in the scope it has been defined:
4555 pub fn call_method(foo: &Foo) { // We create a public function.
4556 foo.method(); // Which calls the item.
4560 let foo = inner::Foo;
4561 inner::call_method(&foo); // And since the function is public, we can call the
4562 // method through it.
4565 2. Make the item public:
4572 pub fn method(&self) {} // It's now public.
4576 let foo = inner::Foo;
4577 foo.method(); // Ok!
4582 This error indicates that the struct, enum or enum variant must be matched
4583 non-exhaustively as it has been marked as `non_exhaustive`.
4585 When applied within a crate, downstream users of the crate will need to use the
4586 `_` pattern when matching enums and use the `..` pattern when matching structs.
4587 Downstream crates cannot match against non-exhaustive enum variants.
4589 For example, in the below example, since the enum is marked as
4590 `non_exhaustive`, it is required that downstream crates match non-exhaustively
4593 ```rust,ignore (pseudo-Rust)
4594 use std::error::Error as StdError;
4596 #[non_exhaustive] pub enum Error {
4601 impl StdError for Error {
4602 fn description(&self) -> &str {
4603 // This will not error, despite being marked as non_exhaustive, as this
4604 // enum is defined within the current crate, it can be matched
4607 Message(ref s) => s,
4608 Other => "other or unknown error",
4614 An example of matching non-exhaustively on the above enum is provided below:
4616 ```rust,ignore (pseudo-Rust)
4619 // This will not error as the non_exhaustive Error enum has been matched with a
4622 Message(ref s) => ...,
4628 Similarly, for structs, match with `..` to avoid this error.
4632 This error indicates that the struct, enum or enum variant cannot be
4633 instantiated from outside of the defining crate as it has been marked
4634 as `non_exhaustive` and as such more fields/variants may be added in
4635 future that could cause adverse side effects for this code.
4637 It is recommended that you look for a `new` function or equivalent in the
4638 crate's documentation.
4642 This error indicates that there is a mismatch between generic parameters and
4643 impl Trait parameters in a trait declaration versus its impl.
4645 ```compile_fail,E0643
4647 fn foo(&self, _: &impl Iterator);
4650 fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible
4651 // signature for trait
4657 It is not possible to define `main` with a where clause.
4658 Erroneous code example:
4660 ```compile_fail,E0646
4661 fn main() where i32: Copy { // error: main function is not allowed to have
4668 It is not possible to define `start` with a where clause.
4669 Erroneous code example:
4671 ```compile_fail,E0647
4675 fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
4676 //^ error: start function is not allowed to have a where clause
4683 `export_name` attributes may not contain null characters (`\0`).
4685 ```compile_fail,E0648
4686 #[export_name="\0foo"] // error: `export_name` may not contain null characters
4692 This error indicates that the numeric value for the method being passed exists
4693 but the type of the numeric value or binding could not be identified.
4695 The error happens on numeric literals:
4697 ```compile_fail,E0689
4701 and on numeric bindings without an identified concrete type:
4703 ```compile_fail,E0689
4705 x.neg(); // same error as above
4708 Because of this, you must give the numeric literal or binding a type:
4713 let _ = 2.0_f32.neg();
4716 let _ = (2.0 as f32).neg();
4721 A struct with the representation hint `repr(transparent)` had zero or more than
4722 one fields that were not guaranteed to be zero-sized.
4724 Erroneous code example:
4726 ```compile_fail,E0690
4727 #[repr(transparent)]
4728 struct LengthWithUnit<U> { // error: transparent struct needs exactly one
4729 value: f32, // non-zero-sized field, but has 2
4734 Because transparent structs are represented exactly like one of their fields at
4735 run time, said field must be uniquely determined. If there is no field, or if
4736 there are multiple fields, it is not clear how the struct should be represented.
4737 Note that fields of zero-typed types (e.g., `PhantomData`) can also exist
4738 alongside the field that contains the actual data, they do not count for this
4739 error. When generic types are involved (as in the above example), an error is
4740 reported because the type parameter could be non-zero-sized.
4742 To combine `repr(transparent)` with type parameters, `PhantomData` may be
4746 use std::marker::PhantomData;
4748 #[repr(transparent)]
4749 struct LengthWithUnit<U> {
4751 unit: PhantomData<U>,
4757 A struct, enum, or union with the `repr(transparent)` representation hint
4758 contains a zero-sized field that requires non-trivial alignment.
4760 Erroneous code example:
4762 ```compile_fail,E0691
4763 #![feature(repr_align)]
4766 struct ForceAlign32;
4768 #[repr(transparent)]
4769 struct Wrapper(f32, ForceAlign32); // error: zero-sized field in transparent
4770 // struct has alignment larger than 1
4773 A transparent struct, enum, or union is supposed to be represented exactly like
4774 the piece of data it contains. Zero-sized fields with different alignment
4775 requirements potentially conflict with this property. In the example above,
4776 `Wrapper` would have to be aligned to 32 bytes even though `f32` has a smaller
4777 alignment requirement.
4779 Consider removing the over-aligned zero-sized field:
4782 #[repr(transparent)]
4783 struct Wrapper(f32);
4786 Alternatively, `PhantomData<T>` has alignment 1 for all `T`, so you can use it
4787 if you need to keep the field for some reason:
4790 #![feature(repr_align)]
4792 use std::marker::PhantomData;
4795 struct ForceAlign32;
4797 #[repr(transparent)]
4798 struct Wrapper(f32, PhantomData<ForceAlign32>);
4801 Note that empty arrays `[T; 0]` have the same alignment requirement as the
4802 element type `T`. Also note that the error is conservatively reported even when
4803 the alignment of the zero-sized type is less than or equal to the data field's
4808 A method was called on a raw pointer whose inner type wasn't completely known.
4810 For example, you may have done something like:
4813 # #![deny(warnings)]
4815 let bar = foo as *const _;
4821 Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
4822 specify a type for the pointer (preferably something that makes sense for the
4823 thing you're pointing to):
4827 let bar = foo as *const i32;
4833 Even though `is_null()` exists as a method on any raw pointer, Rust shows this
4834 error because Rust allows for `self` to have arbitrary types (behind the
4835 arbitrary_self_types feature flag).
4837 This means that someone can specify such a function:
4839 ```ignore (cannot-doctest-feature-doesnt-exist-yet)
4841 fn is_null(self: *const Self) -> bool {
4842 // do something else
4847 and now when you call `.is_null()` on a raw pointer to `Foo`, there's ambiguity.
4849 Given that we don't know what type the pointer is, and there's potential
4850 ambiguity for some types, we disallow calling methods on raw pointers when
4851 the type is unknown.
4855 A `#[marker]` trait contained an associated item.
4857 The items of marker traits cannot be overridden, so there's no need to have them
4858 when they cannot be changed per-type anyway. If you wanted them for ergonomic
4859 reasons, consider making an extension trait instead.
4863 An `impl` for a `#[marker]` trait tried to override an associated item.
4865 Because marker traits are allowed to have multiple implementations for the same
4866 type, it's not allowed to override anything in those implementations, as it
4867 would be ambiguous which override should actually be used.
4872 An `impl Trait` type expands to a recursive type.
4874 An `impl Trait` type must be expandable to a concrete type that contains no
4875 `impl Trait` types. For example the following example tries to create an
4876 `impl Trait` type `T` that is equal to `[T, T]`:
4878 ```compile_fail,E0720
4879 fn make_recursive_type() -> impl Sized {
4880 [make_recursive_type(), make_recursive_type()]
4886 An array without a fixed length was pattern-matched.
4888 Example of erroneous code:
4890 ```compile_fail,E0730
4891 #![feature(const_generics)]
4893 fn is_123<const N: usize>(x: [u32; N]) -> bool {
4895 [1, 2, 3] => true, // error: cannot pattern-match on an
4896 // array without a fixed length
4902 Ensure that the pattern is consistent with the size of the matched
4903 array. Additional elements can be matched with `..`:
4906 #![feature(slice_patterns)]
4908 let r = &[1, 2, 3, 4];
4910 &[a, b, ..] => { // ok!
4911 println!("a={}, b={}", a, b);
4918 An enum with the representation hint `repr(transparent)` had zero or more than
4921 Erroneous code example:
4923 ```compile_fail,E0731
4924 #[repr(transparent)]
4925 enum Status { // error: transparent enum needs exactly one variant, but has 2
4931 Because transparent enums are represented exactly like one of their variants at
4932 run time, said variant must be uniquely determined. If there is no variant, or
4933 if there are multiple variants, it is not clear how the enum should be
4938 An `enum` with a discriminant must specify a `#[repr(inttype)]`.
4940 A `#[repr(inttype)]` must be provided on an `enum` if it has a non-unit
4941 variant with a discriminant, or where there are both unit variants with
4942 discriminants and non-unit variants. This restriction ensures that there
4943 is a well-defined way to extract a variant's discriminant from a value;
4947 #![feature(arbitrary_enum_discriminant)]
4959 fn discriminant(v : &Enum) -> u8 {
4960 unsafe { *(v as *const Enum as *const u8) }
4963 assert_eq!(3, discriminant(&Enum::Unit));
4964 assert_eq!(2, discriminant(&Enum::Tuple(5)));
4965 assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
4970 A `union` cannot have fields with destructors.
4974 Recursion in an `async fn` requires boxing. For example, this will not compile:
4976 ```edition2018,compile_fail,E0733
4977 async fn foo(n: usize) {
4984 To achieve async recursion, the `async fn` needs to be desugared
4985 such that the `Future` is explicit in the return type:
4987 ```edition2018,compile_fail,E0720
4988 use std::future::Future;
4989 fn foo_desugared(n: usize) -> impl Future<Output = ()> {
4992 foo_desugared(n - 1).await;
4998 Finally, the future is wrapped in a pinned box:
5001 use std::future::Future;
5003 fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
5004 Box::pin(async move {
5006 foo_recursive(n - 1).await;
5012 The `Box<...>` ensures that the result is of known size,
5013 and the pin is required to keep it in the same place in memory.
5017 `#[track_caller]` requires functions to have the `"Rust"` ABI for implicitly
5018 receiving caller location. See [RFC 2091] for details on this and other
5021 Erroneous code example:
5023 ```compile_fail,E0737
5024 #![feature(track_caller)]
5027 extern "C" fn foo() {}
5030 [RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
5034 Only `structural_match` types (that is, types that derive `PartialEq` and `Eq`)
5035 may be used as the types of const generic parameters.
5037 ```compile_fail,E0741
5038 #![feature(const_generics)]
5042 struct B<const X: A>; // error!
5045 To fix this example, we derive `PartialEq` and `Eq`.
5048 #![feature(const_generics)]
5050 #[derive(PartialEq, Eq)]
5053 struct B<const X: A>; // ok!
5058 // E0035, merged into E0087/E0089
5059 // E0036, merged into E0087/E0089
5065 // E0122, // bounds in type aliases are ignored, turned into proper lint
5070 // E0159, // use of trait `{}` as struct constructor
5071 // E0163, // merged into E0071
5074 // E0172, // non-trait found in a type sum, moved to resolve
5075 // E0173, // manual implementations of unboxed closure traits are experimental
5077 // E0182, // merged into E0229
5079 // E0187, // cannot infer the kind of the closure
5080 // E0188, // can not cast an immutable reference to a mutable pointer
5081 // E0189, // deprecated: can only cast a boxed pointer to a boxed object
5082 // E0190, // deprecated: can only cast a &-pointer to an &-object
5083 // E0194, // merged into E0403
5084 // E0196, // cannot determine a type for this closure
5085 E0203, // type parameter has more than one relaxed default bound,
5086 // and only one is supported
5088 // E0209, // builtin traits can only be implemented on structs or enums
5089 E0212, // cannot extract an associated type from a higher-ranked trait bound
5090 // E0213, // associated types are not accepted in this context
5091 // E0215, // angle-bracket notation is not stable with `Fn`
5092 // E0216, // parenthetical notation is only stable with `Fn`
5093 // E0217, // ambiguous associated type, defined in multiple supertraits
5094 // E0218, // no associated type defined
5095 // E0219, // associated type defined in higher-ranked supertrait
5096 // E0222, // Error code E0045 (variadic function must have C or cdecl calling
5097 // convention) duplicate
5098 E0224, // at least one non-builtin train is required for an object type
5099 E0227, // ambiguous lifetime bound, explicit lifetime bound required
5100 E0228, // explicit lifetime bound required
5103 // E0235, // structure constructor specifies a structure of type but
5104 // E0236, // no lang item for range syntax
5105 // E0237, // no lang item for range syntax
5106 // E0238, // parenthesized parameters may only be used with a trait
5107 // E0239, // `next` method of `Iterator` trait has unexpected type
5111 // E0245, // not a trait
5112 // E0246, // invalid recursive type
5114 // E0248, // value used as a type, now reported earlier during resolution
5117 // E0319, // trait impls for defaulted traits allowed just for structs/enums
5118 // E0372, // coherence not object safe
5119 E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
5120 // between structures with the same definition
5121 // E0558, // replaced with a generic attribute input check
5122 // E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
5123 // E0564, // only named lifetimes are allowed in `impl Trait`,
5124 // but `{}` was found in the type `{}`
5125 // E0611, // merged into E0616
5126 // E0612, // merged into E0609
5127 // E0613, // Removed (merged with E0609)
5128 E0627, // yield statement outside of generator literal
5129 E0632, // cannot provide explicit generic arguments when `impl Trait` is
5130 // used in argument position
5131 E0634, // type has conflicting packed representaton hints
5132 E0640, // infer outlives requirements
5133 E0641, // cannot cast to/from a pointer with an unknown kind
5134 // E0645, // trait aliases not finished
5135 E0719, // duplicate values for associated type binding
5136 E0722, // Malformed `#[optimize]` attribute
5137 E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions