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