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