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