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