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