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