1 #![allow(non_snake_case)]
3 // Error messages for EXXXX errors.
4 // Each message should start and end with a new line, and be wrapped to 80 characters.
5 // In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
6 register_long_diagnostics! {
8 Trait objects like `Box<Trait>` can only be constructed when certain
9 requirements are satisfied by the trait in question.
11 Trait objects are a form of dynamic dispatch and use a dynamically sized type
12 for the inner type. So, for a given trait `Trait`, when `Trait` is treated as a
13 type, as in `Box<Trait>`, the inner type is 'unsized'. In such cases the boxed
14 pointer is a 'fat pointer' that contains an extra pointer to a table of methods
15 (among other things) for dynamic dispatch. This design mandates some
16 restrictions on the types of traits that are allowed to be used in trait
17 objects, which are collectively termed as 'object safety' rules.
19 Attempting to create a trait object for a non object-safe trait will trigger
22 There are various rules:
24 ### The trait cannot require `Self: Sized`
26 When `Trait` is treated as a type, the type does not implement the special
27 `Sized` trait, because the type does not have a known size at compile time and
28 can only be accessed behind a pointer. Thus, if we have a trait like the
32 trait Foo where Self: Sized {
37 We cannot create an object of type `Box<Foo>` or `&Foo` since in this case
38 `Self` would not be `Sized`.
40 Generally, `Self: Sized` is used to indicate that the trait should not be used
41 as a trait object. If the trait comes from your own crate, consider removing
44 ### Method references the `Self` type in its arguments or return type
46 This happens when a trait has a method like the following:
50 fn foo(&self) -> Self;
53 impl Trait for String {
54 fn foo(&self) -> Self {
60 fn foo(&self) -> Self {
66 (Note that `&self` and `&mut self` are okay, it's additional `Self` types which
69 In such a case, the compiler cannot predict the return type of `foo()` in a
70 situation like the following:
74 fn foo(&self) -> Self;
77 fn call_foo(x: Box<Trait>) {
78 let y = x.foo(); // What type is y?
83 If only some methods aren't object-safe, you can add a `where Self: Sized` bound
84 on them to mark them as explicitly unavailable to trait objects. The
85 functionality will still be available to all other implementers, including
86 `Box<Trait>` which is itself sized (assuming you `impl Trait for Box<Trait>`).
90 fn foo(&self) -> Self where Self: Sized;
95 Now, `foo()` can no longer be called on a trait object, but you will now be
96 allowed to make a trait object, and that will be able to call any object-safe
97 methods. With such a bound, one can still call `foo()` on types implementing
98 that trait that aren't behind trait objects.
100 ### Method has generic type parameters
102 As mentioned before, trait objects contain pointers to method tables. So, if we
110 impl Trait for String {
124 At compile time each implementation of `Trait` will produce a table containing
125 the various methods (and other items) related to the implementation.
127 This works fine, but when the method gains generic parameters, we can have a
130 Usually, generic parameters get _monomorphized_. For example, if I have
138 The machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any
139 other type substitution is different. Hence the compiler generates the
140 implementation on-demand. If you call `foo()` with a `bool` parameter, the
141 compiler will only generate code for `foo::<bool>()`. When we have additional
142 type parameters, the number of monomorphized implementations the compiler
143 generates does not grow drastically, since the compiler will only generate an
144 implementation if the function is called with unparametrized substitutions
145 (i.e., substitutions where none of the substituted types are themselves
148 However, with trait objects we have to make a table containing _every_ object
149 that implements the trait. Now, if it has type parameters, we need to add
150 implementations for every type that implements the trait, and there could
151 theoretically be an infinite number of types.
157 fn foo<T>(&self, on: T);
161 impl Trait for String {
162 fn foo<T>(&self, on: T) {
168 fn foo<T>(&self, on: T) {
173 // 8 more implementations
176 Now, if we have the following code:
178 ```compile_fail,E0038
179 # trait Trait { fn foo<T>(&self, on: T); }
180 # impl Trait for String { fn foo<T>(&self, on: T) {} }
181 # impl Trait for u8 { fn foo<T>(&self, on: T) {} }
182 # impl Trait for bool { fn foo<T>(&self, on: T) {} }
184 fn call_foo(thing: Box<Trait>) {
185 thing.foo(true); // this could be any one of the 8 types above
191 We don't just need to create a table of all implementations of all methods of
192 `Trait`, we need to create such a table, for each different type fed to
193 `foo()`. In this case this turns out to be (10 types implementing `Trait`)*(3
194 types being fed to `foo()`) = 30 implementations!
196 With real world traits these numbers can grow drastically.
198 To fix this, it is suggested to use a `where Self: Sized` bound similar to the
199 fix for the sub-error above if you do not intend to call the method with type
204 fn foo<T>(&self, on: T) where Self: Sized;
209 If this is not an option, consider replacing the type parameter with another
210 trait object (e.g., if `T: OtherTrait`, use `on: Box<OtherTrait>`). If the
211 number of types you intend to feed to this method is limited, consider manually
212 listing out the methods of different types.
214 ### Method has no receiver
216 Methods that do not take a `self` parameter can't be called since there won't be
217 a way to get a pointer to the method table for them.
225 This could be called as `<Foo as Foo>::foo()`, which would not be able to pick
228 Adding a `Self: Sized` bound to these methods will generally make this compile.
232 fn foo() -> u8 where Self: Sized;
236 ### The trait cannot contain associated constants
238 Just like static functions, associated constants aren't stored on the method
239 table. If the trait or any subtrait contain an associated constant, they cannot
240 be made into an object.
242 ```compile_fail,E0038
250 A simple workaround is to use a helper method instead:
258 ### The trait cannot use `Self` as a type parameter in the supertrait listing
260 This is similar to the second sub-error, but subtler. It happens in situations
266 trait Trait: Super<Self> {
271 impl Super<Foo> for Foo{}
273 impl Trait for Foo {}
276 Here, the supertrait might have methods as follows:
280 fn get_a(&self) -> A; // note that this is object safe!
284 If the trait `Foo` was deriving from something like `Super<String>` or
285 `Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
286 `get_a()` will definitely return an object of that type.
288 However, if it derives from `Super<Self>`, even though `Super` is object safe,
289 the method `get_a()` would return an object of unknown type when called on the
290 function. `Self` type parameters let us make object safe traits no longer safe,
291 so they are forbidden when specifying supertraits.
293 There's no easy fix for this, generally code will need to be refactored so that
294 you no longer need to derive from `Super<Self>`.
298 When defining a recursive struct or enum, any use of the type being defined
299 from inside the definition must occur behind a pointer (like `Box` or `&`).
300 This is because structs and enums must have a well-defined size, and without
301 the pointer, the size of the type would need to be unbounded.
303 Consider the following erroneous definition of a type for a list of bytes:
305 ```compile_fail,E0072
306 // error, invalid recursive struct type
309 tail: Option<ListNode>,
313 This type cannot have a well-defined size, because it needs to be arbitrarily
314 large (since we would be able to nest `ListNode`s to any depth). Specifically,
317 size of `ListNode` = 1 byte for `head`
318 + 1 byte for the discriminant of the `Option`
322 One way to fix this is by wrapping `ListNode` in a `Box`, like so:
327 tail: Option<Box<ListNode>>,
331 This works because `Box` is a pointer, so its size is well-known.
335 This error indicates that the compiler was unable to sensibly evaluate an
336 constant expression that had to be evaluated. Attempting to divide by 0
337 or causing integer overflow are two ways to induce this error. For example:
339 ```compile_fail,E0080
346 Ensure that the expressions given can be evaluated as the desired integer type.
347 See the FFI section of the Reference for more information about using a custom
350 https://doc.rust-lang.org/reference.html#ffi-attributes
354 This error indicates that a lifetime is missing from a type. If it is an error
355 inside a function signature, the problem may be with failing to adhere to the
356 lifetime elision rules (see below).
358 Here are some simple examples of where you'll run into this error:
360 ```compile_fail,E0106
361 struct Foo1 { x: &bool }
362 // ^ expected lifetime parameter
363 struct Foo2<'a> { x: &'a bool } // correct
366 // ^^^^ expected lifetime parameter
367 impl<'a> Foo2<'a> {} // correct
369 struct Bar1 { x: Foo2 }
370 // ^^^^ expected lifetime parameter
371 struct Bar2<'a> { x: Foo2<'a> } // correct
373 enum Baz1 { A(u8), B(&bool), }
374 // ^ expected lifetime parameter
375 enum Baz2<'a> { A(u8), B(&'a bool), } // correct
378 // ^ expected lifetime parameter
379 type MyStr2<'a> = &'a str; // correct
382 Lifetime elision is a special, limited kind of inference for lifetimes in
383 function signatures which allows you to leave out lifetimes in certain cases.
384 For more background on lifetime elision see [the book][book-le].
386 The lifetime elision rules require that any function signature with an elided
387 output lifetime must either have
389 - exactly one input lifetime
390 - or, multiple input lifetimes, but the function must also be a method with a
391 `&self` or `&mut self` receiver
393 In the first case, the output lifetime is inferred to be the same as the unique
394 input lifetime. In the second case, the lifetime is instead inferred to be the
395 same as the lifetime on `&self` or `&mut self`.
397 Here are some examples of elision errors:
399 ```compile_fail,E0106
400 // error, no input lifetimes
403 // error, `x` and `y` have distinct lifetimes inferred
404 fn bar(x: &str, y: &str) -> &str { }
406 // error, `y`'s lifetime is inferred to be distinct from `x`'s
407 fn baz<'a>(x: &'a str, y: &str) -> &str { }
410 Lifetime elision in implementation headers was part of the lifetime elision
411 RFC. It is, however, [currently unimplemented][iss15872].
413 [book-le]: https://doc.rust-lang.org/nightly/book/first-edition/lifetimes.html#lifetime-elision
414 [iss15872]: https://github.com/rust-lang/rust/issues/15872
418 There are conflicting trait implementations for the same type.
419 Example of erroneous code:
421 ```compile_fail,E0119
423 fn get(&self) -> usize;
426 impl<T> MyTrait for T {
427 fn get(&self) -> usize { 0 }
434 impl MyTrait for Foo { // error: conflicting implementations of trait
435 // `MyTrait` for type `Foo`
436 fn get(&self) -> usize { self.value }
440 When looking for the implementation for the trait, the compiler finds
441 both the `impl<T> MyTrait for T` where T is all types and the `impl
442 MyTrait for Foo`. Since a trait cannot be implemented multiple times,
443 this is an error. So, when you write:
447 fn get(&self) -> usize;
450 impl<T> MyTrait for T {
451 fn get(&self) -> usize { 0 }
455 This makes the trait implemented on all types in the scope. So if you
456 try to implement it on another one after that, the implementations will
461 fn get(&self) -> usize;
464 impl<T> MyTrait for T {
465 fn get(&self) -> usize { 0 }
473 f.get(); // the trait is implemented so we can use it
478 // This shouldn't really ever trigger since the repeated value error comes first
480 A binary can only have one entry point, and by default that entry point is the
481 function `main()`. If there are multiple such functions, please rename one.
485 More than one function was declared with the `#[main]` attribute.
487 Erroneous code example:
489 ```compile_fail,E0137
496 fn f() {} // error: multiple functions with a #[main] attribute
499 This error indicates that the compiler found multiple functions with the
500 `#[main]` attribute. This is an error because there must be a unique entry
501 point into a Rust program. Example:
512 More than one function was declared with the `#[start]` attribute.
514 Erroneous code example:
516 ```compile_fail,E0138
520 fn foo(argc: isize, argv: *const *const u8) -> isize {}
523 fn f(argc: isize, argv: *const *const u8) -> isize {}
524 // error: multiple 'start' functions
527 This error indicates that the compiler found multiple functions with the
528 `#[start]` attribute. This is an error because there must be a unique entry
529 point into a Rust program. Example:
535 fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
540 #### Note: this error code is no longer emitted by the compiler.
542 There are various restrictions on transmuting between types in Rust; for example
543 types being transmuted must have the same size. To apply all these restrictions,
544 the compiler must know the exact types that may be transmuted. When type
545 parameters are involved, this cannot always be done.
547 So, for example, the following is not allowed:
550 use std::mem::transmute;
552 struct Foo<T>(Vec<T>);
554 fn foo<T>(x: Vec<T>) {
555 // we are transmuting between Vec<T> and Foo<F> here
556 let y: Foo<T> = unsafe { transmute(x) };
557 // do something with y
561 In this specific case there's a good chance that the transmute is harmless (but
562 this is not guaranteed by Rust). However, when alignment and enum optimizations
563 come into the picture, it's quite likely that the sizes may or may not match
564 with different type parameter substitutions. It's not possible to check this for
565 _all_ possible types, so `transmute()` simply only accepts types without any
566 unsubstituted type parameters.
568 If you need this, there's a good chance you're doing something wrong. Keep in
569 mind that Rust doesn't guarantee much about the layout of different structs
570 (even two structs with identical declarations may have different layouts). If
571 there is a solution that avoids the transmute entirely, try it instead.
573 If it's possible, hand-monomorphize the code by writing the function for each
574 possible type substitution. It's possible to use traits to do this cleanly,
578 use std::mem::transmute;
580 struct Foo<T>(Vec<T>);
582 trait MyTransmutableType: Sized {
583 fn transmute(_: Vec<Self>) -> Foo<Self>;
586 impl MyTransmutableType for u8 {
587 fn transmute(x: Vec<u8>) -> Foo<u8> {
588 unsafe { transmute(x) }
592 impl MyTransmutableType for String {
593 fn transmute(x: Vec<String>) -> Foo<String> {
594 unsafe { transmute(x) }
598 // ... more impls for the types you intend to transmute
600 fn foo<T: MyTransmutableType>(x: Vec<T>) {
601 let y: Foo<T> = <T as MyTransmutableType>::transmute(x);
602 // do something with y
606 Each impl will be checked for a size match in the transmute as usual, and since
607 there are no unbound type parameters involved, this should compile unless there
608 is a size mismatch in one of the impls.
610 It is also possible to manually transmute:
614 # let v = Some("value");
615 # type SomeType = &'static [u8];
617 ptr::read(&v as *const _ as *const SomeType) // `v` transmuted to `SomeType`
622 Note that this does not move `v` (unlike `transmute`), and may need a
623 call to `mem::forget(v)` in case you want to avoid destructors being called.
627 A lang item was redefined.
629 Erroneous code example:
631 ```compile_fail,E0152
632 #![feature(lang_items)]
635 struct Foo; // error: duplicate lang item found: `arc`
638 Lang items are already implemented in the standard library. Unless you are
639 writing a free-standing application (e.g., a kernel), you do not need to provide
642 You can build a free-standing crate by adding `#![no_std]` to the crate
645 ```ignore (only-for-syntax-highlight)
649 See also https://doc.rust-lang.org/book/first-edition/no-stdlib.html
653 A generic type was described using parentheses rather than angle brackets.
656 ```compile_fail,E0214
658 let v: Vec(&str) = vec!["foo"];
662 This is not currently supported: `v` should be defined as `Vec<&str>`.
663 Parentheses are currently only used with generic types when defining parameters
664 for `Fn`-family traits.
668 The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
669 message for when a particular trait isn't implemented on a type placed in a
670 position that needs that trait. For example, when the following code is
674 #![feature(on_unimplemented)]
676 fn foo<T: Index<u8>>(x: T){}
678 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
679 trait Index<Idx> { /* ... */ }
681 foo(true); // `bool` does not implement `Index<u8>`
684 There will be an error about `bool` not implementing `Index<u8>`, followed by a
685 note saying "the type `bool` cannot be indexed by `u8`".
687 As you can see, you can specify type parameters in curly braces for
688 substitution with the actual types (using the regular format string syntax) in
689 a given situation. Furthermore, `{Self}` will substitute to the type (in this
690 case, `bool`) that we tried to use.
692 This error appears when the curly braces contain an identifier which doesn't
693 match with any of the type parameters or the string `Self`. This might happen
694 if you misspelled a type parameter, or if you intended to use literal curly
695 braces. If it is the latter, escape the curly braces with a second curly brace
696 of the same type; e.g., a literal `{` is `{{`.
700 The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
701 message for when a particular trait isn't implemented on a type placed in a
702 position that needs that trait. For example, when the following code is
706 #![feature(on_unimplemented)]
708 fn foo<T: Index<u8>>(x: T){}
710 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
711 trait Index<Idx> { /* ... */ }
713 foo(true); // `bool` does not implement `Index<u8>`
716 there will be an error about `bool` not implementing `Index<u8>`, followed by a
717 note saying "the type `bool` cannot be indexed by `u8`".
719 As you can see, you can specify type parameters in curly braces for
720 substitution with the actual types (using the regular format string syntax) in
721 a given situation. Furthermore, `{Self}` will substitute to the type (in this
722 case, `bool`) that we tried to use.
724 This error appears when the curly braces do not contain an identifier. Please
725 add one of the same name as a type parameter. If you intended to use literal
726 braces, use `{{` and `}}` to escape them.
730 The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
731 message for when a particular trait isn't implemented on a type placed in a
732 position that needs that trait. For example, when the following code is
736 #![feature(on_unimplemented)]
738 fn foo<T: Index<u8>>(x: T){}
740 #[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
741 trait Index<Idx> { /* ... */ }
743 foo(true); // `bool` does not implement `Index<u8>`
746 there will be an error about `bool` not implementing `Index<u8>`, followed by a
747 note saying "the type `bool` cannot be indexed by `u8`".
749 For this to work, some note must be specified. An empty attribute will not do
750 anything, please remove the attribute or add some helpful note for users of the
755 When using a lifetime like `'a` in a type, it must be declared before being
758 These two examples illustrate the problem:
760 ```compile_fail,E0261
761 // error, use of undeclared lifetime name `'a`
762 fn foo(x: &'a str) { }
765 // error, use of undeclared lifetime name `'a`
770 These can be fixed by declaring lifetime parameters:
777 fn foo<'a>(x: &'a str) {}
780 Impl blocks declare lifetime parameters separately. You need to add lifetime
781 parameters to an impl block if you're implementing a type that has a lifetime
782 parameter of its own.
785 ```compile_fail,E0261
790 // error, use of undeclared lifetime name `'a`
792 fn foo<'a>(x: &'a str) {}
796 This is fixed by declaring the impl block like this:
805 fn foo(x: &'a str) {}
811 Declaring certain lifetime names in parameters is disallowed. For example,
812 because the `'static` lifetime is a special built-in lifetime name denoting
813 the lifetime of the entire program, this is an error:
815 ```compile_fail,E0262
816 // error, invalid lifetime parameter name `'static`
817 fn foo<'static>(x: &'static str) { }
822 A lifetime name cannot be declared more than once in the same scope. For
825 ```compile_fail,E0263
826 // error, lifetime name `'a` declared twice in the same scope
827 fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
832 An unknown external lang item was used. Erroneous code example:
834 ```compile_fail,E0264
835 #![feature(lang_items)]
838 #[lang = "cake"] // error: unknown external lang item: `cake`
843 A list of available external lang items is available in
844 `src/librustc/middle/weak_lang_items.rs`. Example:
847 #![feature(lang_items)]
850 #[lang = "panic_impl"] // ok!
857 This is because of a type mismatch between the associated type of some
858 trait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
859 and another type `U` that is required to be equal to `T::Bar`, but is not.
862 Here is a basic example:
864 ```compile_fail,E0271
865 trait Trait { type AssociatedType; }
867 fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
871 impl Trait for i8 { type AssociatedType = &'static str; }
876 Here is that same example again, with some explanatory comments:
878 ```compile_fail,E0271
879 trait Trait { type AssociatedType; }
881 fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
882 // ~~~~~~~~ ~~~~~~~~~~~~~~~~~~
884 // This says `foo` can |
885 // only be used with |
887 // implements `Trait`. |
889 // This says not only must
890 // `T` be an impl of `Trait`
891 // but also that the impl
892 // must assign the type `u32`
893 // to the associated type.
897 impl Trait for i8 { type AssociatedType = &'static str; }
898 //~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
903 // ... but it is an implementation
904 // that assigns `&'static str` to
905 // the associated type.
908 // Here, we invoke `foo` with an `i8`, which does not satisfy
909 // the constraint `<i8 as Trait>::AssociatedType=u32`, and
910 // therefore the type-checker complains with this error code.
913 To avoid those issues, you have to make the types match correctly.
914 So we can fix the previous examples like this:
918 trait Trait { type AssociatedType; }
920 fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
924 impl Trait for i8 { type AssociatedType = &'static str; }
929 let vs = vec![1, 2, 3, 4];
941 This error occurs when there was a recursive trait requirement that overflowed
942 before it could be evaluated. Often this means that there is unbounded
943 recursion in resolving some type bounds.
945 For example, in the following code:
947 ```compile_fail,E0275
952 impl<T> Foo for T where Bar<T>: Foo {}
955 To determine if a `T` is `Foo`, we need to check if `Bar<T>` is `Foo`. However,
956 to do this check, we need to determine that `Bar<Bar<T>>` is `Foo`. To
957 determine this, we check if `Bar<Bar<Bar<T>>>` is `Foo`, and so on. This is
958 clearly a recursive requirement that can't be resolved directly.
960 Consider changing your trait bounds so that they're less self-referential.
964 This error occurs when a bound in an implementation of a trait does not match
965 the bounds specified in the original trait. For example:
967 ```compile_fail,E0276
973 fn foo<T>(x: T) where T: Copy {}
977 Here, all types implementing `Foo` must have a method `foo<T>(x: T)` which can
978 take any type `T`. However, in the `impl` for `bool`, we have added an extra
979 bound that `T` is `Copy`, which isn't compatible with the original trait.
981 Consider removing the bound from the method or adding the bound to the original
982 method definition in the trait.
986 You tried to use a type which doesn't implement some trait in a place which
987 expected that trait. Erroneous code example:
989 ```compile_fail,E0277
990 // here we declare the Foo trait with a bar method
995 // we now declare a function which takes an object implementing the Foo trait
996 fn some_func<T: Foo>(foo: T) {
1001 // we now call the method with the i32 type, which doesn't implement
1003 some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied
1007 In order to fix this error, verify that the type you're using does implement
1015 fn some_func<T: Foo>(foo: T) {
1016 foo.bar(); // we can now use this method since i32 implements the
1020 // we implement the trait on the i32 type
1026 some_func(5i32); // ok!
1030 Or in a generic context, an erroneous code example would look like:
1032 ```compile_fail,E0277
1033 fn some_func<T>(foo: T) {
1034 println!("{:?}", foo); // error: the trait `core::fmt::Debug` is not
1035 // implemented for the type `T`
1039 // We now call the method with the i32 type,
1040 // which *does* implement the Debug trait.
1045 Note that the error here is in the definition of the generic function: Although
1046 we only call it with a parameter that does implement `Debug`, the compiler
1047 still rejects the function: It must work with all possible input types. In
1048 order to make this example compile, we need to restrict the generic type we're
1054 // Restrict the input type to types that implement Debug.
1055 fn some_func<T: fmt::Debug>(foo: T) {
1056 println!("{:?}", foo);
1060 // Calling the method is still fine, as i32 implements Debug.
1063 // This would fail to compile now:
1064 // struct WithoutDebug;
1065 // some_func(WithoutDebug);
1069 Rust only looks at the signature of the called function, as such it must
1070 already specify all requirements that will be used for every type parameter.
1074 #### Note: this error code is no longer emitted by the compiler.
1076 You tried to supply a type which doesn't implement some trait in a location
1077 which expected that trait. This error typically occurs when working with
1078 `Fn`-based types. Erroneous code example:
1081 fn foo<F: Fn(usize)>(x: F) { }
1084 // type mismatch: ... implements the trait `core::ops::Fn<(String,)>`,
1085 // but the trait `core::ops::Fn<(usize,)>` is required
1087 foo(|y: String| { });
1091 The issue in this case is that `foo` is defined as accepting a `Fn` with one
1092 argument of type `String`, but the closure we attempted to pass to it requires
1093 one arguments of type `usize`.
1097 This error indicates that type inference did not result in one unique possible
1098 type, and extra information is required. In most cases this can be provided
1099 by adding a type annotation. Sometimes you need to specify a generic type
1102 A common example is the `collect` method on `Iterator`. It has a generic type
1103 parameter with a `FromIterator` bound, which for a `char` iterator is
1104 implemented by `Vec` and `String` among others. Consider the following snippet
1105 that reverses the characters of a string:
1107 ```compile_fail,E0282
1108 let x = "hello".chars().rev().collect();
1111 In this case, the compiler cannot infer what the type of `x` should be:
1112 `Vec<char>` and `String` are both suitable candidates. To specify which type to
1113 use, you can use a type annotation on `x`:
1116 let x: Vec<char> = "hello".chars().rev().collect();
1119 It is not necessary to annotate the full type. Once the ambiguity is resolved,
1120 the compiler can infer the rest:
1123 let x: Vec<_> = "hello".chars().rev().collect();
1126 Another way to provide the compiler with enough information, is to specify the
1127 generic type parameter:
1130 let x = "hello".chars().rev().collect::<Vec<char>>();
1133 Again, you need not specify the full type if the compiler can infer it:
1136 let x = "hello".chars().rev().collect::<Vec<_>>();
1139 Apart from a method or function with a generic type parameter, this error can
1140 occur when a type parameter of a struct or trait cannot be inferred. In that
1141 case it is not always possible to use a type annotation, because all candidates
1142 have the same return type. For instance:
1144 ```compile_fail,E0282
1155 let number = Foo::bar();
1160 This will fail because the compiler does not know which instance of `Foo` to
1161 call `bar` on. Change `Foo::bar()` to `Foo::<T>::bar()` to resolve the error.
1165 This error occurs when the compiler doesn't have enough information
1166 to unambiguously choose an implementation.
1170 ```compile_fail,E0283
1177 impl Generator for Impl {
1178 fn create() -> u32 { 1 }
1183 impl Generator for AnotherImpl {
1184 fn create() -> u32 { 2 }
1188 let cont: u32 = Generator::create();
1189 // error, impossible to choose one of Generator trait implementation
1190 // Should it be Impl or AnotherImpl, maybe something else?
1194 To resolve this error use the concrete type:
1203 impl Generator for AnotherImpl {
1204 fn create() -> u32 { 2 }
1208 let gen1 = AnotherImpl::create();
1210 // if there are multiple methods with same name (different traits)
1211 let gen2 = <AnotherImpl as Generator>::create();
1217 This error occurs when the compiler was unable to infer the concrete type of a
1218 variable. It can occur for several cases, the most common of which is a
1219 mismatch in the expected type that the compiler inferred for a variable's
1220 initializing expression, and the actual type explicitly assigned to the
1225 ```compile_fail,E0308
1226 let x: i32 = "I am not a number!";
1227 // ~~~ ~~~~~~~~~~~~~~~~~~~~
1229 // | initializing expression;
1230 // | compiler infers type `&str`
1232 // type `i32` assigned to variable `x`
1237 The type definition contains some field whose type
1238 requires an outlives annotation. Outlives annotations
1239 (e.g., `T: 'a`) are used to guarantee that all the data in T is valid
1240 for at least the lifetime `'a`. This scenario most commonly
1241 arises when the type contains an associated type reference
1242 like `<T as SomeTrait<'a>>::Output`, as shown in this example:
1244 ```compile_fail,E0309
1245 // This won't compile because the applicable impl of
1246 // `SomeTrait` (below) requires that `T: 'a`, but the struct does
1247 // not have a matching where-clause.
1249 foo: <T as SomeTrait<'a>>::Output,
1252 trait SomeTrait<'a> {
1256 impl<'a, T> SomeTrait<'a> for T
1264 Here, the where clause `T: 'a` that appears on the impl is not known to be
1265 satisfied on the struct. To make this example compile, you have to add
1266 a where-clause like `T: 'a` to the struct definition:
1273 foo: <T as SomeTrait<'a>>::Output
1276 trait SomeTrait<'a> {
1280 impl<'a, T> SomeTrait<'a> for T
1290 Types in type definitions have lifetimes associated with them that represent
1291 how long the data stored within them is guaranteed to be live. This lifetime
1292 must be as long as the data needs to be alive, and missing the constraint that
1293 denotes this will cause this error.
1295 ```compile_fail,E0310
1296 // This won't compile because T is not constrained to the static lifetime
1297 // the reference needs
1303 This will compile, because it has the constraint on the type parameter:
1306 struct Foo<T: 'static> {
1313 This error occurs when an `if` expression without an `else` block is used in a
1314 context where a type other than `()` is expected, for example a `let`
1317 ```compile_fail,E0317
1320 let a = if x == 5 { 1 };
1324 An `if` expression without an `else` block has the type `()`, so this is a type
1325 error. To resolve it, add an `else` block having the same type as the `if`
1330 This error indicates that some types or traits depend on each other
1331 and therefore cannot be constructed.
1333 The following example contains a circular dependency between two traits:
1335 ```compile_fail,E0391
1336 trait FirstTrait : SecondTrait {
1340 trait SecondTrait : FirstTrait {
1347 #### Note: this error code is no longer emitted by the compiler.
1349 In Rust 1.3, the default object lifetime bounds are expected to change, as
1350 described in [RFC 1156]. You are getting a warning because the compiler
1351 thinks it is possible that this change will cause a compilation error in your
1352 code. It is possible, though unlikely, that this is a false alarm.
1354 The heart of the change is that where `&'a Box<SomeTrait>` used to default to
1355 `&'a Box<SomeTrait+'a>`, it now defaults to `&'a Box<SomeTrait+'static>` (here,
1356 `SomeTrait` is the name of some trait type). Note that the only types which are
1357 affected are references to boxes, like `&Box<SomeTrait>` or
1358 `&[Box<SomeTrait>]`. More common types like `&SomeTrait` or `Box<SomeTrait>`
1361 To silence this warning, edit your code to use an explicit bound. Most of the
1362 time, this means that you will want to change the signature of a function that
1363 you are calling. For example, if the error is reported on a call like `foo(x)`,
1364 and `foo` is defined as follows:
1367 # trait SomeTrait {}
1368 fn foo(arg: &Box<SomeTrait>) { /* ... */ }
1371 You might change it to:
1374 # trait SomeTrait {}
1375 fn foo<'a>(arg: &'a Box<SomeTrait+'a>) { /* ... */ }
1378 This explicitly states that you expect the trait object `SomeTrait` to contain
1379 references (with a maximum lifetime of `'a`).
1381 [RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md
1385 An invalid lint attribute has been given. Erroneous code example:
1387 ```compile_fail,E0452
1388 #![allow(foo = "")] // error: malformed lint attribute
1391 Lint attributes only accept a list of identifiers (where each identifier is a
1392 lint name). Ensure the attribute is of this form:
1395 #![allow(foo)] // ok!
1397 #![allow(foo, foo2)] // ok!
1402 A lint check attribute was overruled by a `forbid` directive set as an
1403 attribute on an enclosing scope, or on the command line with the `-F` option.
1405 Example of erroneous code:
1407 ```compile_fail,E0453
1408 #![forbid(non_snake_case)]
1410 #[allow(non_snake_case)]
1412 let MyNumber = 2; // error: allow(non_snake_case) overruled by outer
1413 // forbid(non_snake_case)
1417 The `forbid` lint setting, like `deny`, turns the corresponding compiler
1418 warning into a hard error. Unlike `deny`, `forbid` prevents itself from being
1419 overridden by inner attributes.
1421 If you're sure you want to override the lint check, you can change `forbid` to
1422 `deny` (or use `-D` instead of `-F` if the `forbid` setting was given as a
1423 command-line option) to allow the inner lint check attribute:
1426 #![deny(non_snake_case)]
1428 #[allow(non_snake_case)]
1430 let MyNumber = 2; // ok!
1434 Otherwise, edit the code to pass the lint check, and remove the overruled
1438 #![forbid(non_snake_case)]
1447 A lifetime bound was not satisfied.
1449 Erroneous code example:
1451 ```compile_fail,E0478
1452 // Check that the explicit lifetime bound (`'SnowWhite`, in this example) must
1453 // outlive all the superbounds from the trait (`'kiss`, in this example).
1455 trait Wedding<'t>: 't { }
1457 struct Prince<'kiss, 'SnowWhite> {
1458 child: Box<Wedding<'kiss> + 'SnowWhite>,
1459 // error: lifetime bound not satisfied
1463 In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
1464 lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
1465 this issue, you need to specify it:
1468 trait Wedding<'t>: 't { }
1470 struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
1471 // longer than 'SnowWhite.
1472 child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
1478 A reference has a longer lifetime than the data it references.
1480 Erroneous code example:
1482 ```compile_fail,E0491
1483 trait SomeTrait<'a> {
1487 impl<'a, T> SomeTrait<'a> for T {
1488 type Output = &'a T; // compile error E0491
1492 Here, the problem is that a reference type like `&'a T` is only valid
1493 if all the data in T outlives the lifetime `'a`. But this impl as written
1494 is applicable to any lifetime `'a` and any type `T` -- we have no guarantee
1495 that `T` outlives `'a`. To fix this, you can add a where clause like
1499 trait SomeTrait<'a> {
1503 impl<'a, T> SomeTrait<'a> for T
1507 type Output = &'a T; // compile error E0491
1513 A lifetime name is shadowing another lifetime name. Erroneous code example:
1515 ```compile_fail,E0496
1521 fn f<'a>(x: &'a i32) { // error: lifetime name `'a` shadows a lifetime
1522 // name that is already in scope
1527 Please change the name of one of the lifetimes to remove this error. Example:
1535 fn f<'b>(x: &'b i32) { // ok!
1545 A stability attribute was used outside of the standard library. Erroneous code
1549 #[stable] // error: stability attributes may not be used outside of the
1554 It is not possible to use stability attributes outside of the standard library.
1555 Also, for now, it is not possible to write deprecation messages either.
1559 Transmute with two differently sized types was attempted. Erroneous code
1562 ```compile_fail,E0512
1563 fn takes_u8(_: u8) {}
1566 unsafe { takes_u8(::std::mem::transmute(0u16)); }
1567 // error: cannot transmute between types of different sizes,
1568 // or dependently-sized types
1572 Please use types with same size or use the expected type directly. Example:
1575 fn takes_u8(_: u8) {}
1578 unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
1580 unsafe { takes_u8(0u8); } // ok!
1586 This error indicates that a `#[repr(..)]` attribute was placed on an
1589 Examples of erroneous code:
1591 ```compile_fail,E0517
1599 struct Foo {bar: bool, baz: bool}
1607 * The `#[repr(C)]` attribute can only be placed on structs and enums.
1608 * The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs.
1609 * The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums.
1611 These attributes do not work on typedefs, since typedefs are just aliases.
1613 Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
1614 discriminant size for enums with no data fields on any of the variants, e.g.
1615 `enum Color {Red, Blue, Green}`, effectively setting the size of the enum to
1616 the size of the provided type. Such an enum can be cast to a value of the same
1617 type as well. In short, `#[repr(u8)]` makes the enum behave like an integer
1618 with a constrained set of allowed values.
1620 Only field-less enums can be cast to numerical primitives, so this attribute
1621 will not apply to structs.
1623 `#[repr(packed)]` reduces padding to make the struct size smaller. The
1624 representation of enums isn't strictly defined in Rust, and this attribute
1625 won't work on enums.
1627 `#[repr(simd)]` will give a struct consisting of a homogeneous series of machine
1628 types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via
1629 SIMD. This doesn't make much sense for enums since they don't consist of a
1630 single list of data.
1634 This error indicates that an `#[inline(..)]` attribute was incorrectly placed
1635 on something other than a function or method.
1637 Examples of erroneous code:
1639 ```compile_fail,E0518
1649 `#[inline]` hints the compiler whether or not to attempt to inline a method or
1650 function. By default, the compiler does a pretty good job of figuring this out
1651 itself, but if you feel the need for annotations, `#[inline(always)]` and
1652 `#[inline(never)]` can override or force the compiler's decision.
1654 If you wish to apply this attribute to all methods in an impl, manually annotate
1655 each method; it is not possible to annotate the entire impl with an `#[inline]`
1660 The lang attribute is intended for marking special items that are built-in to
1661 Rust itself. This includes special traits (like `Copy` and `Sized`) that affect
1662 how the compiler behaves, as well as special functions that may be automatically
1663 invoked (such as the handler for out-of-bounds accesses when indexing a slice).
1664 Erroneous code example:
1666 ```compile_fail,E0522
1667 #![feature(lang_items)]
1670 fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
1677 A closure was used but didn't implement the expected trait.
1679 Erroneous code example:
1681 ```compile_fail,E0525
1685 fn bar<T: Fn(u32)>(_: T) {}
1689 let closure = |_| foo(x); // error: expected a closure that implements
1690 // the `Fn` trait, but this closure only
1691 // implements `FnOnce`
1696 In the example above, `closure` is an `FnOnce` closure whereas the `bar`
1697 function expected an `Fn` closure. In this case, it's simple to fix the issue,
1698 you just have to implement `Copy` and `Clone` traits on `struct X` and it'll
1702 #[derive(Clone, Copy)] // We implement `Clone` and `Copy` traits.
1706 fn bar<T: Fn(u32)>(_: T) {}
1710 let closure = |_| foo(x);
1711 bar(closure); // ok!
1715 To understand better how closures work in Rust, read:
1716 https://doc.rust-lang.org/book/first-edition/closures.html
1720 The `main` function was incorrectly declared.
1722 Erroneous code example:
1724 ```compile_fail,E0580
1725 fn main(x: i32) { // error: main function has wrong type
1730 The `main` function prototype should never take arguments.
1739 If you want to get command-line arguments, use `std::env::args`. To exit with a
1740 specified exit code, use `std::process::exit`.
1744 Abstract return types (written `impl Trait` for some trait `Trait`) are only
1745 allowed as function and inherent impl return types.
1747 Erroneous code example:
1749 ```compile_fail,E0562
1751 let count_to_ten: impl Iterator<Item=usize> = 0..10;
1752 // error: `impl Trait` not allowed outside of function and inherent method
1754 for i in count_to_ten {
1760 Make sure `impl Trait` only appears in return-type position.
1763 fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
1768 for i in count_to_n(10) { // ok!
1774 See [RFC 1522] for more details.
1776 [RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
1780 Per [RFC 401][rfc401], if you have a function declaration `foo`:
1783 // For the purposes of this explanation, all of these
1784 // different kinds of `fn` declarations are equivalent:
1786 fn foo(x: S) { /* ... */ }
1787 # #[cfg(for_demonstration_only)]
1788 extern "C" { fn foo(x: S); }
1789 # #[cfg(for_demonstration_only)]
1790 impl S { fn foo(self) { /* ... */ } }
1793 the type of `foo` is **not** `fn(S)`, as one might expect.
1794 Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`.
1795 However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,
1796 so you rarely notice this:
1801 let x: fn(S) = foo; // OK, coerces
1804 The reason that this matter is that the type `fn(S)` is not specific to
1805 any particular function: it's a function _pointer_. So calling `x()` results
1806 in a virtual call, whereas `foo()` is statically dispatched, because the type
1807 of `foo` tells us precisely what function is being called.
1809 As noted above, coercions mean that most code doesn't have to be
1810 concerned with this distinction. However, you can tell the difference
1811 when using **transmute** to convert a fn item into a fn pointer.
1813 This is sometimes done as part of an FFI:
1815 ```compile_fail,E0591
1816 extern "C" fn foo(userdata: Box<i32>) {
1820 # fn callback(_: extern "C" fn(*mut i32)) {}
1821 # use std::mem::transmute;
1823 let f: extern "C" fn(*mut i32) = transmute(foo);
1828 Here, transmute is being used to convert the types of the fn arguments.
1829 This pattern is incorrect because, because the type of `foo` is a function
1830 **item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
1831 is a function pointer, which is not zero-sized.
1832 This pattern should be rewritten. There are a few possible ways to do this:
1834 - change the original fn declaration to match the expected signature,
1835 and do the cast in the fn body (the preferred option)
1836 - cast the fn item fo a fn pointer before calling transmute, as shown here:
1839 # extern "C" fn foo(_: Box<i32>) {}
1840 # use std::mem::transmute;
1842 let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
1843 let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
1847 The same applies to transmutes to `*mut fn()`, which were observedin practice.
1848 Note though that use of this type is generally incorrect.
1849 The intention is typically to describe a function pointer, but just `fn()`
1850 alone suffices for that. `*mut fn()` is a pointer to a fn pointer.
1851 (Since these values are typically just passed to C code, however, this rarely
1852 makes a difference in practice.)
1854 [rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1858 You tried to supply an `Fn`-based type with an incorrect number of arguments
1859 than what was expected.
1861 Erroneous code example:
1863 ```compile_fail,E0593
1864 fn foo<F: Fn()>(x: F) { }
1867 // [E0593] closure takes 1 argument but 0 arguments are required
1874 No `main` function was found in a binary crate. To fix this error, add a
1875 `main` function. For example:
1879 // Your program will start here.
1880 println!("Hello world!");
1884 If you don't know the basics of Rust, you can go look to the Rust Book to get
1885 started: https://doc.rust-lang.org/book/
1889 An unknown lint was used on the command line.
1894 rustc -D bogus omse_file.rs
1897 Maybe you just misspelled the lint name or the lint doesn't exist anymore.
1898 Either way, try to update/remove it in order to fix the error.
1902 This error code indicates a mismatch between the lifetimes appearing in the
1903 function signature (i.e., the parameter types and the return type) and the
1904 data-flow found in the function body.
1906 Erroneous code example:
1908 ```compile_fail,E0621
1909 fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 { // error: explicit lifetime
1910 // required in the type of
1912 if x > y { x } else { y }
1916 In the code above, the function is returning data borrowed from either `x` or
1917 `y`, but the `'a` annotation indicates that it is returning data only from `x`.
1918 To fix the error, the signature and the body must be made to match. Typically,
1919 this is done by updating the function signature. So, in this case, we change
1920 the type of `y` to `&'a i32`, like so:
1923 fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
1924 if x > y { x } else { y }
1928 Now the signature indicates that the function data borrowed from either `x` or
1929 `y`. Alternatively, you could change the body to not return data from `y`:
1932 fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
1939 The `#![feature]` attribute specified an unknown feature.
1941 Erroneous code example:
1943 ```compile_fail,E0635
1944 #![feature(nonexistent_rust_feature)] // error: unknown feature
1950 A `#![feature]` attribute was declared multiple times.
1952 Erroneous code example:
1954 ```compile_fail,E0636
1955 #![allow(stable_features)]
1957 #![feature(rust1)] // error: the feature `rust1` has already been declared
1963 A closure or generator was constructed that references its own type.
1967 ```compile-fail,E0644
1976 // Here, when `x` is called, the parameter `y` is equal to `x`.
1981 Rust does not permit a closure to directly reference its own type,
1982 either through an argument (as in the example above) or by capturing
1983 itself through its environment. This restriction helps keep closure
1984 inference tractable.
1986 The easiest fix is to rewrite your closure into a top-level function,
1987 or into a method. In some cases, you may also be able to have your
1988 closure call itself by capturing a `&Fn()` object or `fn()` pointer
1989 that refers to itself. That is permitting, since the closure would be
1990 invoking itself via a virtual call, and hence does not directly
1991 reference its own *type*.
1996 A `repr(transparent)` type was also annotated with other, incompatible
1997 representation hints.
1999 Erroneous code example:
2001 ```compile_fail,E0692
2002 #[repr(transparent, C)] // error: incompatible representation hints
2006 A type annotated as `repr(transparent)` delegates all representation concerns to
2007 another type, so adding more representation hints is contradictory. Remove
2008 either the `transparent` hint or the other hints, like this:
2011 #[repr(transparent)]
2015 Alternatively, move the other attributes to the contained type:
2024 #[repr(transparent)]
2025 struct FooWrapper(Foo);
2028 Note that introducing another `struct` just to have a place for the other
2029 attributes may have unintended side effects on the representation:
2032 #[repr(transparent)]
2038 #[repr(transparent)]
2039 struct Grams2(Float); // this is not equivalent to `Grams` above
2042 Here, `Grams2` is a not equivalent to `Grams` -- the former transparently wraps
2043 a (non-transparent) struct containing a single float, while `Grams` is a
2044 transparent wrapper around a float. This can make a difference for the ABI.
2048 The `impl Trait` return type captures lifetime parameters that do not
2049 appear within the `impl Trait` itself.
2051 Erroneous code example:
2053 ```compile-fail,E0700
2054 use std::cell::Cell;
2058 impl<'a, 'b> Trait<'b> for Cell<&'a u32> { }
2060 fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
2067 Here, the function `foo` returns a value of type `Cell<&'x u32>`,
2068 which references the lifetime `'x`. However, the return type is
2069 declared as `impl Trait<'y>` -- this indicates that `foo` returns
2070 "some type that implements `Trait<'y>`", but it also indicates that
2071 the return type **only captures data referencing the lifetime `'y`**.
2072 In this case, though, we are referencing data with lifetime `'x`, so
2073 this function is in error.
2075 To fix this, you must reference the lifetime `'x` from the return
2076 type. For example, changing the return type to `impl Trait<'y> + 'x`
2080 use std::cell::Cell;
2084 impl<'a,'b> Trait<'b> for Cell<&'a u32> { }
2086 fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + 'x
2095 This error indicates that a `#[non_exhaustive]` attribute was incorrectly placed
2096 on something other than a struct or enum.
2098 Examples of erroneous code:
2100 ```compile_fail,E0701
2101 # #![feature(non_exhaustive)]
2109 This error indicates that a `#[lang = ".."]` attribute was placed
2110 on the wrong type of item.
2112 Examples of erroneous code:
2114 ```compile_fail,E0718
2115 #![feature(lang_items)]
2125 register_diagnostics! {
2126 // E0006, // merged with E0005
2127 // E0101, // replaced with E0282
2128 // E0102, // replaced with E0282
2131 // E0272, // on_unimplemented #0
2132 // E0273, // on_unimplemented #1
2133 // E0274, // on_unimplemented #2
2134 E0278, // requirement is not satisfied
2135 E0279, // requirement is not satisfied
2136 E0280, // requirement is not satisfied
2137 E0284, // cannot resolve type
2138 // E0285, // overflow evaluation builtin bounds
2139 // E0296, // replaced with a generic attribute input check
2140 // E0300, // unexpanded macro
2141 // E0304, // expected signed integer constant
2142 // E0305, // expected constant
2143 E0311, // thing may not live long enough
2144 E0312, // lifetime of reference outlives lifetime of borrowed content
2145 E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
2146 E0314, // closure outlives stack frame
2147 E0315, // cannot invoke closure outside of its lifetime
2148 E0316, // nested quantification of lifetimes
2149 E0320, // recursive overflow during dropck
2150 E0473, // dereference of reference outside its lifetime
2151 E0474, // captured variable `..` does not outlive the enclosing closure
2152 E0475, // index of slice outside its lifetime
2153 E0476, // lifetime of the source pointer does not outlive lifetime bound...
2154 E0477, // the type `..` does not fulfill the required lifetime...
2155 E0479, // the type `..` (provided as the value of a type parameter) is...
2156 E0480, // lifetime of method receiver does not outlive the method call
2157 E0481, // lifetime of function argument does not outlive the function call
2158 E0482, // lifetime of return value does not outlive the function call
2159 E0483, // lifetime of operand does not outlive the operation
2160 E0484, // reference is not valid at the time of borrow
2161 E0485, // automatically reference is not valid at the time of borrow
2162 E0486, // type of expression contains references that are not valid during...
2163 E0487, // unsafe use of destructor: destructor might be called while...
2164 E0488, // lifetime of variable does not enclose its declaration
2165 E0489, // type/lifetime parameter not in scope here
2166 E0490, // a value of type `..` is borrowed for too long
2167 E0495, // cannot infer an appropriate lifetime due to conflicting requirements
2168 E0566, // conflicting representation hints
2169 E0623, // lifetime mismatch where both parameters are anonymous regions
2170 E0628, // generators cannot have explicit arguments
2171 E0631, // type mismatch in closure arguments
2172 E0637, // "'_" is not a valid lifetime bound
2173 E0657, // `impl Trait` can only capture lifetimes bound at the fn level
2174 E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
2175 E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
2176 E0697, // closures cannot be static
2177 E0707, // multiple elided lifetimes used in arguments of `async fn`
2178 E0708, // `async` non-`move` closures with arguments are not currently supported
2179 E0709, // multiple different lifetimes used in arguments of `async fn`
2180 E0710, // an unknown tool name found in scoped lint
2181 E0711, // a feature has been declared with conflicting stability attributes
2182 // E0702, // replaced with a generic attribute input check