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