]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/error_codes.rs
Rollup merge of #64763 - GuillaumeGomez:long-err-explanation-E0734, r=estebank
[rust.git] / src / librustc_typeck / error_codes.rs
1 // ignore-tidy-filelength
2
3 syntax::register_diagnostics! {
4
5 E0023: r##"
6 A pattern used to match against an enum variant must provide a sub-pattern for
7 each field of the enum variant. This error indicates that a pattern attempted to
8 extract an incorrect number of fields from a variant.
9
10 ```
11 enum Fruit {
12     Apple(String, String),
13     Pear(u32),
14 }
15 ```
16
17 Here the `Apple` variant has two fields, and should be matched against like so:
18
19 ```
20 enum Fruit {
21     Apple(String, String),
22     Pear(u32),
23 }
24
25 let x = Fruit::Apple(String::new(), String::new());
26
27 // Correct.
28 match x {
29     Fruit::Apple(a, b) => {},
30     _ => {}
31 }
32 ```
33
34 Matching with the wrong number of fields has no sensible interpretation:
35
36 ```compile_fail,E0023
37 enum Fruit {
38     Apple(String, String),
39     Pear(u32),
40 }
41
42 let x = Fruit::Apple(String::new(), String::new());
43
44 // Incorrect.
45 match x {
46     Fruit::Apple(a) => {},
47     Fruit::Apple(a, b, c) => {},
48 }
49 ```
50
51 Check how many fields the enum was declared with and ensure that your pattern
52 uses the same number.
53 "##,
54
55 E0025: r##"
56 Each field of a struct can only be bound once in a pattern. Erroneous code
57 example:
58
59 ```compile_fail,E0025
60 struct Foo {
61     a: u8,
62     b: u8,
63 }
64
65 fn main(){
66     let x = Foo { a:1, b:2 };
67
68     let Foo { a: x, a: y } = x;
69     // error: field `a` bound multiple times in the pattern
70 }
71 ```
72
73 Each occurrence of a field name binds the value of that field, so to fix this
74 error you will have to remove or alter the duplicate uses of the field name.
75 Perhaps you misspelled another field name? Example:
76
77 ```
78 struct Foo {
79     a: u8,
80     b: u8,
81 }
82
83 fn main(){
84     let x = Foo { a:1, b:2 };
85
86     let Foo { a: x, b: y } = x; // ok!
87 }
88 ```
89 "##,
90
91 E0026: r##"
92 This error indicates that a struct pattern attempted to extract a non-existent
93 field from a struct. Struct fields are identified by the name used before the
94 colon `:` so struct patterns should resemble the declaration of the struct type
95 being matched.
96
97 ```
98 // Correct matching.
99 struct Thing {
100     x: u32,
101     y: u32
102 }
103
104 let thing = Thing { x: 1, y: 2 };
105
106 match thing {
107     Thing { x: xfield, y: yfield } => {}
108 }
109 ```
110
111 If you are using shorthand field patterns but want to refer to the struct field
112 by a different name, you should rename it explicitly.
113
114 Change this:
115
116 ```compile_fail,E0026
117 struct Thing {
118     x: u32,
119     y: u32
120 }
121
122 let thing = Thing { x: 0, y: 0 };
123
124 match thing {
125     Thing { x, z } => {}
126 }
127 ```
128
129 To this:
130
131 ```
132 struct Thing {
133     x: u32,
134     y: u32
135 }
136
137 let thing = Thing { x: 0, y: 0 };
138
139 match thing {
140     Thing { x, y: z } => {}
141 }
142 ```
143 "##,
144
145 E0027: r##"
146 This error indicates that a pattern for a struct fails to specify a sub-pattern
147 for every one of the struct's fields. Ensure that each field from the struct's
148 definition is mentioned in the pattern, or use `..` to ignore unwanted fields.
149
150 For example:
151
152 ```compile_fail,E0027
153 struct Dog {
154     name: String,
155     age: u32,
156 }
157
158 let d = Dog { name: "Rusty".to_string(), age: 8 };
159
160 // This is incorrect.
161 match d {
162     Dog { age: x } => {}
163 }
164 ```
165
166 This is correct (explicit):
167
168 ```
169 struct Dog {
170     name: String,
171     age: u32,
172 }
173
174 let d = Dog { name: "Rusty".to_string(), age: 8 };
175
176 match d {
177     Dog { name: ref n, age: x } => {}
178 }
179
180 // This is also correct (ignore unused fields).
181 match d {
182     Dog { age: x, .. } => {}
183 }
184 ```
185 "##,
186
187 E0029: r##"
188 In a match expression, only numbers and characters can be matched against a
189 range. This is because the compiler checks that the range is non-empty at
190 compile-time, and is unable to evaluate arbitrary comparison functions. If you
191 want to capture values of an orderable type between two end-points, you can use
192 a guard.
193
194 ```compile_fail,E0029
195 let string = "salutations !";
196
197 // The ordering relation for strings can't be evaluated at compile time,
198 // so this doesn't work:
199 match string {
200     "hello" ..= "world" => {}
201     _ => {}
202 }
203
204 // This is a more general version, using a guard:
205 match string {
206     s if s >= "hello" && s <= "world" => {}
207     _ => {}
208 }
209 ```
210 "##,
211
212 E0033: r##"
213 This error indicates that a pointer to a trait type cannot be implicitly
214 dereferenced by a pattern. Every trait defines a type, but because the
215 size of trait implementers isn't fixed, this type has no compile-time size.
216 Therefore, all accesses to trait types must be through pointers. If you
217 encounter this error you should try to avoid dereferencing the pointer.
218
219 ```compile_fail,E0033
220 # trait SomeTrait { fn method_one(&self){} fn method_two(&self){} }
221 # impl<T> SomeTrait for T {}
222 let trait_obj: &SomeTrait = &"some_value";
223
224 // This tries to implicitly dereference to create an unsized local variable.
225 let &invalid = trait_obj;
226
227 // You can call methods without binding to the value being pointed at.
228 trait_obj.method_one();
229 trait_obj.method_two();
230 ```
231
232 You can read more about trait objects in the [Trait Objects] section of the
233 Reference.
234
235 [Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects
236 "##,
237
238 E0034: r##"
239 The compiler doesn't know what method to call because more than one method
240 has the same prototype. Erroneous code example:
241
242 ```compile_fail,E0034
243 struct Test;
244
245 trait Trait1 {
246     fn foo();
247 }
248
249 trait Trait2 {
250     fn foo();
251 }
252
253 impl Trait1 for Test { fn foo() {} }
254 impl Trait2 for Test { fn foo() {} }
255
256 fn main() {
257     Test::foo() // error, which foo() to call?
258 }
259 ```
260
261 To avoid this error, you have to keep only one of them and remove the others.
262 So let's take our example and fix it:
263
264 ```
265 struct Test;
266
267 trait Trait1 {
268     fn foo();
269 }
270
271 impl Trait1 for Test { fn foo() {} }
272
273 fn main() {
274     Test::foo() // and now that's good!
275 }
276 ```
277
278 However, a better solution would be using fully explicit naming of type and
279 trait:
280
281 ```
282 struct Test;
283
284 trait Trait1 {
285     fn foo();
286 }
287
288 trait Trait2 {
289     fn foo();
290 }
291
292 impl Trait1 for Test { fn foo() {} }
293 impl Trait2 for Test { fn foo() {} }
294
295 fn main() {
296     <Test as Trait1>::foo()
297 }
298 ```
299
300 One last example:
301
302 ```
303 trait F {
304     fn m(&self);
305 }
306
307 trait G {
308     fn m(&self);
309 }
310
311 struct X;
312
313 impl F for X { fn m(&self) { println!("I am F"); } }
314 impl G for X { fn m(&self) { println!("I am G"); } }
315
316 fn main() {
317     let f = X;
318
319     F::m(&f); // it displays "I am F"
320     G::m(&f); // it displays "I am G"
321 }
322 ```
323 "##,
324
325 E0040: r##"
326 It is not allowed to manually call destructors in Rust. It is also not
327 necessary to do this since `drop` is called automatically whenever a value goes
328 out of scope.
329
330 Here's an example of this error:
331
332 ```compile_fail,E0040
333 struct Foo {
334     x: i32,
335 }
336
337 impl Drop for Foo {
338     fn drop(&mut self) {
339         println!("kaboom");
340     }
341 }
342
343 fn main() {
344     let mut x = Foo { x: -7 };
345     x.drop(); // error: explicit use of destructor method
346 }
347 ```
348 "##,
349
350 E0044: r##"
351 You can't use type or const parameters on foreign items.
352 Example of erroneous code:
353
354 ```compile_fail,E0044
355 extern { fn some_func<T>(x: T); }
356 ```
357
358 To fix this, replace the generic parameter with the specializations that you
359 need:
360
361 ```
362 extern { fn some_func_i32(x: i32); }
363 extern { fn some_func_i64(x: i64); }
364 ```
365 "##,
366
367 E0045: r##"
368 Rust only supports variadic parameters for interoperability with C code in its
369 FFI. As such, variadic parameters can only be used with functions which are
370 using the C ABI. Examples of erroneous code:
371
372 ```compile_fail
373 #![feature(unboxed_closures)]
374
375 extern "rust-call" { fn foo(x: u8, ...); }
376
377 // or
378
379 fn foo(x: u8, ...) {}
380 ```
381
382 To fix such code, put them in an extern "C" block:
383
384 ```
385 extern "C" {
386     fn foo (x: u8, ...);
387 }
388 ```
389 "##,
390
391 E0046: r##"
392 Items are missing in a trait implementation. Erroneous code example:
393
394 ```compile_fail,E0046
395 trait Foo {
396     fn foo();
397 }
398
399 struct Bar;
400
401 impl Foo for Bar {}
402 // error: not all trait items implemented, missing: `foo`
403 ```
404
405 When trying to make some type implement a trait `Foo`, you must, at minimum,
406 provide implementations for all of `Foo`'s required methods (meaning the
407 methods that do not have default implementations), as well as any required
408 trait items like associated types or constants. Example:
409
410 ```
411 trait Foo {
412     fn foo();
413 }
414
415 struct Bar;
416
417 impl Foo for Bar {
418     fn foo() {} // ok!
419 }
420 ```
421 "##,
422
423 E0049: r##"
424 This error indicates that an attempted implementation of a trait method
425 has the wrong number of type or const parameters.
426
427 For example, the trait below has a method `foo` with a type parameter `T`,
428 but the implementation of `foo` for the type `Bar` is missing this parameter:
429
430 ```compile_fail,E0049
431 trait Foo {
432     fn foo<T: Default>(x: T) -> Self;
433 }
434
435 struct Bar;
436
437 // error: method `foo` has 0 type parameters but its trait declaration has 1
438 // type parameter
439 impl Foo for Bar {
440     fn foo(x: bool) -> Self { Bar }
441 }
442 ```
443 "##,
444
445 E0050: r##"
446 This error indicates that an attempted implementation of a trait method
447 has the wrong number of function parameters.
448
449 For example, the trait below has a method `foo` with two function parameters
450 (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
451 the `u8` parameter:
452
453 ```compile_fail,E0050
454 trait Foo {
455     fn foo(&self, x: u8) -> bool;
456 }
457
458 struct Bar;
459
460 // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
461 // has 2
462 impl Foo for Bar {
463     fn foo(&self) -> bool { true }
464 }
465 ```
466 "##,
467
468 E0053: r##"
469 The parameters of any trait method must match between a trait implementation
470 and the trait definition.
471
472 Here are a couple examples of this error:
473
474 ```compile_fail,E0053
475 trait Foo {
476     fn foo(x: u16);
477     fn bar(&self);
478 }
479
480 struct Bar;
481
482 impl Foo for Bar {
483     // error, expected u16, found i16
484     fn foo(x: i16) { }
485
486     // error, types differ in mutability
487     fn bar(&mut self) { }
488 }
489 ```
490 "##,
491
492 E0054: r##"
493 It is not allowed to cast to a bool. If you are trying to cast a numeric type
494 to a bool, you can compare it with zero instead:
495
496 ```compile_fail,E0054
497 let x = 5;
498
499 // Not allowed, won't compile
500 let x_is_nonzero = x as bool;
501 ```
502
503 ```
504 let x = 5;
505
506 // Ok
507 let x_is_nonzero = x != 0;
508 ```
509 "##,
510
511 E0055: r##"
512 During a method call, a value is automatically dereferenced as many times as
513 needed to make the value's type match the method's receiver. The catch is that
514 the compiler will only attempt to dereference a number of times up to the
515 recursion limit (which can be set via the `recursion_limit` attribute).
516
517 For a somewhat artificial example:
518
519 ```compile_fail,E0055
520 #![recursion_limit="5"]
521
522 struct Foo;
523
524 impl Foo {
525     fn foo(&self) {}
526 }
527
528 fn main() {
529     let foo = Foo;
530     let ref_foo = &&&&&Foo;
531
532     // error, reached the recursion limit while auto-dereferencing `&&&&&Foo`
533     ref_foo.foo();
534 }
535 ```
536
537 One fix may be to increase the recursion limit. Note that it is possible to
538 create an infinite recursion of dereferencing, in which case the only fix is to
539 somehow break the recursion.
540 "##,
541
542 E0057: r##"
543 When invoking closures or other implementations of the function traits `Fn`,
544 `FnMut` or `FnOnce` using call notation, the number of parameters passed to the
545 function must match its definition.
546
547 An example using a closure:
548
549 ```compile_fail,E0057
550 let f = |x| x * 3;
551 let a = f();        // invalid, too few parameters
552 let b = f(4);       // this works!
553 let c = f(2, 3);    // invalid, too many parameters
554 ```
555
556 A generic function must be treated similarly:
557
558 ```
559 fn foo<F: Fn()>(f: F) {
560     f(); // this is valid, but f(3) would not work
561 }
562 ```
563 "##,
564
565 E0059: r##"
566 The built-in function traits are generic over a tuple of the function arguments.
567 If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
568 (`Fn(T) -> U`) to denote the function trait, the type parameter should be a
569 tuple. Otherwise function call notation cannot be used and the trait will not be
570 implemented by closures.
571
572 The most likely source of this error is using angle-bracket notation without
573 wrapping the function argument type into a tuple, for example:
574
575 ```compile_fail,E0059
576 #![feature(unboxed_closures)]
577
578 fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
579 ```
580
581 It can be fixed by adjusting the trait bound like this:
582
583 ```
584 #![feature(unboxed_closures)]
585
586 fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
587 ```
588
589 Note that `(T,)` always denotes the type of a 1-tuple containing an element of
590 type `T`. The comma is necessary for syntactic disambiguation.
591 "##,
592
593 E0060: r##"
594 External C functions are allowed to be variadic. However, a variadic function
595 takes a minimum number of arguments. For example, consider C's variadic `printf`
596 function:
597
598 ```
599 use std::os::raw::{c_char, c_int};
600
601 extern "C" {
602     fn printf(_: *const c_char, ...) -> c_int;
603 }
604 ```
605
606 Using this declaration, it must be called with at least one argument, so
607 simply calling `printf()` is invalid. But the following uses are allowed:
608
609 ```
610 # #![feature(static_nobundle)]
611 # use std::os::raw::{c_char, c_int};
612 # #[cfg_attr(all(windows, target_env = "msvc"),
613 #            link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
614 # extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
615 # fn main() {
616 unsafe {
617     use std::ffi::CString;
618
619     let fmt = CString::new("test\n").unwrap();
620     printf(fmt.as_ptr());
621
622     let fmt = CString::new("number = %d\n").unwrap();
623     printf(fmt.as_ptr(), 3);
624
625     let fmt = CString::new("%d, %d\n").unwrap();
626     printf(fmt.as_ptr(), 10, 5);
627 }
628 # }
629 ```
630 "##,
631 // ^ Note: On MSVC 2015, the `printf` function is "inlined" in the C code, and
632 // the C runtime does not contain the `printf` definition. This leads to linker
633 // error from the doc test (issue #42830).
634 // This can be fixed by linking to the static library
635 // `legacy_stdio_definitions.lib` (see https://stackoverflow.com/a/36504365/).
636 // If this compatibility library is removed in the future, consider changing
637 // `printf` in this example to another well-known variadic function.
638
639 E0061: r##"
640 The number of arguments passed to a function must match the number of arguments
641 specified in the function signature.
642
643 For example, a function like:
644
645 ```
646 fn f(a: u16, b: &str) {}
647 ```
648
649 Must always be called with exactly two arguments, e.g., `f(2, "test")`.
650
651 Note that Rust does not have a notion of optional function arguments or
652 variadic functions (except for its C-FFI).
653 "##,
654
655 E0062: r##"
656 This error indicates that during an attempt to build a struct or struct-like
657 enum variant, one of the fields was specified more than once. Erroneous code
658 example:
659
660 ```compile_fail,E0062
661 struct Foo {
662     x: i32,
663 }
664
665 fn main() {
666     let x = Foo {
667                 x: 0,
668                 x: 0, // error: field `x` specified more than once
669             };
670 }
671 ```
672
673 Each field should be specified exactly one time. Example:
674
675 ```
676 struct Foo {
677     x: i32,
678 }
679
680 fn main() {
681     let x = Foo { x: 0 }; // ok!
682 }
683 ```
684 "##,
685
686 E0063: r##"
687 This error indicates that during an attempt to build a struct or struct-like
688 enum variant, one of the fields was not provided. Erroneous code example:
689
690 ```compile_fail,E0063
691 struct Foo {
692     x: i32,
693     y: i32,
694 }
695
696 fn main() {
697     let x = Foo { x: 0 }; // error: missing field: `y`
698 }
699 ```
700
701 Each field should be specified exactly once. Example:
702
703 ```
704 struct Foo {
705     x: i32,
706     y: i32,
707 }
708
709 fn main() {
710     let x = Foo { x: 0, y: 0 }; // ok!
711 }
712 ```
713 "##,
714
715 E0067: r##"
716 The left-hand side of a compound assignment expression must be a place
717 expression. A place expression represents a memory location and includes
718 item paths (ie, namespaced variables), dereferences, indexing expressions,
719 and field references.
720
721 Let's start with some erroneous code examples:
722
723 ```compile_fail,E0067
724 use std::collections::LinkedList;
725
726 // Bad: assignment to non-place expression
727 LinkedList::new() += 1;
728
729 // ...
730
731 fn some_func(i: &mut i32) {
732     i += 12; // Error : '+=' operation cannot be applied on a reference !
733 }
734 ```
735
736 And now some working examples:
737
738 ```
739 let mut i : i32 = 0;
740
741 i += 12; // Good !
742
743 // ...
744
745 fn some_func(i: &mut i32) {
746     *i += 12; // Good !
747 }
748 ```
749 "##,
750
751 E0069: r##"
752 The compiler found a function whose body contains a `return;` statement but
753 whose return type is not `()`. An example of this is:
754
755 ```compile_fail,E0069
756 // error
757 fn foo() -> u8 {
758     return;
759 }
760 ```
761
762 Since `return;` is just like `return ();`, there is a mismatch between the
763 function's return type and the value being returned.
764 "##,
765
766 E0070: r##"
767 The left-hand side of an assignment operator must be a place expression. A
768 place expression represents a memory location and can be a variable (with
769 optional namespacing), a dereference, an indexing expression or a field
770 reference.
771
772 More details can be found in the [Expressions] section of the Reference.
773
774 [Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
775
776 Now, we can go further. Here are some erroneous code examples:
777
778 ```compile_fail,E0070
779 struct SomeStruct {
780     x: i32,
781     y: i32
782 }
783
784 const SOME_CONST : i32 = 12;
785
786 fn some_other_func() {}
787
788 fn some_function() {
789     SOME_CONST = 14; // error : a constant value cannot be changed!
790     1 = 3; // error : 1 isn't a valid place!
791     some_other_func() = 4; // error : we can't assign value to a function!
792     SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
793                        // like a variable!
794 }
795 ```
796
797 And now let's give working examples:
798
799 ```
800 struct SomeStruct {
801     x: i32,
802     y: i32
803 }
804 let mut s = SomeStruct {x: 0, y: 0};
805
806 s.x = 3; // that's good !
807
808 // ...
809
810 fn some_func(x: &mut i32) {
811     *x = 12; // that's good !
812 }
813 ```
814 "##,
815
816 E0071: r##"
817 You tried to use structure-literal syntax to create an item that is
818 not a structure or enum variant.
819
820 Example of erroneous code:
821
822 ```compile_fail,E0071
823 type U32 = u32;
824 let t = U32 { value: 4 }; // error: expected struct, variant or union type,
825                           // found builtin type `u32`
826 ```
827
828 To fix this, ensure that the name was correctly spelled, and that
829 the correct form of initializer was used.
830
831 For example, the code above can be fixed to:
832
833 ```
834 enum Foo {
835     FirstValue(i32)
836 }
837
838 fn main() {
839     let u = Foo::FirstValue(0i32);
840
841     let t = 4;
842 }
843 ```
844 "##,
845
846 E0073: r##"
847 #### Note: this error code is no longer emitted by the compiler.
848
849 You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
850 in order to make a new `Foo` value. This is because there would be no way a
851 first instance of `Foo` could be made to initialize another instance!
852
853 Here's an example of a struct that has this problem:
854
855 ```
856 struct Foo { x: Box<Foo> } // error
857 ```
858
859 One fix is to use `Option`, like so:
860
861 ```
862 struct Foo { x: Option<Box<Foo>> }
863 ```
864
865 Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
866 "##,
867
868 E0074: r##"
869 #### Note: this error code is no longer emitted by the compiler.
870
871 When using the `#[simd]` attribute on a tuple struct, the components of the
872 tuple struct must all be of a concrete, nongeneric type so the compiler can
873 reason about how to use SIMD with them. This error will occur if the types
874 are generic.
875
876 This will cause an error:
877
878 ```
879 #![feature(repr_simd)]
880
881 #[repr(simd)]
882 struct Bad<T>(T, T, T);
883 ```
884
885 This will not:
886
887 ```
888 #![feature(repr_simd)]
889
890 #[repr(simd)]
891 struct Good(u32, u32, u32);
892 ```
893 "##,
894
895 E0075: r##"
896 The `#[simd]` attribute can only be applied to non empty tuple structs, because
897 it doesn't make sense to try to use SIMD operations when there are no values to
898 operate on.
899
900 This will cause an error:
901
902 ```compile_fail,E0075
903 #![feature(repr_simd)]
904
905 #[repr(simd)]
906 struct Bad;
907 ```
908
909 This will not:
910
911 ```
912 #![feature(repr_simd)]
913
914 #[repr(simd)]
915 struct Good(u32);
916 ```
917 "##,
918
919 E0076: r##"
920 When using the `#[simd]` attribute to automatically use SIMD operations in tuple
921 struct, the types in the struct must all be of the same type, or the compiler
922 will trigger this error.
923
924 This will cause an error:
925
926 ```compile_fail,E0076
927 #![feature(repr_simd)]
928
929 #[repr(simd)]
930 struct Bad(u16, u32, u32);
931 ```
932
933 This will not:
934
935 ```
936 #![feature(repr_simd)]
937
938 #[repr(simd)]
939 struct Good(u32, u32, u32);
940 ```
941 "##,
942
943 E0077: r##"
944 When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
945 must be machine types so SIMD operations can be applied to them.
946
947 This will cause an error:
948
949 ```compile_fail,E0077
950 #![feature(repr_simd)]
951
952 #[repr(simd)]
953 struct Bad(String);
954 ```
955
956 This will not:
957
958 ```
959 #![feature(repr_simd)]
960
961 #[repr(simd)]
962 struct Good(u32, u32, u32);
963 ```
964 "##,
965
966 E0081: r##"
967 Enum discriminants are used to differentiate enum variants stored in memory.
968 This error indicates that the same value was used for two or more variants,
969 making them impossible to tell apart.
970
971 ```compile_fail,E0081
972 // Bad.
973 enum Enum {
974     P = 3,
975     X = 3,
976     Y = 5,
977 }
978 ```
979
980 ```
981 // Good.
982 enum Enum {
983     P,
984     X = 3,
985     Y = 5,
986 }
987 ```
988
989 Note that variants without a manually specified discriminant are numbered from
990 top to bottom starting from 0, so clashes can occur with seemingly unrelated
991 variants.
992
993 ```compile_fail,E0081
994 enum Bad {
995     X,
996     Y = 0
997 }
998 ```
999
1000 Here `X` will have already been specified the discriminant 0 by the time `Y` is
1001 encountered, so a conflict occurs.
1002 "##,
1003
1004 E0084: r##"
1005 An unsupported representation was attempted on a zero-variant enum.
1006
1007 Erroneous code example:
1008
1009 ```compile_fail,E0084
1010 #[repr(i32)]
1011 enum NightsWatch {} // error: unsupported representation for zero-variant enum
1012 ```
1013
1014 It is impossible to define an integer type to be used to represent zero-variant
1015 enum values because there are no zero-variant enum values. There is no way to
1016 construct an instance of the following type using only safe code. So you have
1017 two solutions. Either you add variants in your enum:
1018
1019 ```
1020 #[repr(i32)]
1021 enum NightsWatch {
1022     JonSnow,
1023     Commander,
1024 }
1025 ```
1026
1027 or you remove the integer represention of your enum:
1028
1029 ```
1030 enum NightsWatch {}
1031 ```
1032 "##,
1033
1034 // FIXME(const_generics:docs): example of inferring const parameter.
1035 E0087: r##"
1036 #### Note: this error code is no longer emitted by the compiler.
1037
1038 Too many type arguments were supplied for a function. For example:
1039
1040 ```compile_fail,E0107
1041 fn foo<T>() {}
1042
1043 fn main() {
1044     foo::<f64, bool>(); // error: wrong number of type arguments:
1045                         //        expected 1, found 2
1046 }
1047 ```
1048
1049 The number of supplied arguments must exactly match the number of defined type
1050 parameters.
1051 "##,
1052
1053 E0088: r##"
1054 #### Note: this error code is no longer emitted by the compiler.
1055
1056 You gave too many lifetime arguments. Erroneous code example:
1057
1058 ```compile_fail,E0107
1059 fn f() {}
1060
1061 fn main() {
1062     f::<'static>() // error: wrong number of lifetime arguments:
1063                    //        expected 0, found 1
1064 }
1065 ```
1066
1067 Please check you give the right number of lifetime arguments. Example:
1068
1069 ```
1070 fn f() {}
1071
1072 fn main() {
1073     f() // ok!
1074 }
1075 ```
1076
1077 It's also important to note that the Rust compiler can generally
1078 determine the lifetime by itself. Example:
1079
1080 ```
1081 struct Foo {
1082     value: String
1083 }
1084
1085 impl Foo {
1086     // it can be written like this
1087     fn get_value<'a>(&'a self) -> &'a str { &self.value }
1088     // but the compiler works fine with this too:
1089     fn without_lifetime(&self) -> &str { &self.value }
1090 }
1091
1092 fn main() {
1093     let f = Foo { value: "hello".to_owned() };
1094
1095     println!("{}", f.get_value());
1096     println!("{}", f.without_lifetime());
1097 }
1098 ```
1099 "##,
1100
1101 E0089: r##"
1102 #### Note: this error code is no longer emitted by the compiler.
1103
1104 Too few type arguments were supplied for a function. For example:
1105
1106 ```compile_fail,E0107
1107 fn foo<T, U>() {}
1108
1109 fn main() {
1110     foo::<f64>(); // error: wrong number of type arguments: expected 2, found 1
1111 }
1112 ```
1113
1114 Note that if a function takes multiple type arguments but you want the compiler
1115 to infer some of them, you can use type placeholders:
1116
1117 ```compile_fail,E0107
1118 fn foo<T, U>(x: T) {}
1119
1120 fn main() {
1121     let x: bool = true;
1122     foo::<f64>(x);    // error: wrong number of type arguments:
1123                       //        expected 2, found 1
1124     foo::<_, f64>(x); // same as `foo::<bool, f64>(x)`
1125 }
1126 ```
1127 "##,
1128
1129 E0090: r##"
1130 #### Note: this error code is no longer emitted by the compiler.
1131
1132 You gave too few lifetime arguments. Example:
1133
1134 ```compile_fail,E0107
1135 fn foo<'a: 'b, 'b: 'a>() {}
1136
1137 fn main() {
1138     foo::<'static>(); // error: wrong number of lifetime arguments:
1139                       //        expected 2, found 1
1140 }
1141 ```
1142
1143 Please check you give the right number of lifetime arguments. Example:
1144
1145 ```
1146 fn foo<'a: 'b, 'b: 'a>() {}
1147
1148 fn main() {
1149     foo::<'static, 'static>();
1150 }
1151 ```
1152 "##,
1153
1154 E0091: r##"
1155 You gave an unnecessary type or const parameter in a type alias. Erroneous
1156 code example:
1157
1158 ```compile_fail,E0091
1159 type Foo<T> = u32; // error: type parameter `T` is unused
1160 // or:
1161 type Foo<A,B> = Box<A>; // error: type parameter `B` is unused
1162 ```
1163
1164 Please check you didn't write too many parameters. Example:
1165
1166 ```
1167 type Foo = u32; // ok!
1168 type Foo2<A> = Box<A>; // ok!
1169 ```
1170 "##,
1171
1172 E0092: r##"
1173 You tried to declare an undefined atomic operation function.
1174 Erroneous code example:
1175
1176 ```compile_fail,E0092
1177 #![feature(intrinsics)]
1178
1179 extern "rust-intrinsic" {
1180     fn atomic_foo(); // error: unrecognized atomic operation
1181                      //        function
1182 }
1183 ```
1184
1185 Please check you didn't make a mistake in the function's name. All intrinsic
1186 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1187 libcore/intrinsics.rs in the Rust source code. Example:
1188
1189 ```
1190 #![feature(intrinsics)]
1191
1192 extern "rust-intrinsic" {
1193     fn atomic_fence(); // ok!
1194 }
1195 ```
1196 "##,
1197
1198 E0093: r##"
1199 You declared an unknown intrinsic function. Erroneous code example:
1200
1201 ```compile_fail,E0093
1202 #![feature(intrinsics)]
1203
1204 extern "rust-intrinsic" {
1205     fn foo(); // error: unrecognized intrinsic function: `foo`
1206 }
1207
1208 fn main() {
1209     unsafe {
1210         foo();
1211     }
1212 }
1213 ```
1214
1215 Please check you didn't make a mistake in the function's name. All intrinsic
1216 functions are defined in librustc_codegen_llvm/intrinsic.rs and in
1217 libcore/intrinsics.rs in the Rust source code. Example:
1218
1219 ```
1220 #![feature(intrinsics)]
1221
1222 extern "rust-intrinsic" {
1223     fn atomic_fence(); // ok!
1224 }
1225
1226 fn main() {
1227     unsafe {
1228         atomic_fence();
1229     }
1230 }
1231 ```
1232 "##,
1233
1234 E0094: r##"
1235 You gave an invalid number of type parameters to an intrinsic function.
1236 Erroneous code example:
1237
1238 ```compile_fail,E0094
1239 #![feature(intrinsics)]
1240
1241 extern "rust-intrinsic" {
1242     fn size_of<T, U>() -> usize; // error: intrinsic has wrong number
1243                                  //        of type parameters
1244 }
1245 ```
1246
1247 Please check that you provided the right number of type parameters
1248 and verify with the function declaration in the Rust source code.
1249 Example:
1250
1251 ```
1252 #![feature(intrinsics)]
1253
1254 extern "rust-intrinsic" {
1255     fn size_of<T>() -> usize; // ok!
1256 }
1257 ```
1258 "##,
1259
1260 E0107: r##"
1261 This error means that an incorrect number of generic arguments were provided:
1262
1263 ```compile_fail,E0107
1264 struct Foo<T> { x: T }
1265
1266 struct Bar { x: Foo }             // error: wrong number of type arguments:
1267                                   //        expected 1, found 0
1268 struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
1269                                   //        expected 1, found 2
1270
1271 fn foo<T, U>(x: T, y: U) {}
1272
1273 fn main() {
1274     let x: bool = true;
1275     foo::<bool>(x);                 // error: wrong number of type arguments:
1276                                     //        expected 2, found 1
1277     foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
1278                                     //        expected 2, found 3
1279 }
1280
1281 fn f() {}
1282
1283 fn main() {
1284     f::<'static>(); // error: wrong number of lifetime arguments:
1285                     //        expected 0, found 1
1286 }
1287 ```
1288
1289 "##,
1290
1291 E0109: r##"
1292 You tried to provide a generic argument to a type which doesn't need it.
1293 Erroneous code example:
1294
1295 ```compile_fail,E0109
1296 type X = u32<i32>; // error: type arguments are not allowed for this type
1297 type Y = bool<'static>; // error: lifetime parameters are not allowed on
1298                         //        this type
1299 ```
1300
1301 Check that you used the correct argument and that the definition is correct.
1302
1303 Example:
1304
1305 ```
1306 type X = u32; // ok!
1307 type Y = bool; // ok!
1308 ```
1309
1310 Note that generic arguments for enum variant constructors go after the variant,
1311 not after the enum. For example, you would write `Option::None::<u32>`,
1312 rather than `Option::<u32>::None`.
1313 "##,
1314
1315 E0110: r##"
1316 #### Note: this error code is no longer emitted by the compiler.
1317
1318 You tried to provide a lifetime to a type which doesn't need it.
1319 See `E0109` for more details.
1320 "##,
1321
1322 E0116: r##"
1323 You can only define an inherent implementation for a type in the same crate
1324 where the type was defined. For example, an `impl` block as below is not allowed
1325 since `Vec` is defined in the standard library:
1326
1327 ```compile_fail,E0116
1328 impl Vec<u8> { } // error
1329 ```
1330
1331 To fix this problem, you can do either of these things:
1332
1333  - define a trait that has the desired associated functions/types/constants and
1334    implement the trait for the type in question
1335  - define a new type wrapping the type and define an implementation on the new
1336    type
1337
1338 Note that using the `type` keyword does not work here because `type` only
1339 introduces a type alias:
1340
1341 ```compile_fail,E0116
1342 type Bytes = Vec<u8>;
1343
1344 impl Bytes { } // error, same as above
1345 ```
1346 "##,
1347
1348 E0117: r##"
1349 This error indicates a violation of one of Rust's orphan rules for trait
1350 implementations. The rule prohibits any implementation of a foreign trait (a
1351 trait defined in another crate) where
1352
1353  - the type that is implementing the trait is foreign
1354  - all of the parameters being passed to the trait (if there are any) are also
1355    foreign.
1356
1357 Here's one example of this error:
1358
1359 ```compile_fail,E0117
1360 impl Drop for u32 {}
1361 ```
1362
1363 To avoid this kind of error, ensure that at least one local type is referenced
1364 by the `impl`:
1365
1366 ```
1367 pub struct Foo; // you define your type in your crate
1368
1369 impl Drop for Foo { // and you can implement the trait on it!
1370     // code of trait implementation here
1371 #   fn drop(&mut self) { }
1372 }
1373
1374 impl From<Foo> for i32 { // or you use a type from your crate as
1375                          // a type parameter
1376     fn from(i: Foo) -> i32 {
1377         0
1378     }
1379 }
1380 ```
1381
1382 Alternatively, define a trait locally and implement that instead:
1383
1384 ```
1385 trait Bar {
1386     fn get(&self) -> usize;
1387 }
1388
1389 impl Bar for u32 {
1390     fn get(&self) -> usize { 0 }
1391 }
1392 ```
1393
1394 For information on the design of the orphan rules, see [RFC 1023].
1395
1396 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
1397 "##,
1398
1399 E0118: r##"
1400 You're trying to write an inherent implementation for something which isn't a
1401 struct nor an enum. Erroneous code example:
1402
1403 ```compile_fail,E0118
1404 impl (u8, u8) { // error: no base type found for inherent implementation
1405     fn get_state(&self) -> String {
1406         // ...
1407     }
1408 }
1409 ```
1410
1411 To fix this error, please implement a trait on the type or wrap it in a struct.
1412 Example:
1413
1414 ```
1415 // we create a trait here
1416 trait LiveLongAndProsper {
1417     fn get_state(&self) -> String;
1418 }
1419
1420 // and now you can implement it on (u8, u8)
1421 impl LiveLongAndProsper for (u8, u8) {
1422     fn get_state(&self) -> String {
1423         "He's dead, Jim!".to_owned()
1424     }
1425 }
1426 ```
1427
1428 Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
1429 For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
1430 Example:
1431
1432 ```
1433 struct TypeWrapper((u8, u8));
1434
1435 impl TypeWrapper {
1436     fn get_state(&self) -> String {
1437         "Fascinating!".to_owned()
1438     }
1439 }
1440 ```
1441 "##,
1442
1443 E0120: r##"
1444 An attempt was made to implement Drop on a trait, which is not allowed: only
1445 structs and enums can implement Drop. An example causing this error:
1446
1447 ```compile_fail,E0120
1448 trait MyTrait {}
1449
1450 impl Drop for MyTrait {
1451     fn drop(&mut self) {}
1452 }
1453 ```
1454
1455 A workaround for this problem is to wrap the trait up in a struct, and implement
1456 Drop on that. An example is shown below:
1457
1458 ```
1459 trait MyTrait {}
1460 struct MyWrapper<T: MyTrait> { foo: T }
1461
1462 impl <T: MyTrait> Drop for MyWrapper<T> {
1463     fn drop(&mut self) {}
1464 }
1465
1466 ```
1467
1468 Alternatively, wrapping trait objects requires something like the following:
1469
1470 ```
1471 trait MyTrait {}
1472
1473 //or Box<MyTrait>, if you wanted an owned trait object
1474 struct MyWrapper<'a> { foo: &'a MyTrait }
1475
1476 impl <'a> Drop for MyWrapper<'a> {
1477     fn drop(&mut self) {}
1478 }
1479 ```
1480 "##,
1481
1482 E0121: r##"
1483 In order to be consistent with Rust's lack of global type inference,
1484 type and const placeholders are disallowed by design in item signatures.
1485
1486 Examples of this error include:
1487
1488 ```compile_fail,E0121
1489 fn foo() -> _ { 5 } // error, explicitly write out the return type instead
1490
1491 static BAR: _ = "test"; // error, explicitly write out the type instead
1492 ```
1493 "##,
1494
1495 E0124: r##"
1496 You declared two fields of a struct with the same name. Erroneous code
1497 example:
1498
1499 ```compile_fail,E0124
1500 struct Foo {
1501     field1: i32,
1502     field1: i32, // error: field is already declared
1503 }
1504 ```
1505
1506 Please verify that the field names have been correctly spelled. Example:
1507
1508 ```
1509 struct Foo {
1510     field1: i32,
1511     field2: i32, // ok!
1512 }
1513 ```
1514 "##,
1515
1516 E0131: r##"
1517 It is not possible to define `main` with generic parameters.
1518 When `main` is present, it must take no arguments and return `()`.
1519 Erroneous code example:
1520
1521 ```compile_fail,E0131
1522 fn main<T>() { // error: main function is not allowed to have generic parameters
1523 }
1524 ```
1525 "##,
1526
1527 E0132: r##"
1528 A function with the `start` attribute was declared with type parameters.
1529
1530 Erroneous code example:
1531
1532 ```compile_fail,E0132
1533 #![feature(start)]
1534
1535 #[start]
1536 fn f<T>() {}
1537 ```
1538
1539 It is not possible to declare type parameters on a function that has the `start`
1540 attribute. Such a function must have the following type signature (for more
1541 information, view [the unstable book][1]):
1542
1543 [1]: https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib
1544
1545 ```
1546 # let _:
1547 fn(isize, *const *const u8) -> isize;
1548 ```
1549
1550 Example:
1551
1552 ```
1553 #![feature(start)]
1554
1555 #[start]
1556 fn my_start(argc: isize, argv: *const *const u8) -> isize {
1557     0
1558 }
1559 ```
1560 "##,
1561
1562 E0164: r##"
1563 This error means that an attempt was made to match a struct type enum
1564 variant as a non-struct type:
1565
1566 ```compile_fail,E0164
1567 enum Foo { B { i: u32 } }
1568
1569 fn bar(foo: Foo) -> u32 {
1570     match foo {
1571         Foo::B(i) => i, // error E0164
1572     }
1573 }
1574 ```
1575
1576 Try using `{}` instead:
1577
1578 ```
1579 enum Foo { B { i: u32 } }
1580
1581 fn bar(foo: Foo) -> u32 {
1582     match foo {
1583         Foo::B{i} => i,
1584     }
1585 }
1586 ```
1587 "##,
1588
1589 E0184: r##"
1590 Explicitly implementing both Drop and Copy for a type is currently disallowed.
1591 This feature can make some sense in theory, but the current implementation is
1592 incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so
1593 it has been disabled for now.
1594
1595 [iss20126]: https://github.com/rust-lang/rust/issues/20126
1596 "##,
1597
1598 E0185: r##"
1599 An associated function for a trait was defined to be static, but an
1600 implementation of the trait declared the same function to be a method (i.e., to
1601 take a `self` parameter).
1602
1603 Here's an example of this error:
1604
1605 ```compile_fail,E0185
1606 trait Foo {
1607     fn foo();
1608 }
1609
1610 struct Bar;
1611
1612 impl Foo for Bar {
1613     // error, method `foo` has a `&self` declaration in the impl, but not in
1614     // the trait
1615     fn foo(&self) {}
1616 }
1617 ```
1618 "##,
1619
1620 E0186: r##"
1621 An associated function for a trait was defined to be a method (i.e., to take a
1622 `self` parameter), but an implementation of the trait declared the same function
1623 to be static.
1624
1625 Here's an example of this error:
1626
1627 ```compile_fail,E0186
1628 trait Foo {
1629     fn foo(&self);
1630 }
1631
1632 struct Bar;
1633
1634 impl Foo for Bar {
1635     // error, method `foo` has a `&self` declaration in the trait, but not in
1636     // the impl
1637     fn foo() {}
1638 }
1639 ```
1640 "##,
1641
1642 E0191: r##"
1643 Trait objects need to have all associated types specified. Erroneous code
1644 example:
1645
1646 ```compile_fail,E0191
1647 trait Trait {
1648     type Bar;
1649 }
1650
1651 type Foo = Trait; // error: the value of the associated type `Bar` (from
1652                   //        the trait `Trait`) must be specified
1653 ```
1654
1655 Please verify you specified all associated types of the trait and that you
1656 used the right trait. Example:
1657
1658 ```
1659 trait Trait {
1660     type Bar;
1661 }
1662
1663 type Foo = Trait<Bar=i32>; // ok!
1664 ```
1665 "##,
1666
1667 E0192: r##"
1668 Negative impls are only allowed for auto traits. For more
1669 information see the [opt-in builtin traits RFC][RFC 19].
1670
1671 [RFC 19]: https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md
1672 "##,
1673
1674 E0193: r##"
1675 #### Note: this error code is no longer emitted by the compiler.
1676
1677 `where` clauses must use generic type parameters: it does not make sense to use
1678 them otherwise. An example causing this error:
1679
1680 ```
1681 trait Foo {
1682     fn bar(&self);
1683 }
1684
1685 #[derive(Copy,Clone)]
1686 struct Wrapper<T> {
1687     Wrapped: T
1688 }
1689
1690 impl Foo for Wrapper<u32> where Wrapper<u32>: Clone {
1691     fn bar(&self) { }
1692 }
1693 ```
1694
1695 This use of a `where` clause is strange - a more common usage would look
1696 something like the following:
1697
1698 ```
1699 trait Foo {
1700     fn bar(&self);
1701 }
1702
1703 #[derive(Copy,Clone)]
1704 struct Wrapper<T> {
1705     Wrapped: T
1706 }
1707 impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone {
1708     fn bar(&self) { }
1709 }
1710 ```
1711
1712 Here, we're saying that the implementation exists on Wrapper only when the
1713 wrapped type `T` implements `Clone`. The `where` clause is important because
1714 some types will not implement `Clone`, and thus will not get this method.
1715
1716 In our erroneous example, however, we're referencing a single concrete type.
1717 Since we know for certain that `Wrapper<u32>` implements `Clone`, there's no
1718 reason to also specify it in a `where` clause.
1719 "##,
1720
1721 E0195: r##"
1722 Your method's lifetime parameters do not match the trait declaration.
1723 Erroneous code example:
1724
1725 ```compile_fail,E0195
1726 trait Trait {
1727     fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
1728 }
1729
1730 struct Foo;
1731
1732 impl Trait for Foo {
1733     fn bar<'a,'b>(x: &'a str, y: &'b str) {
1734     // error: lifetime parameters or bounds on method `bar`
1735     // do not match the trait declaration
1736     }
1737 }
1738 ```
1739
1740 The lifetime constraint `'b` for bar() implementation does not match the
1741 trait declaration. Ensure lifetime declarations match exactly in both trait
1742 declaration and implementation. Example:
1743
1744 ```
1745 trait Trait {
1746     fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1747 }
1748
1749 struct Foo;
1750
1751 impl Trait for Foo {
1752     fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
1753     }
1754 }
1755 ```
1756 "##,
1757
1758 E0199: r##"
1759 Safe traits should not have unsafe implementations, therefore marking an
1760 implementation for a safe trait unsafe will cause a compiler error. Removing
1761 the unsafe marker on the trait noted in the error will resolve this problem.
1762
1763 ```compile_fail,E0199
1764 struct Foo;
1765
1766 trait Bar { }
1767
1768 // this won't compile because Bar is safe
1769 unsafe impl Bar for Foo { }
1770 // this will compile
1771 impl Bar for Foo { }
1772 ```
1773 "##,
1774
1775 E0200: r##"
1776 Unsafe traits must have unsafe implementations. This error occurs when an
1777 implementation for an unsafe trait isn't marked as unsafe. This may be resolved
1778 by marking the unsafe implementation as unsafe.
1779
1780 ```compile_fail,E0200
1781 struct Foo;
1782
1783 unsafe trait Bar { }
1784
1785 // this won't compile because Bar is unsafe and impl isn't unsafe
1786 impl Bar for Foo { }
1787 // this will compile
1788 unsafe impl Bar for Foo { }
1789 ```
1790 "##,
1791
1792 E0201: r##"
1793 It is an error to define two associated items (like methods, associated types,
1794 associated functions, etc.) with the same identifier.
1795
1796 For example:
1797
1798 ```compile_fail,E0201
1799 struct Foo(u8);
1800
1801 impl Foo {
1802     fn bar(&self) -> bool { self.0 > 5 }
1803     fn bar() {} // error: duplicate associated function
1804 }
1805
1806 trait Baz {
1807     type Quux;
1808     fn baz(&self) -> bool;
1809 }
1810
1811 impl Baz for Foo {
1812     type Quux = u32;
1813
1814     fn baz(&self) -> bool { true }
1815
1816     // error: duplicate method
1817     fn baz(&self) -> bool { self.0 > 5 }
1818
1819     // error: duplicate associated type
1820     type Quux = u32;
1821 }
1822 ```
1823
1824 Note, however, that items with the same name are allowed for inherent `impl`
1825 blocks that don't overlap:
1826
1827 ```
1828 struct Foo<T>(T);
1829
1830 impl Foo<u8> {
1831     fn bar(&self) -> bool { self.0 > 5 }
1832 }
1833
1834 impl Foo<bool> {
1835     fn bar(&self) -> bool { self.0 }
1836 }
1837 ```
1838 "##,
1839
1840 E0202: r##"
1841 Inherent associated types were part of [RFC 195] but are not yet implemented.
1842 See [the tracking issue][iss8995] for the status of this implementation.
1843
1844 [RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
1845 [iss8995]: https://github.com/rust-lang/rust/issues/8995
1846 "##,
1847
1848 E0204: r##"
1849 An attempt to implement the `Copy` trait for a struct failed because one of the
1850 fields does not implement `Copy`. To fix this, you must implement `Copy` for the
1851 mentioned field. Note that this may not be possible, as in the example of
1852
1853 ```compile_fail,E0204
1854 struct Foo {
1855     foo : Vec<u32>,
1856 }
1857
1858 impl Copy for Foo { }
1859 ```
1860
1861 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1862
1863 Here's another example that will fail:
1864
1865 ```compile_fail,E0204
1866 #[derive(Copy)]
1867 struct Foo<'a> {
1868     ty: &'a mut bool,
1869 }
1870 ```
1871
1872 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1873 differs from the behavior for `&T`, which is always `Copy`).
1874 "##,
1875
1876 /*
1877 E0205: r##"
1878 An attempt to implement the `Copy` trait for an enum failed because one of the
1879 variants does not implement `Copy`. To fix this, you must implement `Copy` for
1880 the mentioned variant. Note that this may not be possible, as in the example of
1881
1882 ```compile_fail,E0205
1883 enum Foo {
1884     Bar(Vec<u32>),
1885     Baz,
1886 }
1887
1888 impl Copy for Foo { }
1889 ```
1890
1891 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1892
1893 Here's another example that will fail:
1894
1895 ```compile_fail,E0205
1896 #[derive(Copy)]
1897 enum Foo<'a> {
1898     Bar(&'a mut bool),
1899     Baz,
1900 }
1901 ```
1902
1903 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1904 differs from the behavior for `&T`, which is always `Copy`).
1905 "##,
1906 */
1907
1908 E0206: r##"
1909 You can only implement `Copy` for a struct or enum. Both of the following
1910 examples will fail, because neither `[u8; 256]` nor `&'static mut Bar`
1911 (mutable reference to `Bar`) is a struct or enum:
1912
1913 ```compile_fail,E0206
1914 type Foo = [u8; 256];
1915 impl Copy for Foo { } // error
1916
1917 #[derive(Copy, Clone)]
1918 struct Bar;
1919 impl Copy for &'static mut Bar { } // error
1920 ```
1921 "##,
1922
1923 E0207: r##"
1924 Any type parameter or lifetime parameter of an `impl` must meet at least one of
1925 the following criteria:
1926
1927  - it appears in the _implementing type_ of the impl, e.g. `impl<T> Foo<T>`
1928  - for a trait impl, it appears in the _implemented trait_, e.g.
1929    `impl<T> SomeTrait<T> for Foo`
1930  - it is bound as an associated type, e.g. `impl<T, U> SomeTrait for T
1931    where T: AnotherTrait<AssocType=U>`
1932
1933 ### Error example 1
1934
1935 Suppose we have a struct `Foo` and we would like to define some methods for it.
1936 The following definition leads to a compiler error:
1937
1938 ```compile_fail,E0207
1939 struct Foo;
1940
1941 impl<T: Default> Foo {
1942 // error: the type parameter `T` is not constrained by the impl trait, self
1943 // type, or predicates [E0207]
1944     fn get(&self) -> T {
1945         <T as Default>::default()
1946     }
1947 }
1948 ```
1949
1950 The problem is that the parameter `T` does not appear in the implementing type
1951 (`Foo`) of the impl. In this case, we can fix the error by moving the type
1952 parameter from the `impl` to the method `get`:
1953
1954
1955 ```
1956 struct Foo;
1957
1958 // Move the type parameter from the impl to the method
1959 impl Foo {
1960     fn get<T: Default>(&self) -> T {
1961         <T as Default>::default()
1962     }
1963 }
1964 ```
1965
1966 ### Error example 2
1967
1968 As another example, suppose we have a `Maker` trait and want to establish a
1969 type `FooMaker` that makes `Foo`s:
1970
1971 ```compile_fail,E0207
1972 trait Maker {
1973     type Item;
1974     fn make(&mut self) -> Self::Item;
1975 }
1976
1977 struct Foo<T> {
1978     foo: T
1979 }
1980
1981 struct FooMaker;
1982
1983 impl<T: Default> Maker for FooMaker {
1984 // error: the type parameter `T` is not constrained by the impl trait, self
1985 // type, or predicates [E0207]
1986     type Item = Foo<T>;
1987
1988     fn make(&mut self) -> Foo<T> {
1989         Foo { foo: <T as Default>::default() }
1990     }
1991 }
1992 ```
1993
1994 This fails to compile because `T` does not appear in the trait or in the
1995 implementing type.
1996
1997 One way to work around this is to introduce a phantom type parameter into
1998 `FooMaker`, like so:
1999
2000 ```
2001 use std::marker::PhantomData;
2002
2003 trait Maker {
2004     type Item;
2005     fn make(&mut self) -> Self::Item;
2006 }
2007
2008 struct Foo<T> {
2009     foo: T
2010 }
2011
2012 // Add a type parameter to `FooMaker`
2013 struct FooMaker<T> {
2014     phantom: PhantomData<T>,
2015 }
2016
2017 impl<T: Default> Maker for FooMaker<T> {
2018     type Item = Foo<T>;
2019
2020     fn make(&mut self) -> Foo<T> {
2021         Foo {
2022             foo: <T as Default>::default(),
2023         }
2024     }
2025 }
2026 ```
2027
2028 Another way is to do away with the associated type in `Maker` and use an input
2029 type parameter instead:
2030
2031 ```
2032 // Use a type parameter instead of an associated type here
2033 trait Maker<Item> {
2034     fn make(&mut self) -> Item;
2035 }
2036
2037 struct Foo<T> {
2038     foo: T
2039 }
2040
2041 struct FooMaker;
2042
2043 impl<T: Default> Maker<Foo<T>> for FooMaker {
2044     fn make(&mut self) -> Foo<T> {
2045         Foo { foo: <T as Default>::default() }
2046     }
2047 }
2048 ```
2049
2050 ### Additional information
2051
2052 For more information, please see [RFC 447].
2053
2054 [RFC 447]: https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md
2055 "##,
2056
2057 E0210: r##"
2058 This error indicates a violation of one of Rust's orphan rules for trait
2059 implementations. The rule concerns the use of type parameters in an
2060 implementation of a foreign trait (a trait defined in another crate), and
2061 states that type parameters must be "covered" by a local type. To understand
2062 what this means, it is perhaps easiest to consider a few examples.
2063
2064 If `ForeignTrait` is a trait defined in some external crate `foo`, then the
2065 following trait `impl` is an error:
2066
2067 ```compile_fail,E0210
2068 # #[cfg(for_demonstration_only)]
2069 extern crate foo;
2070 # #[cfg(for_demonstration_only)]
2071 use foo::ForeignTrait;
2072 # use std::panic::UnwindSafe as ForeignTrait;
2073
2074 impl<T> ForeignTrait for T { } // error
2075 # fn main() {}
2076 ```
2077
2078 To work around this, it can be covered with a local type, `MyType`:
2079
2080 ```
2081 # use std::panic::UnwindSafe as ForeignTrait;
2082 struct MyType<T>(T);
2083 impl<T> ForeignTrait for MyType<T> { } // Ok
2084 ```
2085
2086 Please note that a type alias is not sufficient.
2087
2088 For another example of an error, suppose there's another trait defined in `foo`
2089 named `ForeignTrait2` that takes two type parameters. Then this `impl` results
2090 in the same rule violation:
2091
2092 ```ignore (cannot-doctest-multicrate-project)
2093 struct MyType2;
2094 impl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error
2095 ```
2096
2097 The reason for this is that there are two appearances of type parameter `T` in
2098 the `impl` header, both as parameters for `ForeignTrait2`. The first appearance
2099 is uncovered, and so runs afoul of the orphan rule.
2100
2101 Consider one more example:
2102
2103 ```ignore (cannot-doctest-multicrate-project)
2104 impl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok
2105 ```
2106
2107 This only differs from the previous `impl` in that the parameters `T` and
2108 `MyType<T>` for `ForeignTrait2` have been swapped. This example does *not*
2109 violate the orphan rule; it is permitted.
2110
2111 To see why that last example was allowed, you need to understand the general
2112 rule. Unfortunately this rule is a bit tricky to state. Consider an `impl`:
2113
2114 ```ignore (only-for-syntax-highlight)
2115 impl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... }
2116 ```
2117
2118 where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn`
2119 are types. One of the types `T0, ..., Tn` must be a local type (this is another
2120 orphan rule, see the explanation for E0117). Let `i` be the smallest integer
2121 such that `Ti` is a local type. Then no type parameter can appear in any of the
2122 `Tj` for `j < i`.
2123
2124 For information on the design of the orphan rules, see [RFC 1023].
2125
2126 [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md
2127 "##,
2128
2129 /*
2130 E0211: r##"
2131 You used a function or type which doesn't fit the requirements for where it was
2132 used. Erroneous code examples:
2133
2134 ```compile_fail
2135 #![feature(intrinsics)]
2136
2137 extern "rust-intrinsic" {
2138     fn size_of<T>(); // error: intrinsic has wrong type
2139 }
2140
2141 // or:
2142
2143 fn main() -> i32 { 0 }
2144 // error: main function expects type: `fn() {main}`: expected (), found i32
2145
2146 // or:
2147
2148 let x = 1u8;
2149 match x {
2150     0u8..=3i8 => (),
2151     // error: mismatched types in range: expected u8, found i8
2152     _ => ()
2153 }
2154
2155 // or:
2156
2157 use std::rc::Rc;
2158 struct Foo;
2159
2160 impl Foo {
2161     fn x(self: Rc<Foo>) {}
2162     // error: mismatched self type: expected `Foo`: expected struct
2163     //        `Foo`, found struct `alloc::rc::Rc`
2164 }
2165 ```
2166
2167 For the first code example, please check the function definition. Example:
2168
2169 ```
2170 #![feature(intrinsics)]
2171
2172 extern "rust-intrinsic" {
2173     fn size_of<T>() -> usize; // ok!
2174 }
2175 ```
2176
2177 The second case example is a bit particular : the main function must always
2178 have this definition:
2179
2180 ```compile_fail
2181 fn main();
2182 ```
2183
2184 They never take parameters and never return types.
2185
2186 For the third example, when you match, all patterns must have the same type
2187 as the type you're matching on. Example:
2188
2189 ```
2190 let x = 1u8;
2191
2192 match x {
2193     0u8..=3u8 => (), // ok!
2194     _ => ()
2195 }
2196 ```
2197
2198 And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
2199 or `&mut Self` work as explicit self parameters. Example:
2200
2201 ```
2202 struct Foo;
2203
2204 impl Foo {
2205     fn x(self: Box<Foo>) {} // ok!
2206 }
2207 ```
2208 "##,
2209      */
2210
2211 E0220: r##"
2212 You used an associated type which isn't defined in the trait.
2213 Erroneous code example:
2214
2215 ```compile_fail,E0220
2216 trait T1 {
2217     type Bar;
2218 }
2219
2220 type Foo = T1<F=i32>; // error: associated type `F` not found for `T1`
2221
2222 // or:
2223
2224 trait T2 {
2225     type Bar;
2226
2227     // error: Baz is used but not declared
2228     fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2229 }
2230 ```
2231
2232 Make sure that you have defined the associated type in the trait body.
2233 Also, verify that you used the right trait or you didn't misspell the
2234 associated type name. Example:
2235
2236 ```
2237 trait T1 {
2238     type Bar;
2239 }
2240
2241 type Foo = T1<Bar=i32>; // ok!
2242
2243 // or:
2244
2245 trait T2 {
2246     type Bar;
2247     type Baz; // we declare `Baz` in our trait.
2248
2249     // and now we can use it here:
2250     fn return_bool(&self, _: &Self::Bar, _: &Self::Baz) -> bool;
2251 }
2252 ```
2253 "##,
2254
2255 E0221: r##"
2256 An attempt was made to retrieve an associated type, but the type was ambiguous.
2257 For example:
2258
2259 ```compile_fail,E0221
2260 trait T1 {}
2261 trait T2 {}
2262
2263 trait Foo {
2264     type A: T1;
2265 }
2266
2267 trait Bar : Foo {
2268     type A: T2;
2269     fn do_something() {
2270         let _: Self::A;
2271     }
2272 }
2273 ```
2274
2275 In this example, `Foo` defines an associated type `A`. `Bar` inherits that type
2276 from `Foo`, and defines another associated type of the same name. As a result,
2277 when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined
2278 by `Foo` or the one defined by `Bar`.
2279
2280 There are two options to work around this issue. The first is simply to rename
2281 one of the types. Alternatively, one can specify the intended type using the
2282 following syntax:
2283
2284 ```
2285 trait T1 {}
2286 trait T2 {}
2287
2288 trait Foo {
2289     type A: T1;
2290 }
2291
2292 trait Bar : Foo {
2293     type A: T2;
2294     fn do_something() {
2295         let _: <Self as Bar>::A;
2296     }
2297 }
2298 ```
2299 "##,
2300
2301 E0223: r##"
2302 An attempt was made to retrieve an associated type, but the type was ambiguous.
2303 For example:
2304
2305 ```compile_fail,E0223
2306 trait MyTrait {type X; }
2307
2308 fn main() {
2309     let foo: MyTrait::X;
2310 }
2311 ```
2312
2313 The problem here is that we're attempting to take the type of X from MyTrait.
2314 Unfortunately, the type of X is not defined, because it's only made concrete in
2315 implementations of the trait. A working version of this code might look like:
2316
2317 ```
2318 trait MyTrait {type X; }
2319 struct MyStruct;
2320
2321 impl MyTrait for MyStruct {
2322     type X = u32;
2323 }
2324
2325 fn main() {
2326     let foo: <MyStruct as MyTrait>::X;
2327 }
2328 ```
2329
2330 This syntax specifies that we want the X type from MyTrait, as made concrete in
2331 MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
2332 might implement two different traits with identically-named associated types.
2333 This syntax allows disambiguation between the two.
2334 "##,
2335
2336 E0225: r##"
2337 You attempted to use multiple types as bounds for a closure or trait object.
2338 Rust does not currently support this. A simple example that causes this error:
2339
2340 ```compile_fail,E0225
2341 fn main() {
2342     let _: Box<dyn std::io::Read + std::io::Write>;
2343 }
2344 ```
2345
2346 Auto traits such as Send and Sync are an exception to this rule:
2347 It's possible to have bounds of one non-builtin trait, plus any number of
2348 auto traits. For example, the following compiles correctly:
2349
2350 ```
2351 fn main() {
2352     let _: Box<dyn std::io::Read + Send + Sync>;
2353 }
2354 ```
2355 "##,
2356
2357 E0229: r##"
2358 An associated type binding was done outside of the type parameter declaration
2359 and `where` clause. Erroneous code example:
2360
2361 ```compile_fail,E0229
2362 pub trait Foo {
2363     type A;
2364     fn boo(&self) -> <Self as Foo>::A;
2365 }
2366
2367 struct Bar;
2368
2369 impl Foo for isize {
2370     type A = usize;
2371     fn boo(&self) -> usize { 42 }
2372 }
2373
2374 fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
2375 // error: associated type bindings are not allowed here
2376 ```
2377
2378 To solve this error, please move the type bindings in the type parameter
2379 declaration:
2380
2381 ```
2382 # struct Bar;
2383 # trait Foo { type A; }
2384 fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok!
2385 ```
2386
2387 Or in the `where` clause:
2388
2389 ```
2390 # struct Bar;
2391 # trait Foo { type A; }
2392 fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
2393 ```
2394 "##,
2395
2396 E0243: r##"
2397 #### Note: this error code is no longer emitted by the compiler.
2398
2399 This error indicates that not enough type parameters were found in a type or
2400 trait.
2401
2402 For example, the `Foo` struct below is defined to be generic in `T`, but the
2403 type parameter is missing in the definition of `Bar`:
2404
2405 ```compile_fail,E0107
2406 struct Foo<T> { x: T }
2407
2408 struct Bar { x: Foo }
2409 ```
2410 "##,
2411
2412 E0244: r##"
2413 #### Note: this error code is no longer emitted by the compiler.
2414
2415 This error indicates that too many type parameters were found in a type or
2416 trait.
2417
2418 For example, the `Foo` struct below has no type parameters, but is supplied
2419 with two in the definition of `Bar`:
2420
2421 ```compile_fail,E0107
2422 struct Foo { x: bool }
2423
2424 struct Bar<S, T> { x: Foo<S, T> }
2425 ```
2426 "##,
2427
2428 E0307: r##"
2429 This error indicates that the `self` parameter in a method has an invalid
2430 "reciever type".
2431
2432 Methods take a special first parameter, of which there are three variants:
2433 `self`, `&self`, and `&mut self`. These are syntactic sugar for
2434 `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
2435
2436 ```
2437 # struct Foo;
2438 trait Trait {
2439     fn foo(&self);
2440 //         ^^^^^ `self` here is a reference to the receiver object
2441 }
2442
2443 impl Trait for Foo {
2444     fn foo(&self) {}
2445 //         ^^^^^ the receiver type is `&Foo`
2446 }
2447 ```
2448
2449 The type `Self` acts as an alias to the type of the current trait
2450 implementer, or "receiver type". Besides the already mentioned `Self`,
2451 `&Self` and `&mut Self` valid receiver types, the following are also valid:
2452 `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
2453 (where P is one of the previous types except `Self`). Note that `Self` can
2454 also be the underlying implementing type, like `Foo` in the following
2455 example:
2456
2457 ```
2458 # struct Foo;
2459 # trait Trait {
2460 #     fn foo(&self);
2461 # }
2462 impl Trait for Foo {
2463     fn foo(self: &Foo) {}
2464 }
2465 ```
2466
2467 E0307 will be emitted by the compiler when using an invalid reciver type,
2468 like in the following example:
2469
2470 ```compile_fail,E0307
2471 # struct Foo;
2472 # struct Bar;
2473 # trait Trait {
2474 #     fn foo(&self);
2475 # }
2476 impl Trait for Foo {
2477     fn foo(self: &Bar) {}
2478 }
2479 ```
2480
2481 The nightly feature [Arbintrary self types][AST] extends the accepted
2482 set of receiver types to also include any type that can dereference to
2483 `Self`:
2484
2485 ```
2486 #![feature(arbitrary_self_types)]
2487
2488 struct Foo;
2489 struct Bar;
2490
2491 // Because you can dereference `Bar` into `Foo`...
2492 impl std::ops::Deref for Bar {
2493     type Target = Foo;
2494
2495     fn deref(&self) -> &Foo {
2496         &Foo
2497     }
2498 }
2499
2500 impl Foo {
2501     fn foo(self: Bar) {}
2502 //         ^^^^^^^^^ ...it can be used as the receiver type
2503 }
2504 ```
2505
2506 [AST]: https://doc.rust-lang.org/unstable-book/language-features/arbitrary-self-types.html
2507 "##,
2508
2509 E0321: r##"
2510 A cross-crate opt-out trait was implemented on something which wasn't a struct
2511 or enum type. Erroneous code example:
2512
2513 ```compile_fail,E0321
2514 #![feature(optin_builtin_traits)]
2515
2516 struct Foo;
2517
2518 impl !Sync for Foo {}
2519
2520 unsafe impl Send for &'static Foo {}
2521 // error: cross-crate traits with a default impl, like `core::marker::Send`,
2522 //        can only be implemented for a struct/enum type, not
2523 //        `&'static Foo`
2524 ```
2525
2526 Only structs and enums are permitted to impl Send, Sync, and other opt-out
2527 trait, and the struct or enum must be local to the current crate. So, for
2528 example, `unsafe impl Send for Rc<Foo>` is not allowed.
2529 "##,
2530
2531 E0322: r##"
2532 The `Sized` trait is a special trait built-in to the compiler for types with a
2533 constant size known at compile-time. This trait is automatically implemented
2534 for types as needed by the compiler, and it is currently disallowed to
2535 explicitly implement it for a type.
2536 "##,
2537
2538 E0323: r##"
2539 An associated const was implemented when another trait item was expected.
2540 Erroneous code example:
2541
2542 ```compile_fail,E0323
2543 trait Foo {
2544     type N;
2545 }
2546
2547 struct Bar;
2548
2549 impl Foo for Bar {
2550     const N : u32 = 0;
2551     // error: item `N` is an associated const, which doesn't match its
2552     //        trait `<Bar as Foo>`
2553 }
2554 ```
2555
2556 Please verify that the associated const wasn't misspelled and the correct trait
2557 was implemented. Example:
2558
2559 ```
2560 struct Bar;
2561
2562 trait Foo {
2563     type N;
2564 }
2565
2566 impl Foo for Bar {
2567     type N = u32; // ok!
2568 }
2569 ```
2570
2571 Or:
2572
2573 ```
2574 struct Bar;
2575
2576 trait Foo {
2577     const N : u32;
2578 }
2579
2580 impl Foo for Bar {
2581     const N : u32 = 0; // ok!
2582 }
2583 ```
2584 "##,
2585
2586 E0324: r##"
2587 A method was implemented when another trait item was expected. Erroneous
2588 code example:
2589
2590 ```compile_fail,E0324
2591 struct Bar;
2592
2593 trait Foo {
2594     const N : u32;
2595
2596     fn M();
2597 }
2598
2599 impl Foo for Bar {
2600     fn N() {}
2601     // error: item `N` is an associated method, which doesn't match its
2602     //        trait `<Bar as Foo>`
2603 }
2604 ```
2605
2606 To fix this error, please verify that the method name wasn't misspelled and
2607 verify that you are indeed implementing the correct trait items. Example:
2608
2609 ```
2610 struct Bar;
2611
2612 trait Foo {
2613     const N : u32;
2614
2615     fn M();
2616 }
2617
2618 impl Foo for Bar {
2619     const N : u32 = 0;
2620
2621     fn M() {} // ok!
2622 }
2623 ```
2624 "##,
2625
2626 E0325: r##"
2627 An associated type was implemented when another trait item was expected.
2628 Erroneous code example:
2629
2630 ```compile_fail,E0325
2631 struct Bar;
2632
2633 trait Foo {
2634     const N : u32;
2635 }
2636
2637 impl Foo for Bar {
2638     type N = u32;
2639     // error: item `N` is an associated type, which doesn't match its
2640     //        trait `<Bar as Foo>`
2641 }
2642 ```
2643
2644 Please verify that the associated type name wasn't misspelled and your
2645 implementation corresponds to the trait definition. Example:
2646
2647 ```
2648 struct Bar;
2649
2650 trait Foo {
2651     type N;
2652 }
2653
2654 impl Foo for Bar {
2655     type N = u32; // ok!
2656 }
2657 ```
2658
2659 Or:
2660
2661 ```
2662 struct Bar;
2663
2664 trait Foo {
2665     const N : u32;
2666 }
2667
2668 impl Foo for Bar {
2669     const N : u32 = 0; // ok!
2670 }
2671 ```
2672 "##,
2673
2674 E0326: r##"
2675 The types of any associated constants in a trait implementation must match the
2676 types in the trait definition. This error indicates that there was a mismatch.
2677
2678 Here's an example of this error:
2679
2680 ```compile_fail,E0326
2681 trait Foo {
2682     const BAR: bool;
2683 }
2684
2685 struct Bar;
2686
2687 impl Foo for Bar {
2688     const BAR: u32 = 5; // error, expected bool, found u32
2689 }
2690 ```
2691 "##,
2692
2693 E0328: r##"
2694 The Unsize trait should not be implemented directly. All implementations of
2695 Unsize are provided automatically by the compiler.
2696
2697 Erroneous code example:
2698
2699 ```compile_fail,E0328
2700 #![feature(unsize)]
2701
2702 use std::marker::Unsize;
2703
2704 pub struct MyType;
2705
2706 impl<T> Unsize<T> for MyType {}
2707 ```
2708
2709 If you are defining your own smart pointer type and would like to enable
2710 conversion from a sized to an unsized type with the
2711 [DST coercion system][RFC 982], use [`CoerceUnsized`] instead.
2712
2713 ```
2714 #![feature(coerce_unsized)]
2715
2716 use std::ops::CoerceUnsized;
2717
2718 pub struct MyType<T: ?Sized> {
2719     field_with_unsized_type: T,
2720 }
2721
2722 impl<T, U> CoerceUnsized<MyType<U>> for MyType<T>
2723     where T: CoerceUnsized<U> {}
2724 ```
2725
2726 [RFC 982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
2727 [`CoerceUnsized`]: https://doc.rust-lang.org/std/ops/trait.CoerceUnsized.html
2728 "##,
2729
2730 /*
2731 // Associated consts can now be accessed through generic type parameters, and
2732 // this error is no longer emitted.
2733 //
2734 // FIXME: consider whether to leave it in the error index, or remove it entirely
2735 //        as associated consts is not stabilized yet.
2736
2737 E0329: r##"
2738 An attempt was made to access an associated constant through either a generic
2739 type parameter or `Self`. This is not supported yet. An example causing this
2740 error is shown below:
2741
2742 ```
2743 trait Foo {
2744     const BAR: f64;
2745 }
2746
2747 struct MyStruct;
2748
2749 impl Foo for MyStruct {
2750     const BAR: f64 = 0f64;
2751 }
2752
2753 fn get_bar_bad<F: Foo>(t: F) -> f64 {
2754     F::BAR
2755 }
2756 ```
2757
2758 Currently, the value of `BAR` for a particular type can only be accessed
2759 through a concrete type, as shown below:
2760
2761 ```
2762 trait Foo {
2763     const BAR: f64;
2764 }
2765
2766 struct MyStruct;
2767
2768 fn get_bar_good() -> f64 {
2769     <MyStruct as Foo>::BAR
2770 }
2771 ```
2772 "##,
2773 */
2774
2775 E0366: r##"
2776 An attempt was made to implement `Drop` on a concrete specialization of a
2777 generic type. An example is shown below:
2778
2779 ```compile_fail,E0366
2780 struct Foo<T> {
2781     t: T
2782 }
2783
2784 impl Drop for Foo<u32> {
2785     fn drop(&mut self) {}
2786 }
2787 ```
2788
2789 This code is not legal: it is not possible to specialize `Drop` to a subset of
2790 implementations of a generic type. One workaround for this is to wrap the
2791 generic type, as shown below:
2792
2793 ```
2794 struct Foo<T> {
2795     t: T
2796 }
2797
2798 struct Bar {
2799     t: Foo<u32>
2800 }
2801
2802 impl Drop for Bar {
2803     fn drop(&mut self) {}
2804 }
2805 ```
2806 "##,
2807
2808 E0367: r##"
2809 An attempt was made to implement `Drop` on a specialization of a generic type.
2810 An example is shown below:
2811
2812 ```compile_fail,E0367
2813 trait Foo{}
2814
2815 struct MyStruct<T> {
2816     t: T
2817 }
2818
2819 impl<T: Foo> Drop for MyStruct<T> {
2820     fn drop(&mut self) {}
2821 }
2822 ```
2823
2824 This code is not legal: it is not possible to specialize `Drop` to a subset of
2825 implementations of a generic type. In order for this code to work, `MyStruct`
2826 must also require that `T` implements `Foo`. Alternatively, another option is
2827 to wrap the generic type in another that specializes appropriately:
2828
2829 ```
2830 trait Foo{}
2831
2832 struct MyStruct<T> {
2833     t: T
2834 }
2835
2836 struct MyStructWrapper<T: Foo> {
2837     t: MyStruct<T>
2838 }
2839
2840 impl <T: Foo> Drop for MyStructWrapper<T> {
2841     fn drop(&mut self) {}
2842 }
2843 ```
2844 "##,
2845
2846 E0368: r##"
2847 This error indicates that a binary assignment operator like `+=` or `^=` was
2848 applied to a type that doesn't support it. For example:
2849
2850 ```compile_fail,E0368
2851 let mut x = 12f32; // error: binary operation `<<` cannot be applied to
2852                    //        type `f32`
2853
2854 x <<= 2;
2855 ```
2856
2857 To fix this error, please check that this type implements this binary
2858 operation. Example:
2859
2860 ```
2861 let mut x = 12u32; // the `u32` type does implement the `ShlAssign` trait
2862
2863 x <<= 2; // ok!
2864 ```
2865
2866 It is also possible to overload most operators for your own type by
2867 implementing the `[OP]Assign` traits from `std::ops`.
2868
2869 Another problem you might be facing is this: suppose you've overloaded the `+`
2870 operator for some type `Foo` by implementing the `std::ops::Add` trait for
2871 `Foo`, but you find that using `+=` does not work, as in this example:
2872
2873 ```compile_fail,E0368
2874 use std::ops::Add;
2875
2876 struct Foo(u32);
2877
2878 impl Add for Foo {
2879     type Output = Foo;
2880
2881     fn add(self, rhs: Foo) -> Foo {
2882         Foo(self.0 + rhs.0)
2883     }
2884 }
2885
2886 fn main() {
2887     let mut x: Foo = Foo(5);
2888     x += Foo(7); // error, `+= cannot be applied to the type `Foo`
2889 }
2890 ```
2891
2892 This is because `AddAssign` is not automatically implemented, so you need to
2893 manually implement it for your type.
2894 "##,
2895
2896 E0369: r##"
2897 A binary operation was attempted on a type which doesn't support it.
2898 Erroneous code example:
2899
2900 ```compile_fail,E0369
2901 let x = 12f32; // error: binary operation `<<` cannot be applied to
2902                //        type `f32`
2903
2904 x << 2;
2905 ```
2906
2907 To fix this error, please check that this type implements this binary
2908 operation. Example:
2909
2910 ```
2911 let x = 12u32; // the `u32` type does implement it:
2912                // https://doc.rust-lang.org/stable/std/ops/trait.Shl.html
2913
2914 x << 2; // ok!
2915 ```
2916
2917 It is also possible to overload most operators for your own type by
2918 implementing traits from `std::ops`.
2919
2920 String concatenation appends the string on the right to the string on the
2921 left and may require reallocation. This requires ownership of the string
2922 on the left. If something should be added to a string literal, move the
2923 literal to the heap by allocating it with `to_owned()` like in
2924 `"Your text".to_owned()`.
2925
2926 "##,
2927
2928 E0370: r##"
2929 The maximum value of an enum was reached, so it cannot be automatically
2930 set in the next enum value. Erroneous code example:
2931
2932 ```compile_fail,E0370
2933 #[repr(i64)]
2934 enum Foo {
2935     X = 0x7fffffffffffffff,
2936     Y, // error: enum discriminant overflowed on value after
2937        //        9223372036854775807: i64; set explicitly via
2938        //        Y = -9223372036854775808 if that is desired outcome
2939 }
2940 ```
2941
2942 To fix this, please set manually the next enum value or put the enum variant
2943 with the maximum value at the end of the enum. Examples:
2944
2945 ```
2946 #[repr(i64)]
2947 enum Foo {
2948     X = 0x7fffffffffffffff,
2949     Y = 0, // ok!
2950 }
2951 ```
2952
2953 Or:
2954
2955 ```
2956 #[repr(i64)]
2957 enum Foo {
2958     Y = 0, // ok!
2959     X = 0x7fffffffffffffff,
2960 }
2961 ```
2962 "##,
2963
2964 E0371: r##"
2965 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
2966 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
2967 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
2968 definition, so it is not useful to do this.
2969
2970 Example:
2971
2972 ```compile_fail,E0371
2973 trait Foo { fn foo(&self) { } }
2974 trait Bar: Foo { }
2975 trait Baz: Bar { }
2976
2977 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
2978 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
2979 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
2980 impl Baz for Bar { } // Note: This is OK
2981 ```
2982 "##,
2983
2984 E0374: r##"
2985 A struct without a field containing an unsized type cannot implement
2986 `CoerceUnsized`. An [unsized type][1] is any type that the compiler
2987 doesn't know the length or alignment of at compile time. Any struct
2988 containing an unsized type is also unsized.
2989
2990 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
2991
2992 Example of erroneous code:
2993
2994 ```compile_fail,E0374
2995 #![feature(coerce_unsized)]
2996 use std::ops::CoerceUnsized;
2997
2998 struct Foo<T: ?Sized> {
2999     a: i32,
3000 }
3001
3002 // error: Struct `Foo` has no unsized fields that need `CoerceUnsized`.
3003 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T>
3004     where T: CoerceUnsized<U> {}
3005 ```
3006
3007 `CoerceUnsized` is used to coerce one struct containing an unsized type
3008 into another struct containing a different unsized type. If the struct
3009 doesn't have any fields of unsized types then you don't need explicit
3010 coercion to get the types you want. To fix this you can either
3011 not try to implement `CoerceUnsized` or you can add a field that is
3012 unsized to the struct.
3013
3014 Example:
3015
3016 ```
3017 #![feature(coerce_unsized)]
3018 use std::ops::CoerceUnsized;
3019
3020 // We don't need to impl `CoerceUnsized` here.
3021 struct Foo {
3022     a: i32,
3023 }
3024
3025 // We add the unsized type field to the struct.
3026 struct Bar<T: ?Sized> {
3027     a: i32,
3028     b: T,
3029 }
3030
3031 // The struct has an unsized field so we can implement
3032 // `CoerceUnsized` for it.
3033 impl<T, U> CoerceUnsized<Bar<U>> for Bar<T>
3034     where T: CoerceUnsized<U> {}
3035 ```
3036
3037 Note that `CoerceUnsized` is mainly used by smart pointers like `Box`, `Rc`
3038 and `Arc` to be able to mark that they can coerce unsized types that they
3039 are pointing at.
3040 "##,
3041
3042 E0375: r##"
3043 A struct with more than one field containing an unsized type cannot implement
3044 `CoerceUnsized`. This only occurs when you are trying to coerce one of the
3045 types in your struct to another type in the struct. In this case we try to
3046 impl `CoerceUnsized` from `T` to `U` which are both types that the struct
3047 takes. An [unsized type][1] is any type that the compiler doesn't know the
3048 length or alignment of at compile time. Any struct containing an unsized type
3049 is also unsized.
3050
3051 Example of erroneous code:
3052
3053 ```compile_fail,E0375
3054 #![feature(coerce_unsized)]
3055 use std::ops::CoerceUnsized;
3056
3057 struct Foo<T: ?Sized, U: ?Sized> {
3058     a: i32,
3059     b: T,
3060     c: U,
3061 }
3062
3063 // error: Struct `Foo` has more than one unsized field.
3064 impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
3065 ```
3066
3067 `CoerceUnsized` only allows for coercion from a structure with a single
3068 unsized type field to another struct with a single unsized type field.
3069 In fact Rust only allows for a struct to have one unsized type in a struct
3070 and that unsized type must be the last field in the struct. So having two
3071 unsized types in a single struct is not allowed by the compiler. To fix this
3072 use only one field containing an unsized type in the struct and then use
3073 multiple structs to manage each unsized type field you need.
3074
3075 Example:
3076
3077 ```
3078 #![feature(coerce_unsized)]
3079 use std::ops::CoerceUnsized;
3080
3081 struct Foo<T: ?Sized> {
3082     a: i32,
3083     b: T,
3084 }
3085
3086 impl <T, U> CoerceUnsized<Foo<U>> for Foo<T>
3087     where T: CoerceUnsized<U> {}
3088
3089 fn coerce_foo<T: CoerceUnsized<U>, U>(t: T) -> Foo<U> {
3090     Foo { a: 12i32, b: t } // we use coercion to get the `Foo<U>` type we need
3091 }
3092 ```
3093
3094 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3095 "##,
3096
3097 E0376: r##"
3098 The type you are trying to impl `CoerceUnsized` for is not a struct.
3099 `CoerceUnsized` can only be implemented for a struct. Unsized types are
3100 already able to be coerced without an implementation of `CoerceUnsized`
3101 whereas a struct containing an unsized type needs to know the unsized type
3102 field it's containing is able to be coerced. An [unsized type][1]
3103 is any type that the compiler doesn't know the length or alignment of at
3104 compile time. Any struct containing an unsized type is also unsized.
3105
3106 [1]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait
3107
3108 Example of erroneous code:
3109
3110 ```compile_fail,E0376
3111 #![feature(coerce_unsized)]
3112 use std::ops::CoerceUnsized;
3113
3114 struct Foo<T: ?Sized> {
3115     a: T,
3116 }
3117
3118 // error: The type `U` is not a struct
3119 impl<T, U> CoerceUnsized<U> for Foo<T> {}
3120 ```
3121
3122 The `CoerceUnsized` trait takes a struct type. Make sure the type you are
3123 providing to `CoerceUnsized` is a struct with only the last field containing an
3124 unsized type.
3125
3126 Example:
3127
3128 ```
3129 #![feature(coerce_unsized)]
3130 use std::ops::CoerceUnsized;
3131
3132 struct Foo<T> {
3133     a: T,
3134 }
3135
3136 // The `Foo<U>` is a struct so `CoerceUnsized` can be implemented
3137 impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
3138 ```
3139
3140 Note that in Rust, structs can only contain an unsized type if the field
3141 containing the unsized type is the last and only unsized type field in the
3142 struct.
3143 "##,
3144
3145 E0378: r##"
3146 The `DispatchFromDyn` trait currently can only be implemented for
3147 builtin pointer types and structs that are newtype wrappers around them
3148 — that is, the struct must have only one field (except for`PhantomData`),
3149 and that field must itself implement `DispatchFromDyn`.
3150
3151 Examples:
3152
3153 ```
3154 #![feature(dispatch_from_dyn, unsize)]
3155 use std::{
3156     marker::Unsize,
3157     ops::DispatchFromDyn,
3158 };
3159
3160 struct Ptr<T: ?Sized>(*const T);
3161
3162 impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
3163 where
3164     T: Unsize<U>,
3165 {}
3166 ```
3167
3168 ```
3169 #![feature(dispatch_from_dyn)]
3170 use std::{
3171     ops::DispatchFromDyn,
3172     marker::PhantomData,
3173 };
3174
3175 struct Wrapper<T> {
3176     ptr: T,
3177     _phantom: PhantomData<()>,
3178 }
3179
3180 impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
3181 where
3182     T: DispatchFromDyn<U>,
3183 {}
3184 ```
3185
3186 Example of illegal `DispatchFromDyn` implementation
3187 (illegal because of extra field)
3188
3189 ```compile-fail,E0378
3190 #![feature(dispatch_from_dyn)]
3191 use std::ops::DispatchFromDyn;
3192
3193 struct WrapperExtraField<T> {
3194     ptr: T,
3195     extra_stuff: i32,
3196 }
3197
3198 impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
3199 where
3200     T: DispatchFromDyn<U>,
3201 {}
3202 ```
3203 "##,
3204
3205 E0390: r##"
3206 You tried to implement methods for a primitive type. Erroneous code example:
3207
3208 ```compile_fail,E0390
3209 struct Foo {
3210     x: i32
3211 }
3212
3213 impl *mut Foo {}
3214 // error: only a single inherent implementation marked with
3215 //        `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive
3216 ```
3217
3218 This isn't allowed, but using a trait to implement a method is a good solution.
3219 Example:
3220
3221 ```
3222 struct Foo {
3223     x: i32
3224 }
3225
3226 trait Bar {
3227     fn bar();
3228 }
3229
3230 impl Bar for *mut Foo {
3231     fn bar() {} // ok!
3232 }
3233 ```
3234 "##,
3235
3236 E0392: r##"
3237 This error indicates that a type or lifetime parameter has been declared
3238 but not actually used. Here is an example that demonstrates the error:
3239
3240 ```compile_fail,E0392
3241 enum Foo<T> {
3242     Bar,
3243 }
3244 ```
3245
3246 If the type parameter was included by mistake, this error can be fixed
3247 by simply removing the type parameter, as shown below:
3248
3249 ```
3250 enum Foo {
3251     Bar,
3252 }
3253 ```
3254
3255 Alternatively, if the type parameter was intentionally inserted, it must be
3256 used. A simple fix is shown below:
3257
3258 ```
3259 enum Foo<T> {
3260     Bar(T),
3261 }
3262 ```
3263
3264 This error may also commonly be found when working with unsafe code. For
3265 example, when using raw pointers one may wish to specify the lifetime for
3266 which the pointed-at data is valid. An initial attempt (below) causes this
3267 error:
3268
3269 ```compile_fail,E0392
3270 struct Foo<'a, T> {
3271     x: *const T,
3272 }
3273 ```
3274
3275 We want to express the constraint that Foo should not outlive `'a`, because
3276 the data pointed to by `T` is only valid for that lifetime. The problem is
3277 that there are no actual uses of `'a`. It's possible to work around this
3278 by adding a PhantomData type to the struct, using it to tell the compiler
3279 to act as if the struct contained a borrowed reference `&'a T`:
3280
3281 ```
3282 use std::marker::PhantomData;
3283
3284 struct Foo<'a, T: 'a> {
3285     x: *const T,
3286     phantom: PhantomData<&'a T>
3287 }
3288 ```
3289
3290 [PhantomData] can also be used to express information about unused type
3291 parameters.
3292
3293 [PhantomData]: https://doc.rust-lang.org/std/marker/struct.PhantomData.html
3294 "##,
3295
3296 E0393: r##"
3297 A type parameter which references `Self` in its default value was not specified.
3298 Example of erroneous code:
3299
3300 ```compile_fail,E0393
3301 trait A<T=Self> {}
3302
3303 fn together_we_will_rule_the_galaxy(son: &A) {}
3304 // error: the type parameter `T` must be explicitly specified in an
3305 //        object type because its default value `Self` references the
3306 //        type `Self`
3307 ```
3308
3309 A trait object is defined over a single, fully-defined trait. With a regular
3310 default parameter, this parameter can just be substituted in. However, if the
3311 default parameter is `Self`, the trait changes for each concrete type; i.e.
3312 `i32` will be expected to implement `A<i32>`, `bool` will be expected to
3313 implement `A<bool>`, etc... These types will not share an implementation of a
3314 fully-defined trait; instead they share implementations of a trait with
3315 different parameters substituted in for each implementation. This is
3316 irreconcilable with what we need to make a trait object work, and is thus
3317 disallowed. Making the trait concrete by explicitly specifying the value of the
3318 defaulted parameter will fix this issue. Fixed example:
3319
3320 ```
3321 trait A<T=Self> {}
3322
3323 fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
3324 ```
3325 "##,
3326
3327 E0399: r##"
3328 You implemented a trait, overriding one or more of its associated types but did
3329 not reimplement its default methods.
3330
3331 Example of erroneous code:
3332
3333 ```compile_fail,E0399
3334 #![feature(associated_type_defaults)]
3335
3336 pub trait Foo {
3337     type Assoc = u8;
3338     fn bar(&self) {}
3339 }
3340
3341 impl Foo for i32 {
3342     // error - the following trait items need to be reimplemented as
3343     //         `Assoc` was overridden: `bar`
3344     type Assoc = i32;
3345 }
3346 ```
3347
3348 To fix this, add an implementation for each default method from the trait:
3349
3350 ```
3351 #![feature(associated_type_defaults)]
3352
3353 pub trait Foo {
3354     type Assoc = u8;
3355     fn bar(&self) {}
3356 }
3357
3358 impl Foo for i32 {
3359     type Assoc = i32;
3360     fn bar(&self) {} // ok!
3361 }
3362 ```
3363 "##,
3364
3365 E0436: r##"
3366 The functional record update syntax is only allowed for structs. (Struct-like
3367 enum variants don't qualify, for example.)
3368
3369 Erroneous code example:
3370
3371 ```compile_fail,E0436
3372 enum PublicationFrequency {
3373     Weekly,
3374     SemiMonthly { days: (u8, u8), annual_special: bool },
3375 }
3376
3377 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3378                      -> PublicationFrequency {
3379     match competitor_frequency {
3380         PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3381             days: (1, 15), annual_special: false
3382         },
3383         c @ PublicationFrequency::SemiMonthly{ .. } =>
3384             PublicationFrequency::SemiMonthly {
3385                 annual_special: true, ..c // error: functional record update
3386                                           //        syntax requires a struct
3387         }
3388     }
3389 }
3390 ```
3391
3392 Rewrite the expression without functional record update syntax:
3393
3394 ```
3395 enum PublicationFrequency {
3396     Weekly,
3397     SemiMonthly { days: (u8, u8), annual_special: bool },
3398 }
3399
3400 fn one_up_competitor(competitor_frequency: PublicationFrequency)
3401                      -> PublicationFrequency {
3402     match competitor_frequency {
3403         PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3404             days: (1, 15), annual_special: false
3405         },
3406         PublicationFrequency::SemiMonthly{ days, .. } =>
3407             PublicationFrequency::SemiMonthly {
3408                 days, annual_special: true // ok!
3409         }
3410     }
3411 }
3412 ```
3413 "##,
3414
3415 E0439: r##"
3416 The length of the platform-intrinsic function `simd_shuffle`
3417 wasn't specified. Erroneous code example:
3418
3419 ```compile_fail,E0439
3420 #![feature(platform_intrinsics)]
3421
3422 extern "platform-intrinsic" {
3423     fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3424     // error: invalid `simd_shuffle`, needs length: `simd_shuffle`
3425 }
3426 ```
3427
3428 The `simd_shuffle` function needs the length of the array passed as
3429 last parameter in its name. Example:
3430
3431 ```
3432 #![feature(platform_intrinsics)]
3433
3434 extern "platform-intrinsic" {
3435     fn simd_shuffle8<A,B>(a: A, b: A, c: [u32; 8]) -> B;
3436 }
3437 ```
3438 "##,
3439
3440 E0516: r##"
3441 The `typeof` keyword is currently reserved but unimplemented.
3442 Erroneous code example:
3443
3444 ```compile_fail,E0516
3445 fn main() {
3446     let x: typeof(92) = 92;
3447 }
3448 ```
3449
3450 Try using type inference instead. Example:
3451
3452 ```
3453 fn main() {
3454     let x = 92;
3455 }
3456 ```
3457 "##,
3458
3459 E0520: r##"
3460 A non-default implementation was already made on this type so it cannot be
3461 specialized further. Erroneous code example:
3462
3463 ```compile_fail,E0520
3464 #![feature(specialization)]
3465
3466 trait SpaceLlama {
3467     fn fly(&self);
3468 }
3469
3470 // applies to all T
3471 impl<T> SpaceLlama for T {
3472     default fn fly(&self) {}
3473 }
3474
3475 // non-default impl
3476 // applies to all `Clone` T and overrides the previous impl
3477 impl<T: Clone> SpaceLlama for T {
3478     fn fly(&self) {}
3479 }
3480
3481 // since `i32` is clone, this conflicts with the previous implementation
3482 impl SpaceLlama for i32 {
3483     default fn fly(&self) {}
3484     // error: item `fly` is provided by an `impl` that specializes
3485     //        another, but the item in the parent `impl` is not marked
3486     //        `default` and so it cannot be specialized.
3487 }
3488 ```
3489
3490 Specialization only allows you to override `default` functions in
3491 implementations.
3492
3493 To fix this error, you need to mark all the parent implementations as default.
3494 Example:
3495
3496 ```
3497 #![feature(specialization)]
3498
3499 trait SpaceLlama {
3500     fn fly(&self);
3501 }
3502
3503 // applies to all T
3504 impl<T> SpaceLlama for T {
3505     default fn fly(&self) {} // This is a parent implementation.
3506 }
3507
3508 // applies to all `Clone` T; overrides the previous impl
3509 impl<T: Clone> SpaceLlama for T {
3510     default fn fly(&self) {} // This is a parent implementation but was
3511                              // previously not a default one, causing the error
3512 }
3513
3514 // applies to i32, overrides the previous two impls
3515 impl SpaceLlama for i32 {
3516     fn fly(&self) {} // And now that's ok!
3517 }
3518 ```
3519 "##,
3520
3521 E0527: r##"
3522 The number of elements in an array or slice pattern differed from the number of
3523 elements in the array being matched.
3524
3525 Example of erroneous code:
3526
3527 ```compile_fail,E0527
3528 let r = &[1, 2, 3, 4];
3529 match r {
3530     &[a, b] => { // error: pattern requires 2 elements but array
3531                  //        has 4
3532         println!("a={}, b={}", a, b);
3533     }
3534 }
3535 ```
3536
3537 Ensure that the pattern is consistent with the size of the matched
3538 array. Additional elements can be matched with `..`:
3539
3540 ```
3541 #![feature(slice_patterns)]
3542
3543 let r = &[1, 2, 3, 4];
3544 match r {
3545     &[a, b, ..] => { // ok!
3546         println!("a={}, b={}", a, b);
3547     }
3548 }
3549 ```
3550 "##,
3551
3552 E0528: r##"
3553 An array or slice pattern required more elements than were present in the
3554 matched array.
3555
3556 Example of erroneous code:
3557
3558 ```compile_fail,E0528
3559 #![feature(slice_patterns)]
3560
3561 let r = &[1, 2];
3562 match r {
3563     &[a, b, c, rest @ ..] => { // error: pattern requires at least 3
3564                                //        elements but array has 2
3565         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3566     }
3567 }
3568 ```
3569
3570 Ensure that the matched array has at least as many elements as the pattern
3571 requires. You can match an arbitrary number of remaining elements with `..`:
3572
3573 ```
3574 #![feature(slice_patterns)]
3575
3576 let r = &[1, 2, 3, 4, 5];
3577 match r {
3578     &[a, b, c, rest @ ..] => { // ok!
3579         // prints `a=1, b=2, c=3 rest=[4, 5]`
3580         println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3581     }
3582 }
3583 ```
3584 "##,
3585
3586 E0529: r##"
3587 An array or slice pattern was matched against some other type.
3588
3589 Example of erroneous code:
3590
3591 ```compile_fail,E0529
3592 let r: f32 = 1.0;
3593 match r {
3594     [a, b] => { // error: expected an array or slice, found `f32`
3595         println!("a={}, b={}", a, b);
3596     }
3597 }
3598 ```
3599
3600 Ensure that the pattern and the expression being matched on are of consistent
3601 types:
3602
3603 ```
3604 let r = [1.0, 2.0];
3605 match r {
3606     [a, b] => { // ok!
3607         println!("a={}, b={}", a, b);
3608     }
3609 }
3610 ```
3611 "##,
3612
3613 E0534: r##"
3614 The `inline` attribute was malformed.
3615
3616 Erroneous code example:
3617
3618 ```ignore (compile_fail not working here; see Issue #43707)
3619 #[inline()] // error: expected one argument
3620 pub fn something() {}
3621
3622 fn main() {}
3623 ```
3624
3625 The parenthesized `inline` attribute requires the parameter to be specified:
3626
3627 ```
3628 #[inline(always)]
3629 fn something() {}
3630 ```
3631
3632 or:
3633
3634 ```
3635 #[inline(never)]
3636 fn something() {}
3637 ```
3638
3639 Alternatively, a paren-less version of the attribute may be used to hint the
3640 compiler about inlining opportunity:
3641
3642 ```
3643 #[inline]
3644 fn something() {}
3645 ```
3646
3647 For more information about the inline attribute, read:
3648 https://doc.rust-lang.org/reference.html#inline-attributes
3649 "##,
3650
3651 E0535: r##"
3652 An unknown argument was given to the `inline` attribute.
3653
3654 Erroneous code example:
3655
3656 ```ignore (compile_fail not working here; see Issue #43707)
3657 #[inline(unknown)] // error: invalid argument
3658 pub fn something() {}
3659
3660 fn main() {}
3661 ```
3662
3663 The `inline` attribute only supports two arguments:
3664
3665  * always
3666  * never
3667
3668 All other arguments given to the `inline` attribute will return this error.
3669 Example:
3670
3671 ```
3672 #[inline(never)] // ok!
3673 pub fn something() {}
3674
3675 fn main() {}
3676 ```
3677
3678 For more information about the inline attribute, https:
3679 read://doc.rust-lang.org/reference.html#inline-attributes
3680 "##,
3681
3682 E0559: r##"
3683 An unknown field was specified into an enum's structure variant.
3684
3685 Erroneous code example:
3686
3687 ```compile_fail,E0559
3688 enum Field {
3689     Fool { x: u32 },
3690 }
3691
3692 let s = Field::Fool { joke: 0 };
3693 // error: struct variant `Field::Fool` has no field named `joke`
3694 ```
3695
3696 Verify you didn't misspell the field's name or that the field exists. Example:
3697
3698 ```
3699 enum Field {
3700     Fool { joke: u32 },
3701 }
3702
3703 let s = Field::Fool { joke: 0 }; // ok!
3704 ```
3705 "##,
3706
3707 E0560: r##"
3708 An unknown field was specified into a structure.
3709
3710 Erroneous code example:
3711
3712 ```compile_fail,E0560
3713 struct Simba {
3714     mother: u32,
3715 }
3716
3717 let s = Simba { mother: 1, father: 0 };
3718 // error: structure `Simba` has no field named `father`
3719 ```
3720
3721 Verify you didn't misspell the field's name or that the field exists. Example:
3722
3723 ```
3724 struct Simba {
3725     mother: u32,
3726     father: u32,
3727 }
3728
3729 let s = Simba { mother: 1, father: 0 }; // ok!
3730 ```
3731 "##,
3732
3733 E0569: r##"
3734 If an impl has a generic parameter with the `#[may_dangle]` attribute, then
3735 that impl must be declared as an `unsafe impl.
3736
3737 Erroneous code example:
3738
3739 ```compile_fail,E0569
3740 #![feature(dropck_eyepatch)]
3741
3742 struct Foo<X>(X);
3743 impl<#[may_dangle] X> Drop for Foo<X> {
3744     fn drop(&mut self) { }
3745 }
3746 ```
3747
3748 In this example, we are asserting that the destructor for `Foo` will not
3749 access any data of type `X`, and require this assertion to be true for
3750 overall safety in our program. The compiler does not currently attempt to
3751 verify this assertion; therefore we must tag this `impl` as unsafe.
3752 "##,
3753
3754 E0570: r##"
3755 The requested ABI is unsupported by the current target.
3756
3757 The rust compiler maintains for each target a blacklist of ABIs unsupported on
3758 that target. If an ABI is present in such a list this usually means that the
3759 target / ABI combination is currently unsupported by llvm.
3760
3761 If necessary, you can circumvent this check using custom target specifications.
3762 "##,
3763
3764 E0572: r##"
3765 A return statement was found outside of a function body.
3766
3767 Erroneous code example:
3768
3769 ```compile_fail,E0572
3770 const FOO: u32 = return 0; // error: return statement outside of function body
3771
3772 fn main() {}
3773 ```
3774
3775 To fix this issue, just remove the return keyword or move the expression into a
3776 function. Example:
3777
3778 ```
3779 const FOO: u32 = 0;
3780
3781 fn some_fn() -> u32 {
3782     return FOO;
3783 }
3784
3785 fn main() {
3786     some_fn();
3787 }
3788 ```
3789 "##,
3790
3791 E0581: r##"
3792 In a `fn` type, a lifetime appears only in the return type,
3793 and not in the arguments types.
3794
3795 Erroneous code example:
3796
3797 ```compile_fail,E0581
3798 fn main() {
3799     // Here, `'a` appears only in the return type:
3800     let x: for<'a> fn() -> &'a i32;
3801 }
3802 ```
3803
3804 To fix this issue, either use the lifetime in the arguments, or use
3805 `'static`. Example:
3806
3807 ```
3808 fn main() {
3809     // Here, `'a` appears only in the return type:
3810     let x: for<'a> fn(&'a i32) -> &'a i32;
3811     let y: fn() -> &'static i32;
3812 }
3813 ```
3814
3815 Note: The examples above used to be (erroneously) accepted by the
3816 compiler, but this was since corrected. See [issue #33685] for more
3817 details.
3818
3819 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3820 "##,
3821
3822 E0582: r##"
3823 A lifetime appears only in an associated-type binding,
3824 and not in the input types to the trait.
3825
3826 Erroneous code example:
3827
3828 ```compile_fail,E0582
3829 fn bar<F>(t: F)
3830     // No type can satisfy this requirement, since `'a` does not
3831     // appear in any of the input types (here, `i32`):
3832     where F: for<'a> Fn(i32) -> Option<&'a i32>
3833 {
3834 }
3835
3836 fn main() { }
3837 ```
3838
3839 To fix this issue, either use the lifetime in the inputs, or use
3840 `'static`. Example:
3841
3842 ```
3843 fn bar<F, G>(t: F, u: G)
3844     where F: for<'a> Fn(&'a i32) -> Option<&'a i32>,
3845           G: Fn(i32) -> Option<&'static i32>,
3846 {
3847 }
3848
3849 fn main() { }
3850 ```
3851
3852 Note: The examples above used to be (erroneously) accepted by the
3853 compiler, but this was since corrected. See [issue #33685] for more
3854 details.
3855
3856 [issue #33685]: https://github.com/rust-lang/rust/issues/33685
3857 "##,
3858
3859 E0592: r##"
3860 This error occurs when you defined methods or associated functions with same
3861 name.
3862
3863 Erroneous code example:
3864
3865 ```compile_fail,E0592
3866 struct Foo;
3867
3868 impl Foo {
3869     fn bar() {} // previous definition here
3870 }
3871
3872 impl Foo {
3873     fn bar() {} // duplicate definition here
3874 }
3875 ```
3876
3877 A similar error is E0201. The difference is whether there is one declaration
3878 block or not. To avoid this error, you must give each `fn` a unique name.
3879
3880 ```
3881 struct Foo;
3882
3883 impl Foo {
3884     fn bar() {}
3885 }
3886
3887 impl Foo {
3888     fn baz() {} // define with different name
3889 }
3890 ```
3891 "##,
3892
3893 E0599: r##"
3894 This error occurs when a method is used on a type which doesn't implement it:
3895
3896 Erroneous code example:
3897
3898 ```compile_fail,E0599
3899 struct Mouth;
3900
3901 let x = Mouth;
3902 x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
3903                //        in the current scope
3904 ```
3905 "##,
3906
3907 E0600: r##"
3908 An unary operator was used on a type which doesn't implement it.
3909
3910 Example of erroneous code:
3911
3912 ```compile_fail,E0600
3913 enum Question {
3914     Yes,
3915     No,
3916 }
3917
3918 !Question::Yes; // error: cannot apply unary operator `!` to type `Question`
3919 ```
3920
3921 In this case, `Question` would need to implement the `std::ops::Not` trait in
3922 order to be able to use `!` on it. Let's implement it:
3923
3924 ```
3925 use std::ops::Not;
3926
3927 enum Question {
3928     Yes,
3929     No,
3930 }
3931
3932 // We implement the `Not` trait on the enum.
3933 impl Not for Question {
3934     type Output = bool;
3935
3936     fn not(self) -> bool {
3937         match self {
3938             Question::Yes => false, // If the `Answer` is `Yes`, then it
3939                                     // returns false.
3940             Question::No => true, // And here we do the opposite.
3941         }
3942     }
3943 }
3944
3945 assert_eq!(!Question::Yes, false);
3946 assert_eq!(!Question::No, true);
3947 ```
3948 "##,
3949
3950 E0608: r##"
3951 An attempt to index into a type which doesn't implement the `std::ops::Index`
3952 trait was performed.
3953
3954 Erroneous code example:
3955
3956 ```compile_fail,E0608
3957 0u8[2]; // error: cannot index into a value of type `u8`
3958 ```
3959
3960 To be able to index into a type it needs to implement the `std::ops::Index`
3961 trait. Example:
3962
3963 ```
3964 let v: Vec<u8> = vec![0, 1, 2, 3];
3965
3966 // The `Vec` type implements the `Index` trait so you can do:
3967 println!("{}", v[2]);
3968 ```
3969 "##,
3970
3971 E0604: r##"
3972 A cast to `char` was attempted on a type other than `u8`.
3973
3974 Erroneous code example:
3975
3976 ```compile_fail,E0604
3977 0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
3978 ```
3979
3980 As the error message indicates, only `u8` can be cast into `char`. Example:
3981
3982 ```
3983 let c = 86u8 as char; // ok!
3984 assert_eq!(c, 'V');
3985 ```
3986
3987 For more information about casts, take a look at the Type cast section in
3988 [The Reference Book][1].
3989
3990 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
3991 "##,
3992
3993 E0605: r##"
3994 An invalid cast was attempted.
3995
3996 Erroneous code examples:
3997
3998 ```compile_fail,E0605
3999 let x = 0u8;
4000 x as Vec<u8>; // error: non-primitive cast: `u8` as `std::vec::Vec<u8>`
4001
4002 // Another example
4003
4004 let v = core::ptr::null::<u8>(); // So here, `v` is a `*const u8`.
4005 v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
4006 ```
4007
4008 Only primitive types can be cast into each other. Examples:
4009
4010 ```
4011 let x = 0u8;
4012 x as u32; // ok!
4013
4014 let v = core::ptr::null::<u8>();
4015 v as *const i8; // ok!
4016 ```
4017
4018 For more information about casts, take a look at the Type cast section in
4019 [The Reference Book][1].
4020
4021 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4022 "##,
4023
4024 E0606: r##"
4025 An incompatible cast was attempted.
4026
4027 Erroneous code example:
4028
4029 ```compile_fail,E0606
4030 let x = &0u8; // Here, `x` is a `&u8`.
4031 let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid
4032 ```
4033
4034 When casting, keep in mind that only primitive types can be cast into each
4035 other. Example:
4036
4037 ```
4038 let x = &0u8;
4039 let y: u32 = *x as u32; // We dereference it first and then cast it.
4040 ```
4041
4042 For more information about casts, take a look at the Type cast section in
4043 [The Reference Book][1].
4044
4045 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4046 "##,
4047
4048 E0607: r##"
4049 A cast between a thin and a fat pointer was attempted.
4050
4051 Erroneous code example:
4052
4053 ```compile_fail,E0607
4054 let v = core::ptr::null::<u8>();
4055 v as *const [u8];
4056 ```
4057
4058 First: what are thin and fat pointers?
4059
4060 Thin pointers are "simple" pointers: they are purely a reference to a memory
4061 address.
4062
4063 Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
4064 DST don't have a statically known size, therefore they can only exist behind
4065 some kind of pointers that contain additional information. Slices and trait
4066 objects are DSTs. In the case of slices, the additional information the fat
4067 pointer holds is their size.
4068
4069 To fix this error, don't try to cast directly between thin and fat pointers.
4070
4071 For more information about casts, take a look at the Type cast section in
4072 [The Reference Book][1].
4073
4074 [1]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
4075 "##,
4076
4077 E0609: r##"
4078 Attempted to access a non-existent field in a struct.
4079
4080 Erroneous code example:
4081
4082 ```compile_fail,E0609
4083 struct StructWithFields {
4084     x: u32,
4085 }
4086
4087 let s = StructWithFields { x: 0 };
4088 println!("{}", s.foo); // error: no field `foo` on type `StructWithFields`
4089 ```
4090
4091 To fix this error, check that you didn't misspell the field's name or that the
4092 field actually exists. Example:
4093
4094 ```
4095 struct StructWithFields {
4096     x: u32,
4097 }
4098
4099 let s = StructWithFields { x: 0 };
4100 println!("{}", s.x); // ok!
4101 ```
4102 "##,
4103
4104 E0610: r##"
4105 Attempted to access a field on a primitive type.
4106
4107 Erroneous code example:
4108
4109 ```compile_fail,E0610
4110 let x: u32 = 0;
4111 println!("{}", x.foo); // error: `{integer}` is a primitive type, therefore
4112                        //        doesn't have fields
4113 ```
4114
4115 Primitive types are the most basic types available in Rust and don't have
4116 fields. To access data via named fields, struct types are used. Example:
4117
4118 ```
4119 // We declare struct called `Foo` containing two fields:
4120 struct Foo {
4121     x: u32,
4122     y: i64,
4123 }
4124
4125 // We create an instance of this struct:
4126 let variable = Foo { x: 0, y: -12 };
4127 // And we can now access its fields:
4128 println!("x: {}, y: {}", variable.x, variable.y);
4129 ```
4130
4131 For more information about primitives and structs, take a look at The Book:
4132 https://doc.rust-lang.org/book/ch03-02-data-types.html
4133 https://doc.rust-lang.org/book/ch05-00-structs.html
4134 "##,
4135
4136 E0614: r##"
4137 Attempted to dereference a variable which cannot be dereferenced.
4138
4139 Erroneous code example:
4140
4141 ```compile_fail,E0614
4142 let y = 0u32;
4143 *y; // error: type `u32` cannot be dereferenced
4144 ```
4145
4146 Only types implementing `std::ops::Deref` can be dereferenced (such as `&T`).
4147 Example:
4148
4149 ```
4150 let y = 0u32;
4151 let x = &y;
4152 // So here, `x` is a `&u32`, so we can dereference it:
4153 *x; // ok!
4154 ```
4155 "##,
4156
4157 E0615: r##"
4158 Attempted to access a method like a field.
4159
4160 Erroneous code example:
4161
4162 ```compile_fail,E0615
4163 struct Foo {
4164     x: u32,
4165 }
4166
4167 impl Foo {
4168     fn method(&self) {}
4169 }
4170
4171 let f = Foo { x: 0 };
4172 f.method; // error: attempted to take value of method `method` on type `Foo`
4173 ```
4174
4175 If you want to use a method, add `()` after it:
4176
4177 ```
4178 # struct Foo { x: u32 }
4179 # impl Foo { fn method(&self) {} }
4180 # let f = Foo { x: 0 };
4181 f.method();
4182 ```
4183
4184 However, if you wanted to access a field of a struct check that the field name
4185 is spelled correctly. Example:
4186
4187 ```
4188 # struct Foo { x: u32 }
4189 # impl Foo { fn method(&self) {} }
4190 # let f = Foo { x: 0 };
4191 println!("{}", f.x);
4192 ```
4193 "##,
4194
4195 E0616: r##"
4196 Attempted to access a private field on a struct.
4197
4198 Erroneous code example:
4199
4200 ```compile_fail,E0616
4201 mod some_module {
4202     pub struct Foo {
4203         x: u32, // So `x` is private in here.
4204     }
4205
4206     impl Foo {
4207         pub fn new() -> Foo { Foo { x: 0 } }
4208     }
4209 }
4210
4211 let f = some_module::Foo::new();
4212 println!("{}", f.x); // error: field `x` of struct `some_module::Foo` is private
4213 ```
4214
4215 If you want to access this field, you have two options:
4216
4217 1) Set the field public:
4218
4219 ```
4220 mod some_module {
4221     pub struct Foo {
4222         pub x: u32, // `x` is now public.
4223     }
4224
4225     impl Foo {
4226         pub fn new() -> Foo { Foo { x: 0 } }
4227     }
4228 }
4229
4230 let f = some_module::Foo::new();
4231 println!("{}", f.x); // ok!
4232 ```
4233
4234 2) Add a getter function:
4235
4236 ```
4237 mod some_module {
4238     pub struct Foo {
4239         x: u32, // So `x` is still private in here.
4240     }
4241
4242     impl Foo {
4243         pub fn new() -> Foo { Foo { x: 0 } }
4244
4245         // We create the getter function here:
4246         pub fn get_x(&self) -> &u32 { &self.x }
4247     }
4248 }
4249
4250 let f = some_module::Foo::new();
4251 println!("{}", f.get_x()); // ok!
4252 ```
4253 "##,
4254
4255 E0617: r##"
4256 Attempted to pass an invalid type of variable into a variadic function.
4257
4258 Erroneous code example:
4259
4260 ```compile_fail,E0617
4261 extern {
4262     fn printf(c: *const i8, ...);
4263 }
4264
4265 unsafe {
4266     printf(::std::ptr::null(), 0f32);
4267     // error: can't pass an `f32` to variadic function, cast to `c_double`
4268 }
4269 ```
4270
4271 Certain Rust types must be cast before passing them to a variadic function,
4272 because of arcane ABI rules dictated by the C standard. To fix the error,
4273 cast the value to the type specified by the error message (which you may need
4274 to import from `std::os::raw`).
4275 "##,
4276
4277 E0618: r##"
4278 Attempted to call something which isn't a function nor a method.
4279
4280 Erroneous code examples:
4281
4282 ```compile_fail,E0618
4283 enum X {
4284     Entry,
4285 }
4286
4287 X::Entry(); // error: expected function, found `X::Entry`
4288
4289 // Or even simpler:
4290 let x = 0i32;
4291 x(); // error: expected function, found `i32`
4292 ```
4293
4294 Only functions and methods can be called using `()`. Example:
4295
4296 ```
4297 // We declare a function:
4298 fn i_am_a_function() {}
4299
4300 // And we call it:
4301 i_am_a_function();
4302 ```
4303 "##,
4304
4305 E0619: r##"
4306 #### Note: this error code is no longer emitted by the compiler.
4307 The type-checker needed to know the type of an expression, but that type had not
4308 yet been inferred.
4309
4310 Erroneous code example:
4311
4312 ```compile_fail
4313 let mut x = vec![];
4314 match x.pop() {
4315     Some(v) => {
4316         // Here, the type of `v` is not (yet) known, so we
4317         // cannot resolve this method call:
4318         v.to_uppercase(); // error: the type of this value must be known in
4319                           //        this context
4320     }
4321     None => {}
4322 }
4323 ```
4324
4325 Type inference typically proceeds from the top of the function to the bottom,
4326 figuring out types as it goes. In some cases -- notably method calls and
4327 overloadable operators like `*` -- the type checker may not have enough
4328 information *yet* to make progress. This can be true even if the rest of the
4329 function provides enough context (because the type-checker hasn't looked that
4330 far ahead yet). In this case, type annotations can be used to help it along.
4331
4332 To fix this error, just specify the type of the variable. Example:
4333
4334 ```
4335 let mut x: Vec<String> = vec![]; // We precise the type of the vec elements.
4336 match x.pop() {
4337     Some(v) => {
4338         v.to_uppercase(); // Since rustc now knows the type of the vec elements,
4339                           // we can use `v`'s methods.
4340     }
4341     None => {}
4342 }
4343 ```
4344 "##,
4345
4346 E0620: r##"
4347 A cast to an unsized type was attempted.
4348
4349 Erroneous code example:
4350
4351 ```compile_fail,E0620
4352 let x = &[1_usize, 2] as [usize]; // error: cast to unsized type: `&[usize; 2]`
4353                                   //        as `[usize]`
4354 ```
4355
4356 In Rust, some types don't have a known size at compile-time. For example, in a
4357 slice type like `[u32]`, the number of elements is not known at compile-time and
4358 hence the overall size cannot be computed. As a result, such types can only be
4359 manipulated through a reference (e.g., `&T` or `&mut T`) or other pointer-type
4360 (e.g., `Box` or `Rc`). Try casting to a reference instead:
4361
4362 ```
4363 let x = &[1_usize, 2] as &[usize]; // ok!
4364 ```
4365 "##,
4366
4367 E0622: r##"
4368 An intrinsic was declared without being a function.
4369
4370 Erroneous code example:
4371
4372 ```compile_fail,E0622
4373 #![feature(intrinsics)]
4374 extern "rust-intrinsic" {
4375     pub static breakpoint : unsafe extern "rust-intrinsic" fn();
4376     // error: intrinsic must be a function
4377 }
4378
4379 fn main() { unsafe { breakpoint(); } }
4380 ```
4381
4382 An intrinsic is a function available for use in a given programming language
4383 whose implementation is handled specially by the compiler. In order to fix this
4384 error, just declare a function.
4385 "##,
4386
4387 E0624: r##"
4388 A private item was used outside of its scope.
4389
4390 Erroneous code example:
4391
4392 ```compile_fail,E0624
4393 mod inner {
4394     pub struct Foo;
4395
4396     impl Foo {
4397         fn method(&self) {}
4398     }
4399 }
4400
4401 let foo = inner::Foo;
4402 foo.method(); // error: method `method` is private
4403 ```
4404
4405 Two possibilities are available to solve this issue:
4406
4407 1. Only use the item in the scope it has been defined:
4408
4409 ```
4410 mod inner {
4411     pub struct Foo;
4412
4413     impl Foo {
4414         fn method(&self) {}
4415     }
4416
4417     pub fn call_method(foo: &Foo) { // We create a public function.
4418         foo.method(); // Which calls the item.
4419     }
4420 }
4421
4422 let foo = inner::Foo;
4423 inner::call_method(&foo); // And since the function is public, we can call the
4424                           // method through it.
4425 ```
4426
4427 2. Make the item public:
4428
4429 ```
4430 mod inner {
4431     pub struct Foo;
4432
4433     impl Foo {
4434         pub fn method(&self) {} // It's now public.
4435     }
4436 }
4437
4438 let foo = inner::Foo;
4439 foo.method(); // Ok!
4440 ```
4441 "##,
4442
4443 E0638: r##"
4444 This error indicates that the struct, enum or enum variant must be matched
4445 non-exhaustively as it has been marked as `non_exhaustive`.
4446
4447 When applied within a crate, downstream users of the crate will need to use the
4448 `_` pattern when matching enums and use the `..` pattern when matching structs.
4449 Downstream crates cannot match against non-exhaustive enum variants.
4450
4451 For example, in the below example, since the enum is marked as
4452 `non_exhaustive`, it is required that downstream crates match non-exhaustively
4453 on it.
4454
4455 ```rust,ignore (pseudo-Rust)
4456 use std::error::Error as StdError;
4457
4458 #[non_exhaustive] pub enum Error {
4459    Message(String),
4460    Other,
4461 }
4462
4463 impl StdError for Error {
4464    fn description(&self) -> &str {
4465         // This will not error, despite being marked as non_exhaustive, as this
4466         // enum is defined within the current crate, it can be matched
4467         // exhaustively.
4468         match *self {
4469            Message(ref s) => s,
4470            Other => "other or unknown error",
4471         }
4472    }
4473 }
4474 ```
4475
4476 An example of matching non-exhaustively on the above enum is provided below:
4477
4478 ```rust,ignore (pseudo-Rust)
4479 use mycrate::Error;
4480
4481 // This will not error as the non_exhaustive Error enum has been matched with a
4482 // wildcard.
4483 match error {
4484    Message(ref s) => ...,
4485    Other => ...,
4486    _ => ...,
4487 }
4488 ```
4489
4490 Similarly, for structs, match with `..` to avoid this error.
4491 "##,
4492
4493 E0639: r##"
4494 This error indicates that the struct, enum or enum variant cannot be
4495 instantiated from outside of the defining crate as it has been marked
4496 as `non_exhaustive` and as such more fields/variants may be added in
4497 future that could cause adverse side effects for this code.
4498
4499 It is recommended that you look for a `new` function or equivalent in the
4500 crate's documentation.
4501 "##,
4502
4503 E0643: r##"
4504 This error indicates that there is a mismatch between generic parameters and
4505 impl Trait parameters in a trait declaration versus its impl.
4506
4507 ```compile_fail,E0643
4508 trait Foo {
4509     fn foo(&self, _: &impl Iterator);
4510 }
4511 impl Foo for () {
4512     fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible
4513                                           // signature for trait
4514 }
4515 ```
4516 "##,
4517
4518 E0646: r##"
4519 It is not possible to define `main` with a where clause.
4520 Erroneous code example:
4521
4522 ```compile_fail,E0646
4523 fn main() where i32: Copy { // error: main function is not allowed to have
4524                             // a where clause
4525 }
4526 ```
4527 "##,
4528
4529 E0647: r##"
4530 It is not possible to define `start` with a where clause.
4531 Erroneous code example:
4532
4533 ```compile_fail,E0647
4534 #![feature(start)]
4535
4536 #[start]
4537 fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
4538     //^ error: start function is not allowed to have a where clause
4539     0
4540 }
4541 ```
4542 "##,
4543
4544 E0648: r##"
4545 `export_name` attributes may not contain null characters (`\0`).
4546
4547 ```compile_fail,E0648
4548 #[export_name="\0foo"] // error: `export_name` may not contain null characters
4549 pub fn bar() {}
4550 ```
4551 "##,
4552
4553 E0689: r##"
4554 This error indicates that the numeric value for the method being passed exists
4555 but the type of the numeric value or binding could not be identified.
4556
4557 The error happens on numeric literals:
4558
4559 ```compile_fail,E0689
4560 2.0.neg();
4561 ```
4562
4563 and on numeric bindings without an identified concrete type:
4564
4565 ```compile_fail,E0689
4566 let x = 2.0;
4567 x.neg();  // same error as above
4568 ```
4569
4570 Because of this, you must give the numeric literal or binding a type:
4571
4572 ```
4573 use std::ops::Neg;
4574
4575 let _ = 2.0_f32.neg();
4576 let x: f32 = 2.0;
4577 let _ = x.neg();
4578 let _ = (2.0 as f32).neg();
4579 ```
4580 "##,
4581
4582 E0690: r##"
4583 A struct with the representation hint `repr(transparent)` had zero or more than
4584 one fields that were not guaranteed to be zero-sized.
4585
4586 Erroneous code example:
4587
4588 ```compile_fail,E0690
4589 #[repr(transparent)]
4590 struct LengthWithUnit<U> { // error: transparent struct needs exactly one
4591     value: f32,            //        non-zero-sized field, but has 2
4592     unit: U,
4593 }
4594 ```
4595
4596 Because transparent structs are represented exactly like one of their fields at
4597 run time, said field must be uniquely determined. If there is no field, or if
4598 there are multiple fields, it is not clear how the struct should be represented.
4599 Note that fields of zero-typed types (e.g., `PhantomData`) can also exist
4600 alongside the field that contains the actual data, they do not count for this
4601 error. When generic types are involved (as in the above example), an error is
4602 reported because the type parameter could be non-zero-sized.
4603
4604 To combine `repr(transparent)` with type parameters, `PhantomData` may be
4605 useful:
4606
4607 ```
4608 use std::marker::PhantomData;
4609
4610 #[repr(transparent)]
4611 struct LengthWithUnit<U> {
4612     value: f32,
4613     unit: PhantomData<U>,
4614 }
4615 ```
4616 "##,
4617
4618 E0691: r##"
4619 A struct, enum, or union with the `repr(transparent)` representation hint
4620 contains a zero-sized field that requires non-trivial alignment.
4621
4622 Erroneous code example:
4623
4624 ```compile_fail,E0691
4625 #![feature(repr_align)]
4626
4627 #[repr(align(32))]
4628 struct ForceAlign32;
4629
4630 #[repr(transparent)]
4631 struct Wrapper(f32, ForceAlign32); // error: zero-sized field in transparent
4632                                    //        struct has alignment larger than 1
4633 ```
4634
4635 A transparent struct, enum, or union is supposed to be represented exactly like
4636 the piece of data it contains. Zero-sized fields with different alignment
4637 requirements potentially conflict with this property. In the example above,
4638 `Wrapper` would have to be aligned to 32 bytes even though `f32` has a smaller
4639 alignment requirement.
4640
4641 Consider removing the over-aligned zero-sized field:
4642
4643 ```
4644 #[repr(transparent)]
4645 struct Wrapper(f32);
4646 ```
4647
4648 Alternatively, `PhantomData<T>` has alignment 1 for all `T`, so you can use it
4649 if you need to keep the field for some reason:
4650
4651 ```
4652 #![feature(repr_align)]
4653
4654 use std::marker::PhantomData;
4655
4656 #[repr(align(32))]
4657 struct ForceAlign32;
4658
4659 #[repr(transparent)]
4660 struct Wrapper(f32, PhantomData<ForceAlign32>);
4661 ```
4662
4663 Note that empty arrays `[T; 0]` have the same alignment requirement as the
4664 element type `T`. Also note that the error is conservatively reported even when
4665 the alignment of the zero-sized type is less than or equal to the data field's
4666 alignment.
4667 "##,
4668
4669 E0699: r##"
4670 A method was called on a raw pointer whose inner type wasn't completely known.
4671
4672 For example, you may have done something like:
4673
4674 ```compile_fail
4675 # #![deny(warnings)]
4676 let foo = &1;
4677 let bar = foo as *const _;
4678 if bar.is_null() {
4679     // ...
4680 }
4681 ```
4682
4683 Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
4684 specify a type for the pointer (preferably something that makes sense for the
4685 thing you're pointing to):
4686
4687 ```
4688 let foo = &1;
4689 let bar = foo as *const i32;
4690 if bar.is_null() {
4691     // ...
4692 }
4693 ```
4694
4695 Even though `is_null()` exists as a method on any raw pointer, Rust shows this
4696 error because  Rust allows for `self` to have arbitrary types (behind the
4697 arbitrary_self_types feature flag).
4698
4699 This means that someone can specify such a function:
4700
4701 ```ignore (cannot-doctest-feature-doesnt-exist-yet)
4702 impl Foo {
4703     fn is_null(self: *const Self) -> bool {
4704         // do something else
4705     }
4706 }
4707 ```
4708
4709 and now when you call `.is_null()` on a raw pointer to `Foo`, there's ambiguity.
4710
4711 Given that we don't know what type the pointer is, and there's potential
4712 ambiguity for some types, we disallow calling methods on raw pointers when
4713 the type is unknown.
4714 "##,
4715
4716 E0714: r##"
4717 A `#[marker]` trait contained an associated item.
4718
4719 The items of marker traits cannot be overridden, so there's no need to have them
4720 when they cannot be changed per-type anyway.  If you wanted them for ergonomic
4721 reasons, consider making an extension trait instead.
4722 "##,
4723
4724 E0715: r##"
4725 An `impl` for a `#[marker]` trait tried to override an associated item.
4726
4727 Because marker traits are allowed to have multiple implementations for the same
4728 type, it's not allowed to override anything in those implementations, as it
4729 would be ambiguous which override should actually be used.
4730 "##,
4731
4732
4733 E0720: r##"
4734 An `impl Trait` type expands to a recursive type.
4735
4736 An `impl Trait` type must be expandable to a concrete type that contains no
4737 `impl Trait` types. For example the following example tries to create an
4738 `impl Trait` type `T` that is equal to `[T, T]`:
4739
4740 ```compile_fail,E0720
4741 fn make_recursive_type() -> impl Sized {
4742     [make_recursive_type(), make_recursive_type()]
4743 }
4744 ```
4745 "##,
4746
4747 E0730: r##"
4748 An array without a fixed length was pattern-matched.
4749
4750 Example of erroneous code:
4751
4752 ```compile_fail,E0730
4753 #![feature(const_generics)]
4754
4755 fn is_123<const N: usize>(x: [u32; N]) -> bool {
4756     match x {
4757         [1, 2, 3] => true, // error: cannot pattern-match on an
4758                            //        array without a fixed length
4759         _ => false
4760     }
4761 }
4762 ```
4763
4764 Ensure that the pattern is consistent with the size of the matched
4765 array. Additional elements can be matched with `..`:
4766
4767 ```
4768 #![feature(slice_patterns)]
4769
4770 let r = &[1, 2, 3, 4];
4771 match r {
4772     &[a, b, ..] => { // ok!
4773         println!("a={}, b={}", a, b);
4774     }
4775 }
4776 ```
4777 "##,
4778
4779 E0731: r##"
4780 An enum with the representation hint `repr(transparent)` had zero or more than
4781 one variants.
4782
4783 Erroneous code example:
4784
4785 ```compile_fail,E0731
4786 #[repr(transparent)]
4787 enum Status { // error: transparent enum needs exactly one variant, but has 2
4788     Errno(u32),
4789     Ok,
4790 }
4791 ```
4792
4793 Because transparent enums are represented exactly like one of their variants at
4794 run time, said variant must be uniquely determined. If there is no variant, or
4795 if there are multiple variants, it is not clear how the enum should be
4796 represented.
4797 "##,
4798
4799 E0732: r##"
4800 An `enum` with a discriminant must specify a `#[repr(inttype)]`.
4801
4802 A `#[repr(inttype)]` must be provided on an `enum` if it has a non-unit
4803 variant with a discriminant, or where there are both unit variants with
4804 discriminants and non-unit variants. This restriction ensures that there
4805 is a well-defined way to extract a variant's discriminant from a value;
4806 for instance:
4807
4808 ```
4809 #![feature(arbitrary_enum_discriminant)]
4810
4811 #[repr(u8)]
4812 enum Enum {
4813     Unit = 3,
4814     Tuple(u16) = 2,
4815     Struct {
4816         a: u8,
4817         b: u16,
4818     } = 1,
4819 }
4820
4821 fn discriminant(v : &Enum) -> u8 {
4822     unsafe { *(v as *const Enum as *const u8) }
4823 }
4824
4825 assert_eq!(3, discriminant(&Enum::Unit));
4826 assert_eq!(2, discriminant(&Enum::Tuple(5)));
4827 assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
4828 ```
4829 "##,
4830
4831 E0733: r##"
4832 Recursion in an `async fn` requires boxing. For example, this will not compile:
4833
4834 ```edition2018,compile_fail,E0733
4835 async fn foo(n: usize) {
4836     if n > 0 {
4837         foo(n - 1).await;
4838     }
4839 }
4840 ```
4841
4842 To achieve async recursion, the `async fn` needs to be desugared
4843 such that the `Future` is explicit in the return type:
4844
4845 ```edition2018,compile_fail,E0720
4846 use std::future::Future;
4847 fn foo_desugared(n: usize) -> impl Future<Output = ()> {
4848     async move {
4849         if n > 0 {
4850             foo_desugared(n - 1).await;
4851         }
4852     }
4853 }
4854 ```
4855
4856 Finally, the future is wrapped in a pinned box:
4857
4858 ```edition2018
4859 use std::future::Future;
4860 use std::pin::Pin;
4861 fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
4862     Box::pin(async move {
4863         if n > 0 {
4864             foo_recursive(n - 1).await;
4865         }
4866     })
4867 }
4868 ```
4869
4870 The `Box<...>` ensures that the result is of known size,
4871 and the pin is required to keep it in the same place in memory.
4872 "##,
4873 ;
4874 //  E0035, merged into E0087/E0089
4875 //  E0036, merged into E0087/E0089
4876 //  E0068,
4877 //  E0085,
4878 //  E0086,
4879 //  E0103,
4880 //  E0104,
4881 //  E0122, // bounds in type aliases are ignored, turned into proper lint
4882 //  E0123,
4883 //  E0127,
4884 //  E0129,
4885 //  E0141,
4886 //  E0159, // use of trait `{}` as struct constructor
4887 //  E0163, // merged into E0071
4888 //  E0167,
4889 //  E0168,
4890 //  E0172, // non-trait found in a type sum, moved to resolve
4891 //  E0173, // manual implementations of unboxed closure traits are experimental
4892 //  E0174,
4893 //  E0182, // merged into E0229
4894     E0183,
4895 //  E0187, // can't infer the kind of the closure
4896 //  E0188, // can not cast an immutable reference to a mutable pointer
4897 //  E0189, // deprecated: can only cast a boxed pointer to a boxed object
4898 //  E0190, // deprecated: can only cast a &-pointer to an &-object
4899 //  E0194, // merged into E0403
4900 //  E0196, // cannot determine a type for this closure
4901     E0203, // type parameter has more than one relaxed default bound,
4902            // and only one is supported
4903     E0208,
4904 //  E0209, // builtin traits can only be implemented on structs or enums
4905     E0212, // cannot extract an associated type from a higher-ranked trait bound
4906 //  E0213, // associated types are not accepted in this context
4907 //  E0215, // angle-bracket notation is not stable with `Fn`
4908 //  E0216, // parenthetical notation is only stable with `Fn`
4909 //  E0217, // ambiguous associated type, defined in multiple supertraits
4910 //  E0218, // no associated type defined
4911 //  E0219, // associated type defined in higher-ranked supertrait
4912 //  E0222, // Error code E0045 (variadic function must have C or cdecl calling
4913            // convention) duplicate
4914     E0224, // at least one non-builtin train is required for an object type
4915     E0227, // ambiguous lifetime bound, explicit lifetime bound required
4916     E0228, // explicit lifetime bound required
4917 //  E0233,
4918 //  E0234,
4919 //  E0235, // structure constructor specifies a structure of type but
4920 //  E0236, // no lang item for range syntax
4921 //  E0237, // no lang item for range syntax
4922 //  E0238, // parenthesized parameters may only be used with a trait
4923 //  E0239, // `next` method of `Iterator` trait has unexpected type
4924 //  E0240,
4925 //  E0241,
4926 //  E0242,
4927 //  E0245, // not a trait
4928 //  E0246, // invalid recursive type
4929 //  E0247,
4930 //  E0248, // value used as a type, now reported earlier during resolution
4931            // as E0412
4932 //  E0249,
4933 //  E0319, // trait impls for defaulted traits allowed just for structs/enums
4934 //  E0372, // coherence not object safe
4935     E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
4936            // between structures with the same definition
4937 //  E0558, // replaced with a generic attribute input check
4938     E0533, // `{}` does not name a unit variant, unit struct or a constant
4939 //  E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
4940     E0564, // only named lifetimes are allowed in `impl Trait`,
4941            // but `{}` was found in the type `{}`
4942     E0587, // type has conflicting packed and align representation hints
4943     E0588, // packed type cannot transitively contain a `[repr(align)]` type
4944 //  E0611, // merged into E0616
4945 //  E0612, // merged into E0609
4946 //  E0613, // Removed (merged with E0609)
4947     E0627, // yield statement outside of generator literal
4948     E0632, // cannot provide explicit type parameters when `impl Trait` is used
4949            // in argument position.
4950     E0634, // type has conflicting packed representaton hints
4951     E0640, // infer outlives requirements
4952     E0641, // cannot cast to/from a pointer with an unknown kind
4953     E0645, // trait aliases not finished
4954     E0719, // duplicate values for associated type binding
4955     E0722, // Malformed `#[optimize]` attribute
4956     E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
4957 }