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