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