]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/diagnostics.rs
5027be5fb62a32523c6d51b306f4219704932683
[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 // Correct.
31 match x {
32     Apple(a, b) => ...
33 }
34 ```
35
36 Matching with the wrong number of fields has no sensible interpretation:
37
38 ```
39 // Incorrect.
40 match x {
41     Apple(a) => ...,
42     Apple(a, b, c) => ...
43 }
44 ```
45
46 Check how many fields the enum was declared with and ensure that your pattern
47 uses the same number.
48 "##,
49
50 E0024: r##"
51 This error indicates that a pattern attempted to extract the fields of an enum
52 variant with no fields. Here's a tiny example of this error:
53
54 ```
55 // This enum has two variants.
56 enum Number {
57     // This variant has no fields.
58     Zero,
59     // This variant has one field.
60     One(u32)
61 }
62
63 // Assuming x is a Number we can pattern match on its contents.
64 match x {
65     Zero(inside) => ...,
66     One(inside) => ...
67 }
68 ```
69
70 The pattern match `Zero(inside)` is incorrect because the `Zero` variant
71 contains no fields, yet the `inside` name attempts to bind the first field of
72 the enum.
73 "##,
74
75 E0025: r##"
76 Each field of a struct can only be bound once in a pattern. Each occurrence of a
77 field name binds the value of that field, so to fix this error you will have to
78 remove or alter the duplicate uses of the field name. Perhaps you misspelt
79 another field name?
80 "##,
81
82 E0026: r##"
83 This error indicates that a struct pattern attempted to extract a non-existant
84 field from a struct. Struct fields are identified by the name used before the
85 colon `:` so struct patterns should resemble the declaration of the struct type
86 being matched.
87
88 ```
89 // Correct matching.
90 struct Thing {
91     x: u32,
92     y: u32
93 }
94
95 let thing = Thing { x: 1, y: 2 };
96 match thing {
97     Thing { x: xfield, y: yfield } => ...
98 }
99 ```
100
101 If you are using shorthand field patterns but want to refer to the struct field
102 by a different name, you should rename it explicitly.
103
104 ```
105 // Change this:
106 match thing {
107     Thing { x, z } => ...
108 }
109
110 // To this:
111 match thing {
112     Thing { x, y: z } => ...
113 }
114 ```
115 "##,
116
117 E0027: r##"
118 This error indicates that a pattern for a struct fails to specify a sub-pattern
119 for every one of the struct's fields. Ensure that each field from the struct's
120 definition is mentioned in the pattern, or use `..` to ignore unwanted fields.
121
122 For example:
123
124 ```
125 struct Dog {
126     name: String,
127     age: u32
128 }
129
130 let d = Dog { name: "Rusty".to_string(), age: 8 };
131
132 // This is incorrect.
133 match d {
134     Dog { age: x } => ...
135 }
136
137 // This is correct (explicit).
138 match d {
139     Dog { name: n, age: x } => ...
140 }
141
142 // This is also correct (ignore unused fields).
143 match d {
144     Dog { age: x, .. } => ...
145 }
146 ```
147 "##,
148
149 E0029: r##"
150 In a match expression, only numbers and characters can be matched against a
151 range. This is because the compiler checks that the range is non-empty at
152 compile-time, and is unable to evaluate arbitrary comparison functions. If you
153 want to capture values of an orderable type between two end-points, you can use
154 a guard.
155
156 ```
157 // The ordering relation for strings can't be evaluated at compile time,
158 // so this doesn't work:
159 match string {
160     "hello" ... "world" => ...
161     _ => ...
162 }
163
164 // This is a more general version, using a guard:
165 match string {
166     s if s >= "hello" && s <= "world" => ...
167     _ => ...
168 }
169 ```
170 "##,
171
172 E0030: r##"
173 When matching against a range, the compiler verifies that the range is
174 non-empty.  Range patterns include both end-points, so this is equivalent to
175 requiring the start of the range to be less than or equal to the end of the
176 range.
177
178 For example:
179
180 ```
181 match 5u32 {
182     // This range is ok, albeit pointless.
183     1 ... 1 => ...
184     // This range is empty, and the compiler can tell.
185     1000 ... 5 => ...
186 }
187 ```
188 "##,
189
190 E0033: r##"
191 This error indicates that a pointer to a trait type cannot be implicitly
192 dereferenced by a pattern. Every trait defines a type, but because the
193 size of trait implementors isn't fixed, this type has no compile-time size.
194 Therefore, all accesses to trait types must be through pointers. If you
195 encounter this error you should try to avoid dereferencing the pointer.
196
197 ```
198 let trait_obj: &SomeTrait = ...;
199
200 // This tries to implicitly dereference to create an unsized local variable.
201 let &invalid = trait_obj;
202
203 // You can call methods without binding to the value being pointed at.
204 trait_obj.method_one();
205 trait_obj.method_two();
206 ```
207
208 You can read more about trait objects in the Trait Object section of the
209 Reference:
210
211 http://doc.rust-lang.org/reference.html#trait-objects
212 "##,
213
214 E0034: r##"
215 The compiler doesn't know what method to call because more than one method
216 has the same prototype. Example:
217
218 ```
219 struct Test;
220
221 trait Trait1 {
222     fn foo();
223 }
224
225 trait Trait2 {
226     fn foo();
227 }
228
229 impl Trait1 for Test { fn foo() {} }
230 impl Trait2 for Test { fn foo() {} }
231
232 fn main() {
233     Test::foo() // error, which foo() to call?
234 }
235 ```
236
237 To avoid this error, you have to keep only one of them and remove the others.
238 So let's take our example and fix it:
239
240 ```
241 struct Test;
242
243 trait Trait1 {
244     fn foo();
245 }
246
247 impl Trait1 for Test { fn foo() {} }
248
249 fn main() {
250     Test::foo() // and now that's good!
251 }
252 ```
253
254 However, a better solution would be using fully explicit naming of type and
255 trait:
256
257 ```
258 struct Test;
259
260 trait Trait1 {
261     fn foo();
262 }
263
264 trait Trait2 {
265     fn foo();
266 }
267
268 impl Trait1 for Test { fn foo() {} }
269 impl Trait2 for Test { fn foo() {} }
270
271 fn main() {
272     <Test as Trait1>::foo()
273 }
274 ```
275 "##,
276
277 E0035: r##"
278 You tried to give a type parameter where it wasn't needed. Bad example:
279
280 ```
281 struct Test;
282
283 impl Test {
284     fn method(&self) {}
285 }
286
287 fn main() {
288     let x = Test;
289
290     x.method::<i32>(); // Error: Test::method doesn't need type parameter!
291 }
292 ```
293
294 To fix this error, just remove the type parameter:
295
296 ```
297 struct Test;
298
299 impl Test {
300     fn method(&self) {}
301 }
302
303 fn main() {
304     let x = Test;
305
306     x.method(); // OK, we're good!
307 }
308 ```
309 "##,
310
311 E0036: r##"
312 This error occurrs when you pass too many or not enough type parameters to
313 a method. Example:
314
315 ```
316 struct Test;
317
318 impl Test {
319     fn method<T>(&self, v: &[T]) -> usize {
320         v.len()
321     }
322 }
323
324 fn main() {
325     let x = Test;
326     let v = &[0i32];
327
328     x.method::<i32, i32>(v); // error: only one type parameter is expected!
329 }
330 ```
331
332 To fix it, just specify a correct number of type parameters:
333
334 ```
335 struct Test;
336
337 impl Test {
338     fn method<T>(&self, v: &[T]) -> usize {
339         v.len()
340     }
341 }
342
343 fn main() {
344     let x = Test;
345     let v = &[0i32];
346
347     x.method::<i32>(v); // OK, we're good!
348 }
349 ```
350
351 Please note on the last example that we could have called `method` like this:
352
353 ```
354 x.method(v);
355 ```
356 "##,
357
358 E0040: r##"
359 It is not allowed to manually call destructors in Rust. It is also not
360 necessary to do this since `drop` is called automatically whenever a value goes
361 out of scope.
362
363 Here's an example of this error:
364
365 ```
366 struct Foo {
367     x: i32,
368 }
369
370 impl Drop for Foo {
371     fn drop(&mut self) {
372         println!("kaboom");
373     }
374 }
375
376 fn main() {
377     let mut x = Foo { x: -7 };
378     x.drop(); // error: explicit use of destructor method
379 }
380 ```
381 "##,
382
383 E0044: r##"
384 You can't use type parameters on foreign items. Example of erroneous code:
385
386 ```
387 extern { fn some_func<T>(x: T); }
388 ```
389
390 To fix this, replace the type parameter with the specializations that you
391 need:
392
393 ```
394 extern { fn some_func_i32(x: i32); }
395 extern { fn some_func_i64(x: i64); }
396 ```
397 "##,
398
399 E0045: r##"
400 Rust only supports variadic parameters for interoperability with C code in its
401 FFI. As such, variadic parameters can only be used with functions which are
402 using the C ABI. Examples of erroneous code:
403
404 ```
405 extern "rust-call" { fn foo(x: u8, ...); }
406 // or
407 fn foo(x: u8, ...) {}
408 ```
409
410 To fix such code, put them in an extern "C" block:
411
412 ```
413 extern "C" fn foo (x: u8, ...);
414 // or:
415 extern "C" {
416     fn foo (x: u8, ...);
417 }
418 ```
419 "##,
420
421 E0046: r##"
422 When trying to make some type implement a trait `Foo`, you must, at minimum,
423 provide implementations for all of `Foo`'s required methods (meaning the
424 methods that do not have default implementations), as well as any required
425 trait items like associated types or constants.
426 "##,
427
428 E0049: r##"
429 This error indicates that an attempted implementation of a trait method
430 has the wrong number of type parameters.
431
432 For example, the trait below has a method `foo` with a type parameter `T`,
433 but the implementation of `foo` for the type `Bar` is missing this parameter:
434
435 ```
436 trait Foo {
437     fn foo<T: Default>(x: T) -> Self;
438 }
439
440 struct Bar;
441
442 // error: method `foo` has 0 type parameters but its trait declaration has 1
443 // type parameter
444 impl Foo for Bar {
445     fn foo(x: bool) -> Self { Bar }
446 }
447 ```
448 "##,
449
450 E0050: r##"
451 This error indicates that an attempted implementation of a trait method
452 has the wrong number of function parameters.
453
454 For example, the trait below has a method `foo` with two function parameters
455 (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
456 the `u8` parameter:
457
458 ```
459 trait Foo {
460     fn foo(&self, x: u8) -> bool;
461 }
462
463 struct Bar;
464
465 // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
466 // has 2
467 impl Foo for Bar {
468     fn foo(&self) -> bool { true }
469 }
470 ```
471 "##,
472
473 E0053: r##"
474 The parameters of any trait method must match between a trait implementation
475 and the trait definition.
476
477 Here are a couple examples of this error:
478
479 ```
480 trait Foo {
481     fn foo(x: u16);
482     fn bar(&self);
483 }
484
485 struct Bar;
486
487 impl Foo for Bar {
488     // error, expected u16, found i16
489     fn foo(x: i16) { }
490
491     // error, values differ in mutability
492     fn bar(&mut self) { }
493 }
494 ```
495 "##,
496
497 E0054: r##"
498 It is not allowed to cast to a bool. If you are trying to cast a numeric type
499 to a bool, you can compare it with zero instead:
500
501 ```
502 let x = 5;
503
504 // Ok
505 let x_is_nonzero = x != 0;
506
507 // Not allowed, won't compile
508 let x_is_nonzero = x as bool;
509 ```
510 "##,
511
512 E0055: r##"
513 During a method call, a value is automatically dereferenced as many times as
514 needed to make the value's type match the method's receiver. The catch is that
515 the compiler will only attempt to dereference a number of times up to the
516 recursion limit (which can be set via the `recursion_limit` attribute).
517
518 For a somewhat artificial example:
519
520 ```
521 #![recursion_limit="2"]
522
523 struct Foo;
524
525 impl Foo {
526     fn foo(&self) {}
527 }
528
529 fn main() {
530     let foo = Foo;
531     let ref_foo = &&Foo;
532
533     // error, reached the recursion limit while auto-dereferencing &&Foo
534     ref_foo.foo();
535 }
536 ```
537
538 One fix may be to increase the recursion limit. Note that it is possible to
539 create an infinite recursion of dereferencing, in which case the only fix is to
540 somehow break the recursion.
541 "##,
542
543 E0057: r##"
544 When invoking closures or other implementations of the function traits `Fn`,
545 `FnMut` or `FnOnce` using call notation, the number of parameters passed to the
546 function must match its definition.
547
548 An example using a closure:
549
550 ```
551 let f = |x| x * 3;
552 let a = f();        // invalid, too few parameters
553 let b = f(4);       // this works!
554 let c = f(2, 3);    // invalid, too many parameters
555 ```
556
557 A generic function must be treated similarly:
558
559 ```
560 fn foo<F: Fn()>(f: F) {
561     f(); // this is valid, but f(3) would not work
562 }
563 ```
564 "##,
565
566 E0059: r##"
567 The built-in function traits are generic over a tuple of the function arguments.
568 If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
569 (`Fn(T) -> U`) to denote the function trait, the type parameter should be a
570 tuple. Otherwise function call notation cannot be used and the trait will not be
571 implemented by closures.
572
573 The most likely source of this error is using angle-bracket notation without
574 wrapping the function argument type into a tuple, for example:
575
576 ```
577 fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
578 ```
579
580 It can be fixed by adjusting the trait bound like this:
581
582 ```
583 fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
584 ```
585
586 Note that `(T,)` always denotes the type of a 1-tuple containing an element of
587 type `T`. The comma is necessary for syntactic disambiguation.
588 "##,
589
590 E0060: r##"
591 External C functions are allowed to be variadic. However, a variadic function
592 takes a minimum number of arguments. For example, consider C's variadic `printf`
593 function:
594
595 ```
596 extern crate libc;
597 use libc::{ c_char, c_int };
598
599 extern "C" {
600     fn printf(_: *const c_char, ...) -> c_int;
601 }
602 ```
603
604 Using this declaration, it must be called with at least one argument, so
605 simply calling `printf()` is illegal. But the following uses are allowed:
606
607 ```
608 unsafe {
609     use std::ffi::CString;
610
611     printf(CString::new("test\n").unwrap().as_ptr());
612     printf(CString::new("number = %d\n").unwrap().as_ptr(), 3);
613     printf(CString::new("%d, %d\n").unwrap().as_ptr(), 10, 5);
614 }
615 ```
616 "##,
617
618 E0061: r##"
619 The number of arguments passed to a function must match the number of arguments
620 specified in the function signature.
621
622 For example, a function like
623
624 ```
625 fn f(a: u16, b: &str) {}
626 ```
627
628 must always be called with exactly two arguments, e.g. `f(2, "test")`.
629
630 Note, that Rust does not have a notion of optional function arguments or
631 variadic functions (except for its C-FFI).
632 "##,
633
634 E0062: r##"
635 This error indicates that during an attempt to build a struct or struct-like
636 enum variant, one of the fields was specified more than once. Each field should
637 be specified exactly one time.
638 "##,
639
640 E0063: r##"
641 This error indicates that during an attempt to build a struct or struct-like
642 enum variant, one of the fields was not provided. Each field should be
643 specified exactly once.
644 "##,
645
646 E0066: r##"
647 Box placement expressions (like C++'s "placement new") do not yet support any
648 place expression except the exchange heap (i.e. `std::boxed::HEAP`).
649 Furthermore, the syntax is changing to use `in` instead of `box`. See [RFC 470]
650 and [RFC 809] for more details.
651
652 [RFC 470]: https://github.com/rust-lang/rfcs/pull/470
653 [RFC 809]: https://github.com/rust-lang/rfcs/pull/809
654 "##,
655
656 E0067: r##"
657 The left-hand side of a compound assignment expression must be an lvalue
658 expression. An lvalue expression represents a memory location and includes
659 item paths (ie, namespaced variables), dereferences, indexing expressions,
660 and field references.
661
662 Let's start with some bad examples:
663 ```
664 use std::collections::LinkedList;
665
666 // Bad: assignment to non-lvalue expression
667 LinkedList::new() += 1;
668
669 // ...
670
671 fn some_func(i: &mut i32) {
672     i += 12; // Error : '+=' operation cannot be applied on a reference !
673 }
674
675 And now some good examples:
676 ```
677 let mut i : i32 = 0;
678
679 i += 12; // Good !
680
681 // ...
682
683 fn some_func(i: &mut i32) {
684     *i += 12; // Good !
685 }
686
687 ```
688 "##,
689
690 E0069: r##"
691 The compiler found a function whose body contains a `return;` statement but
692 whose return type is not `()`. An example of this is:
693
694 ```
695 // error
696 fn foo() -> u8 {
697     return;
698 }
699 ```
700
701 Since `return;` is just like `return ();`, there is a mismatch between the
702 function's return type and the value being returned.
703 "##,
704
705 E0070: r##"
706 The left-hand side of an assignment operator must be an lvalue expression. An
707 lvalue expression represents a memory location and can be a variable (with
708 optional namespacing), a dereference, an indexing expression or a field
709 reference.
710
711 More details can be found here:
712 https://doc.rust-lang.org/reference.html#lvalues,-rvalues-and-temporaries
713
714 Now, we can go further. Here are some bad examples:
715 ```
716 struct SomeStruct {
717     x: i32,
718     y: i32
719 }
720 const SOME_CONST : i32 = 12;
721
722 fn some_other_func() {}
723
724 fn some_function() {
725     SOME_CONST = 14; // error : a constant value cannot be changed!
726     1 = 3; // error : 1 isn't a valid lvalue!
727     some_other_func() = 4; // error : we can't assign value to a function!
728     SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
729                        // like a variable!
730 }
731 ```
732
733 And now let's give good examples:
734
735 ```
736 struct SomeStruct {
737     x: i32,
738     y: i32
739 }
740 let mut s = SomeStruct {x: 0, y: 0};
741
742 s.x = 3; // that's good !
743
744 // ...
745
746 fn some_func(x: &mut i32) {
747     *x = 12; // that's good !
748 }
749 ```
750 "##,
751
752 E0071: r##"
753 You tried to use a structure initialization with a non-structure type.
754 Example of erroneous code:
755
756 ```
757 enum Foo { FirstValue };
758
759 let u = Foo::FirstValue { value: 0i32 }; // error: Foo::FirstValue
760                                          // isn't a structure!
761 // or even simpler, if the structure wasn't defined at all:
762 let u = RandomName { random_field: 0i32 }; // error: RandomName
763                                            // isn't a structure!
764 ```
765
766 To fix this, please check:
767  * Did you spell it right?
768  * Did you accidentaly used an enum as a struct?
769  * Did you accidentaly make an enum when you intended to use a struct?
770
771 Here is the previous code with all missing information:
772
773 ```
774 struct Inner {
775     value: i32
776 }
777
778 enum Foo {
779     FirstValue(Inner)
780 }
781
782 fn main() {
783     let u = Foo::FirstValue(Inner { value: 0i32 });
784
785     let t = Inner { value: 0i32 };
786 }
787 ```
788 "##,
789
790 E0072: r##"
791 When defining a recursive struct or enum, any use of the type being defined
792 from inside the definition must occur behind a pointer (like `Box` or `&`).
793 This is because structs and enums must have a well-defined size, and without
794 the pointer the size of the type would need to be unbounded.
795
796 Consider the following erroneous definition of a type for a list of bytes:
797
798 ```
799 // error, illegal recursive struct type
800 struct ListNode {
801     head: u8,
802     tail: Option<ListNode>,
803 }
804 ```
805
806 This type cannot have a well-defined size, because it needs to be arbitrarily
807 large (since we would be able to nest `ListNode`s to any depth). Specifically,
808
809 ```plain
810 size of `ListNode` = 1 byte for `head`
811                    + 1 byte for the discriminant of the `Option`
812                    + size of `ListNode`
813 ```
814
815 One way to fix this is by wrapping `ListNode` in a `Box`, like so:
816
817 ```
818 struct ListNode {
819     head: u8,
820     tail: Option<Box<ListNode>>,
821 }
822 ```
823
824 This works because `Box` is a pointer, so its size is well-known.
825 "##,
826
827 E0073: r##"
828 You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
829 in order to make a new `Foo` value. This is because there would be no way a
830 first instance of `Foo` could be made to initialize another instance!
831
832 Here's an example of a struct that has this problem:
833
834 ```
835 struct Foo { x: Box<Foo> } // error
836 ```
837
838 One fix is to use `Option`, like so:
839
840 ```
841 struct Foo { x: Option<Box<Foo>> }
842 ```
843
844 Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
845 "##,
846
847 E0081: r##"
848 Enum discriminants are used to differentiate enum variants stored in memory.
849 This error indicates that the same value was used for two or more variants,
850 making them impossible to tell apart.
851
852 ```
853 // Good.
854 enum Enum {
855     P,
856     X = 3,
857     Y = 5
858 }
859
860 // Bad.
861 enum Enum {
862     P = 3,
863     X = 3,
864     Y = 5
865 }
866 ```
867
868 Note that variants without a manually specified discriminant are numbered from
869 top to bottom starting from 0, so clashes can occur with seemingly unrelated
870 variants.
871
872 ```
873 enum Bad {
874     X,
875     Y = 0
876 }
877 ```
878
879 Here `X` will have already been assigned the discriminant 0 by the time `Y` is
880 encountered, so a conflict occurs.
881 "##,
882
883 E0082: r##"
884 The default type for enum discriminants is `isize`, but it can be adjusted by
885 adding the `repr` attribute to the enum declaration. This error indicates that
886 an integer literal given as a discriminant is not a member of the discriminant
887 type. For example:
888
889 ```
890 #[repr(u8)]
891 enum Thing {
892     A = 1024,
893     B = 5
894 }
895 ```
896
897 Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
898 invalid. You may want to change representation types to fix this, or else change
899 invalid discriminant values so that they fit within the existing type.
900
901 Note also that without a representation manually defined, the compiler will
902 optimize by using the smallest integer type possible.
903 "##,
904
905 E0083: r##"
906 At present, it's not possible to define a custom representation for an enum with
907 a single variant. As a workaround you can add a `Dummy` variant.
908
909 See: https://github.com/rust-lang/rust/issues/10292
910 "##,
911
912 E0084: r##"
913 It is impossible to define an integer type to be used to represent zero-variant
914 enum values because there are no zero-variant enum values. There is no way to
915 construct an instance of the following type using only safe code:
916
917 ```
918 enum Empty {}
919 ```
920 "##,
921
922 E0087: r##"
923 Too many type parameters were supplied for a function. For example:
924
925 ```
926 fn foo<T>() {}
927
928 fn main() {
929     foo::<f64, bool>(); // error, expected 1 parameter, found 2 parameters
930 }
931 ```
932
933 The number of supplied parameters much exactly match the number of defined type
934 parameters.
935 "##,
936
937 E0088: r##"
938 You gave too many lifetime parameters. Erroneous code example:
939
940 ```
941 fn f() {}
942
943 fn main() {
944     f::<'static>() // error: too many lifetime parameters provided
945 }
946 ```
947
948 Please check you give the right number of lifetime parameters. Example:
949
950 ```
951 fn f() {}
952
953 fn main() {
954     f() // ok!
955 }
956 ```
957
958 It's also important to note that the Rust compiler can generally
959 determine the lifetime by itself. Example:
960
961 ```
962 struct Foo {
963     value: String
964 }
965
966 impl Foo {
967     // it can be written like this
968     fn get_value<'a>(&'a self) -> &'a str { &self.value }
969     // but the compiler works fine with this too:
970     fn without_lifetime(&self) -> &str { &self.value }
971 }
972
973 fn main() {
974     let f = Foo { value: "hello".to_owned() };
975
976     println!("{}", f.get_value());
977     println!("{}", f.without_lifetime());
978 }
979 ```
980 "##,
981
982 E0089: r##"
983 Not enough type parameters were supplied for a function. For example:
984
985 ```
986 fn foo<T, U>() {}
987
988 fn main() {
989     foo::<f64>(); // error, expected 2 parameters, found 1 parameter
990 }
991 ```
992
993 Note that if a function takes multiple type parameters but you want the compiler
994 to infer some of them, you can use type placeholders:
995
996 ```
997 fn foo<T, U>(x: T) {}
998
999 fn main() {
1000     let x: bool = true;
1001     foo::<f64>(x);    // error, expected 2 parameters, found 1 parameter
1002     foo::<_, f64>(x); // same as `foo::<bool, f64>(x)`
1003 }
1004 ```
1005 "##,
1006
1007 E0091: r##"
1008 You gave an unnecessary type parameter in a type alias. Erroneous code
1009 example:
1010
1011 ```
1012 type Foo<T> = u32; // error: type parameter `T` is unused
1013 // or:
1014 type Foo<A,B> = Box<A>; // error: type parameter `B` is unused
1015 ```
1016
1017 Please check you didn't write too many type parameters. Example:
1018
1019 ```
1020 type Foo = u32; // ok!
1021 type Foo<A> = Box<A>; // ok!
1022 ```
1023 "##,
1024
1025 E0092: r##"
1026 You tried to declare an undefined atomic operation function.
1027 Erroneous code example:
1028
1029 ```
1030 #![feature(intrinsics)]
1031
1032 extern "rust-intrinsic" {
1033     fn atomic_foo(); // error: unrecognized atomic operation
1034                      //        function
1035 }
1036 ```
1037
1038 Please check you didn't make a mistake in the function's name. All intrinsic
1039 functions are defined in librustc_trans/trans/intrinsic.rs and in
1040 libcore/intrinsics.rs in the Rust source code. Example:
1041
1042 ```
1043 #![feature(intrinsics)]
1044
1045 extern "rust-intrinsic" {
1046     fn atomic_fence(); // ok!
1047 }
1048 ```
1049 "##,
1050
1051 E0093: r##"
1052 You declared an unknown intrinsic function. Erroneous code example:
1053
1054 ```
1055 #![feature(intrinsics)]
1056
1057 extern "rust-intrinsic" {
1058     fn foo(); // error: unrecognized intrinsic function: `foo`
1059 }
1060
1061 fn main() {
1062     unsafe {
1063         foo();
1064     }
1065 }
1066 ```
1067
1068 Please check you didn't make a mistake in the function's name. All intrinsic
1069 functions are defined in librustc_trans/trans/intrinsic.rs and in
1070 libcore/intrinsics.rs in the Rust source code. Example:
1071
1072 ```
1073 #![feature(intrinsics)]
1074
1075 extern "rust-intrinsic" {
1076     fn atomic_fence(); // ok!
1077 }
1078
1079 fn main() {
1080     unsafe {
1081         atomic_fence();
1082     }
1083 }
1084 ```
1085 "##,
1086
1087 E0094: r##"
1088 You gave an invalid number of type parameters to an intrinsic function.
1089 Erroneous code example:
1090
1091 ```
1092 #![feature(intrinsics)]
1093
1094 extern "rust-intrinsic" {
1095     fn size_of<T, U>() -> usize; // error: intrinsic has wrong number
1096                                  //        of type parameters
1097 }
1098 ```
1099
1100 Please check that you provided the right number of lifetime parameters
1101 and verify with the function declaration in the Rust source code.
1102 Example:
1103
1104 ```
1105 #![feature(intrinsics)]
1106
1107 extern "rust-intrinsic" {
1108     fn size_of<T>() -> usize; // ok!
1109 }
1110 ```
1111 "##,
1112
1113 E0101: r##"
1114 You hit this error because the compiler the compiler lacks information
1115 to determine a type for this expression. Erroneous code example:
1116
1117 ```
1118 fn main() {
1119     let x = |_| {}; // error: cannot determine a type for this expression
1120 }
1121 ```
1122
1123 You have two possibilities to solve this situation:
1124  * Give an explicit definition of the expression
1125  * Infer the expression
1126
1127 Examples:
1128
1129 ```
1130 fn main() {
1131     let x = |_ : u32| {}; // ok!
1132     // or:
1133     let x = |_| {};
1134     x(0u32);
1135 }
1136 ```
1137 "##,
1138
1139 E0106: r##"
1140 This error indicates that a lifetime is missing from a type. If it is an error
1141 inside a function signature, the problem may be with failing to adhere to the
1142 lifetime elision rules (see below).
1143
1144 Here are some simple examples of where you'll run into this error:
1145
1146 ```
1147 struct Foo { x: &bool }        // error
1148 struct Foo<'a> { x: &'a bool } // correct
1149
1150 enum Bar { A(u8), B(&bool), }        // error
1151 enum Bar<'a> { A(u8), B(&'a bool), } // correct
1152
1153 type MyStr = &str;        // error
1154 type MyStr<'a> = &'a str; //correct
1155
1156 ```
1157
1158 Lifetime elision is a special, limited kind of inference for lifetimes in
1159 function signatures which allows you to leave out lifetimes in certain cases.
1160 For more background on lifetime elision see [the book][book-le].
1161
1162 The lifetime elision rules require that any function signature with an elided
1163 output lifetime must either have
1164
1165  - exactly one input lifetime
1166  - or, multiple input lifetimes, but the function must also be a method with a
1167    `&self` or `&mut self` receiver
1168
1169 In the first case, the output lifetime is inferred to be the same as the unique
1170 input lifetime. In the second case, the lifetime is instead inferred to be the
1171 same as the lifetime on `&self` or `&mut self`.
1172
1173 Here are some examples of elision errors:
1174
1175 ```
1176 // error, no input lifetimes
1177 fn foo() -> &str { ... }
1178
1179 // error, `x` and `y` have distinct lifetimes inferred
1180 fn bar(x: &str, y: &str) -> &str { ... }
1181
1182 // error, `y`'s lifetime is inferred to be distinct from `x`'s
1183 fn baz<'a>(x: &'a str, y: &str) -> &str { ... }
1184 ```
1185
1186 [book-le]: http://doc.rust-lang.org/nightly/book/lifetimes.html#lifetime-elision
1187 "##,
1188
1189 E0107: r##"
1190 This error means that an incorrect number of lifetime parameters were provided
1191 for a type (like a struct or enum) or trait.
1192
1193 Some basic examples include:
1194
1195 ```
1196 struct Foo<'a>(&'a str);
1197 enum Bar { A, B, C }
1198
1199 struct Baz<'a> {
1200     foo: Foo,     // error: expected 1, found 0
1201     bar: Bar<'a>, // error: expected 0, found 1
1202 }
1203 ```
1204
1205 Here's an example that is currently an error, but may work in a future version
1206 of Rust:
1207
1208 ```
1209 struct Foo<'a>(&'a str);
1210
1211 trait Quux { }
1212 impl Quux for Foo { } // error: expected 1, found 0
1213 ```
1214
1215 Lifetime elision in implementation headers was part of the lifetime elision
1216 RFC. It is, however, [currently unimplemented][iss15872].
1217
1218 [iss15872]: https://github.com/rust-lang/rust/issues/15872
1219 "##,
1220
1221 E0116: r##"
1222 You can only define an inherent implementation for a type in the same crate
1223 where the type was defined. For example, an `impl` block as below is not allowed
1224 since `Vec` is defined in the standard library:
1225
1226 ```
1227 impl Vec<u8> { ... } // error
1228 ```
1229
1230 To fix this problem, you can do either of these things:
1231
1232  - define a trait that has the desired associated functions/types/constants and
1233    implement the trait for the type in question
1234  - define a new type wrapping the type and define an implementation on the new
1235    type
1236
1237 Note that using the `type` keyword does not work here because `type` only
1238 introduces a type alias:
1239
1240 ```
1241 type Bytes = Vec<u8>;
1242
1243 impl Bytes { ... } // error, same as above
1244 ```
1245 "##,
1246
1247 E0117: r##"
1248 You got this error because because you tried to implement a foreign
1249 trait for a foreign type (with maybe a foreign type parameter). Erroneous
1250 code example:
1251
1252 ```
1253 impl Drop for u32 {}
1254 ```
1255
1256 The type, trait or the type parameter (or all of them) has to be defined
1257 in your crate. Example:
1258
1259 ```
1260 pub struct Foo; // you define your type in your crate
1261
1262 impl Drop for Foo { // and you can implement the trait on it!
1263     // code of trait implementation here
1264 }
1265
1266 trait Bar { // or define your trait in your crate
1267     fn get(&self) -> usize;
1268 }
1269
1270 impl Bar for u32 { // and then you implement it on a foreign type
1271     fn get(&self) -> usize { 0 }
1272 }
1273
1274 impl From<Foo> for i32 { // or you use a type from your crate as
1275                          // a type parameter
1276     fn from(i: Foo) -> i32 {
1277         0
1278     }
1279 }
1280 ```
1281 "##,
1282
1283 E0119: r##"
1284 There are conflicting trait implementations for the same type.
1285 Erroneous code example:
1286
1287 ```
1288 trait MyTrait {
1289     fn get(&self) -> usize;
1290 }
1291
1292 impl<T> MyTrait for T {
1293     fn get(&self) -> usize { 0 }
1294 }
1295
1296 struct Foo {
1297     value: usize
1298 }
1299
1300 impl MyTrait for Foo { // error: conflicting implementations for trait
1301                        //        `MyTrait`
1302     fn get(&self) -> usize { self.value }
1303 }
1304 ```
1305
1306 When you write:
1307
1308 ```
1309 impl<T> MyTrait for T {
1310     fn get(&self) -> usize { 0 }
1311 }
1312 ```
1313
1314 This makes the trait implemented on all types in the scope. So if you
1315 try to implement it on another one after that, the implementations will
1316 conflict. Example:
1317
1318 ```
1319 trait MyTrait {
1320     fn get(&self) -> usize;
1321 }
1322
1323 impl<T> MyTrait for T {
1324     fn get(&self) -> usize { 0 }
1325 }
1326
1327 struct Foo;
1328
1329 fn main() {
1330     let f = Foo;
1331
1332     f.get(); // the trait is implemented so we can use it
1333 }
1334 ```
1335 "##,
1336
1337 E0121: r##"
1338 In order to be consistent with Rust's lack of global type inference, type
1339 placeholders are disallowed by design in item signatures.
1340
1341 Examples of this error include:
1342
1343 ```
1344 fn foo() -> _ { 5 } // error, explicitly write out the return type instead
1345
1346 static BAR: _ = "test"; // error, explicitly write out the type instead
1347 ```
1348 "##,
1349
1350 E0124: r##"
1351 You declared two fields of a struct with the same name. Erroneous code
1352 example:
1353
1354 ```
1355 struct Foo {
1356     field1: i32,
1357     field1: i32 // error: field is already declared
1358 }
1359 ```
1360
1361 Please verify that the field names have been correctly spelled. Example:
1362
1363 ```
1364 struct Foo {
1365     field1: i32,
1366     field2: i32 // ok!
1367 }
1368 ```
1369 "##,
1370
1371 E0128: r##"
1372 Type parameter defaults can only use parameters that occur before them.
1373 Erroneous code example:
1374
1375 ```
1376 pub struct Foo<T=U, U=()> {
1377     field1: T,
1378     filed2: U,
1379 }
1380 // error: type parameters with a default cannot use forward declared
1381 // identifiers
1382 ```
1383
1384 Since type parameters are evaluated in-order, you may be able to fix this issue
1385 by doing:
1386
1387 ```
1388 pub struct Foo<U=(), T=U> {
1389     field1: T,
1390     filed2: U,
1391 }
1392 ```
1393
1394 Please also verify that this wasn't because of a name-clash and rename the type
1395 parameter if so.
1396 "##,
1397
1398 E0130: r##"
1399 You declared a pattern as an argument in a foreign function declaration.
1400 Erroneous code example:
1401
1402 ```
1403 extern {
1404     fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
1405                                 //        function declarations
1406 }
1407 ```
1408
1409 Please replace the pattern argument with a regular one. Example:
1410
1411 ```
1412 struct SomeStruct {
1413     a: u32,
1414     b: u32,
1415 }
1416
1417 extern {
1418     fn foo(s: SomeStruct); // ok!
1419 }
1420 // or
1421 extern {
1422     fn foo(a: (u32, u32)); // ok!
1423 }
1424 ```
1425 "##,
1426
1427 E0131: r##"
1428 It is not possible to define `main` with type parameters, or even with function
1429 parameters. When `main` is present, it must take no arguments and return `()`.
1430 "##,
1431
1432 E0132: r##"
1433 It is not possible to declare type parameters on a function that has the `start`
1434 attribute. Such a function must have the following type signature:
1435
1436 ```
1437 fn(isize, *const *const u8) -> isize
1438 ```
1439 "##,
1440
1441 E0159: r##"
1442 You tried to use a trait as a struct constructor. Erroneous code example:
1443
1444 ```
1445 trait TraitNotAStruct {}
1446
1447 TraitNotAStruct{ value: 0 }; // error: use of trait `TraitNotAStruct` as a
1448                              //        struct constructor
1449 ```
1450
1451 Please verify you used the correct type name or please implement the trait
1452 on a struct and use this struct constructor. Example:
1453
1454 ```
1455 trait TraitNotAStruct {}
1456
1457 struct Foo {
1458     value: i32
1459 }
1460
1461 Foo{ value: 0 }; // ok!
1462 ```
1463 "##,
1464
1465 E0166: r##"
1466 This error means that the compiler found a return expression in a function
1467 marked as diverging. A function diverges if it has `!` in the place of the
1468 return type in its signature. For example:
1469
1470 ```
1471 fn foo() -> ! { return; } // error
1472 ```
1473
1474 For a function that diverges, every control path in the function must never
1475 return, for example with a `loop` that never breaks or a call to another
1476 diverging function (such as `panic!()`).
1477 "##,
1478
1479 E0178: r##"
1480 In types, the `+` type operator has low precedence, so it is often necessary
1481 to use parentheses.
1482
1483 For example:
1484
1485 ```
1486 trait Foo {}
1487
1488 struct Bar<'a> {
1489     w: &'a Foo + Copy,   // error, use &'a (Foo + Copy)
1490     x: &'a Foo + 'a,     // error, use &'a (Foo + 'a)
1491     y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
1492     z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
1493 }
1494 ```
1495
1496 More details can be found in [RFC 438].
1497
1498 [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
1499 "##,
1500
1501 E0184: r##"
1502 Explicitly implementing both Drop and Copy for a type is currently disallowed.
1503 This feature can make some sense in theory, but the current implementation is
1504 incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so
1505 it has been disabled for now.
1506
1507 [iss20126]: https://github.com/rust-lang/rust/issues/20126
1508 "##,
1509
1510 E0185: r##"
1511 An associated function for a trait was defined to be static, but an
1512 implementation of the trait declared the same function to be a method (i.e. to
1513 take a `self` parameter).
1514
1515 Here's an example of this error:
1516
1517 ```
1518 trait Foo {
1519     fn foo();
1520 }
1521
1522 struct Bar;
1523
1524 impl Foo for Bar {
1525     // error, method `foo` has a `&self` declaration in the impl, but not in
1526     // the trait
1527     fn foo(&self) {}
1528 }
1529 "##,
1530
1531 E0186: r##"
1532 An associated function for a trait was defined to be a method (i.e. to take a
1533 `self` parameter), but an implementation of the trait declared the same function
1534 to be static.
1535
1536 Here's an example of this error:
1537
1538 ```
1539 trait Foo {
1540     fn foo(&self);
1541 }
1542
1543 struct Bar;
1544
1545 impl Foo for Bar {
1546     // error, method `foo` has a `&self` declaration in the trait, but not in
1547     // the impl
1548     fn foo() {}
1549 }
1550 ```
1551 "##,
1552
1553 E0191: r##"
1554 Trait objects need to have all associated types specified. Erroneous code
1555 example:
1556
1557 ```
1558 trait Trait {
1559     type Bar;
1560 }
1561
1562 type Foo = Trait; // error: the value of the associated type `Bar` (from
1563                   //        the trait `Trait`) must be specified
1564 ```
1565
1566 Please verify you specified all associated types of the trait and that you
1567 used the right trait. Example:
1568
1569 ```
1570 trait Trait {
1571     type Bar;
1572 }
1573
1574 type Foo = Trait<Bar=i32>; // ok!
1575 ```
1576 "##,
1577
1578 E0192: r##"
1579 Negative impls are only allowed for traits with default impls. For more
1580 information see the [opt-in builtin traits RFC](https://github.com/rust-lang/
1581 rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
1582 "##,
1583
1584 E0195: r##"
1585 Your method's lifetime parameters do not match the trait declaration.
1586 Erroneous code example:
1587
1588 ```
1589 trait Trait {
1590     fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
1591 }
1592
1593 struct Foo;
1594
1595 impl Trait for Foo {
1596     fn bar<'a,'b>(x: &'a str, y: &'b str) {
1597     // error: lifetime parameters or bounds on method `bar`
1598     // do not match the trait declaration
1599     }
1600 }
1601 ```
1602
1603 The lifetime constraint `'b` for bar() implementation does not match the
1604 trait declaration. Ensure lifetime declarations match exactly in both trait
1605 declaration and implementation. Example:
1606
1607 ```
1608 trait Trait {
1609     fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1610 }
1611
1612 struct Foo;
1613
1614 impl Trait for Foo {
1615     fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
1616     }
1617 }
1618 ```
1619 "##,
1620
1621 E0197: r##"
1622 Inherent implementations (one that do not implement a trait but provide
1623 methods associated with a type) are always safe because they are not
1624 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
1625 implementation will resolve this error.
1626
1627 ```
1628 struct Foo;
1629
1630 // this will cause this error
1631 unsafe impl Foo { }
1632 // converting it to this will fix it
1633 impl Foo { }
1634 ```
1635
1636 "##,
1637
1638 E0198: r##"
1639 A negative implementation is one that excludes a type from implementing a
1640 particular trait. Not being able to use a trait is always a safe operation,
1641 so negative implementations are always safe and never need to be marked as
1642 unsafe.
1643
1644 ```
1645 struct Foo;
1646
1647 // unsafe is unnecessary
1648 unsafe impl !Clone for Foo { }
1649 // this will compile
1650 impl !Clone for Foo { }
1651 ```
1652
1653 "##,
1654
1655 E0199: r##"
1656 Safe traits should not have unsafe implementations, therefore marking an
1657 implementation for a safe trait unsafe will cause a compiler error. Removing the
1658 unsafe marker on the trait noted in the error will resolve this problem.
1659
1660 ```
1661 struct Foo;
1662
1663 trait Bar { }
1664
1665 // this won't compile because Bar is safe
1666 unsafe impl Bar for Foo { }
1667 // this will compile
1668 impl Bar for Foo { }
1669 ```
1670
1671 "##,
1672
1673 E0200: r##"
1674 Unsafe traits must have unsafe implementations. This error occurs when an
1675 implementation for an unsafe trait isn't marked as unsafe. This may be resolved
1676 by marking the unsafe implementation as unsafe.
1677
1678 ```
1679 struct Foo;
1680
1681 unsafe trait Bar { }
1682
1683 // this won't compile because Bar is unsafe and impl isn't unsafe
1684 impl Bar for Foo { }
1685 // this will compile
1686 unsafe impl Bar for Foo { }
1687 ```
1688
1689 "##,
1690
1691 E0201: r##"
1692 It is an error to define an associated function more than once.
1693
1694 For example:
1695
1696 ```
1697 struct Foo(u8);
1698
1699 impl Foo {
1700     fn bar(&self) -> bool { self.0 > 5 }
1701
1702     // error: duplicate associated function
1703     fn bar() {}
1704 }
1705
1706 trait Baz {
1707     fn baz(&self) -> bool;
1708 }
1709
1710 impl Baz for Foo {
1711     fn baz(&self) -> bool { true }
1712
1713     // error: duplicate method
1714     fn baz(&self) -> bool { self.0 > 5 }
1715 }
1716 ```
1717 "##,
1718
1719 E0202: r##"
1720 Inherent associated types were part of [RFC 195] but are not yet implemented.
1721 See [the tracking issue][iss8995] for the status of this implementation.
1722
1723 [RFC 195]: https://github.com/rust-lang/rfcs/pull/195
1724 [iss8995]: https://github.com/rust-lang/rust/issues/8995
1725 "##,
1726
1727 E0204: r##"
1728 An attempt to implement the `Copy` trait for a struct failed because one of the
1729 fields does not implement `Copy`. To fix this, you must implement `Copy` for the
1730 mentioned field. Note that this may not be possible, as in the example of
1731
1732 ```
1733 struct Foo {
1734     foo : Vec<u32>,
1735 }
1736
1737 impl Copy for Foo { }
1738 ```
1739
1740 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1741
1742 Here's another example that will fail:
1743
1744 ```
1745 #[derive(Copy)]
1746 struct Foo<'a> {
1747     ty: &'a mut bool,
1748 }
1749 ```
1750
1751 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1752 differs from the behavior for `&T`, which is always `Copy`).
1753 "##,
1754
1755 E0205: r##"
1756 An attempt to implement the `Copy` trait for an enum failed because one of the
1757 variants does not implement `Copy`. To fix this, you must implement `Copy` for
1758 the mentioned variant. Note that this may not be possible, as in the example of
1759
1760 ```
1761 enum Foo {
1762     Bar(Vec<u32>),
1763     Baz,
1764 }
1765
1766 impl Copy for Foo { }
1767 ```
1768
1769 This fails because `Vec<T>` does not implement `Copy` for any `T`.
1770
1771 Here's another example that will fail:
1772
1773 ```
1774 #[derive(Copy)]
1775 enum Foo<'a> {
1776     Bar(&'a mut bool),
1777     Baz
1778 }
1779 ```
1780
1781 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
1782 differs from the behavior for `&T`, which is always `Copy`).
1783 "##,
1784
1785 E0206: r##"
1786 You can only implement `Copy` for a struct or enum. Both of the following
1787 examples will fail, because neither `i32` (primitive type) nor `&'static Bar`
1788 (reference to `Bar`) is a struct or enum:
1789
1790 ```
1791 type Foo = i32;
1792 impl Copy for Foo { } // error
1793
1794 #[derive(Copy, Clone)]
1795 struct Bar;
1796 impl Copy for &'static Bar { } // error
1797 ```
1798 "##,
1799
1800 E0207: r##"
1801 You declared an unused type parameter when implementing a trait on an object.
1802 Erroneous code example:
1803
1804 ```
1805 trait MyTrait {
1806     fn get(&self) -> usize;
1807 }
1808
1809 struct Foo;
1810
1811 impl<T> MyTrait for Foo {
1812     fn get(&self) -> usize {
1813         0
1814     }
1815 }
1816 ```
1817
1818 Please check your object definition and remove unused type
1819 parameter(s). Example:
1820
1821 ```
1822 trait MyTrait {
1823     fn get(&self) -> usize;
1824 }
1825
1826 struct Foo;
1827
1828 impl MyTrait for Foo {
1829     fn get(&self) -> usize {
1830         0
1831     }
1832 }
1833 ```
1834 "##,
1835
1836 E0211: r##"
1837 You used an intrinsic function which doesn't correspond to its
1838 definition. Erroneous code example:
1839
1840 ```
1841 #![feature(intrinsics)]
1842
1843 extern "rust-intrinsic" {
1844     fn size_of<T>(); // error: intrinsic has wrong type
1845 }
1846 ```
1847
1848 Please check the function definition. Example:
1849
1850 ```
1851 #![feature(intrinsics)]
1852
1853 extern "rust-intrinsic" {
1854     fn size_of<T>() -> usize;
1855 }
1856 ```
1857 "##,
1858
1859 E0220: r##"
1860 You used an associated type which isn't defined in the trait.
1861 Erroneous code example:
1862
1863 ```
1864 trait Trait {
1865     type Bar;
1866 }
1867
1868 type Foo = Trait<F=i32>; // error: associated type `F` not found for
1869                          //        `Trait`
1870 ```
1871
1872 Please verify you used the right trait or you didn't misspell the
1873 associated type name. Example:
1874
1875 ```
1876 trait Trait {
1877     type Bar;
1878 }
1879
1880 type Foo = Trait<Bar=i32>; // ok!
1881 ```
1882 "##,
1883
1884 E0232: r##"
1885 The attribute must have a value. Erroneous code example:
1886
1887 ```
1888 #[rustc_on_unimplemented] // error: this attribute must have a value
1889 trait Bar {}
1890 ```
1891
1892 Please supply the missing value of the attribute. Example:
1893
1894 ```
1895 #[rustc_on_unimplemented = "foo"] // ok!
1896 trait Bar {}
1897 ```
1898 "##,
1899
1900 E0243: r##"
1901 This error indicates that not enough type parameters were found in a type or
1902 trait.
1903
1904 For example, the `Foo` struct below is defined to be generic in `T`, but the
1905 type parameter is missing in the definition of `Bar`:
1906
1907 ```
1908 struct Foo<T> { x: T }
1909
1910 struct Bar { x: Foo }
1911 ```
1912 "##,
1913
1914 E0244: r##"
1915 This error indicates that too many type parameters were found in a type or
1916 trait.
1917
1918 For example, the `Foo` struct below has no type parameters, but is supplied
1919 with two in the definition of `Bar`:
1920
1921 ```
1922 struct Foo { x: bool }
1923
1924 struct Bar<S, T> { x: Foo<S, T> }
1925 ```
1926 "##,
1927
1928 E0249: r##"
1929 This error indicates a constant expression for the array length was found, but
1930 it was not an integer (signed or unsigned) expression.
1931
1932 Some examples of code that produces this error are:
1933
1934 ```
1935 const A: [u32; "hello"] = []; // error
1936 const B: [u32; true] = []; // error
1937 const C: [u32; 0.0] = []; // error
1938 "##,
1939
1940 E0250: r##"
1941 There was an error while evaluating the expression for the length of a fixed-
1942 size array type.
1943
1944 Some examples of this error are:
1945
1946 ```
1947 // divide by zero in the length expression
1948 const A: [u32; 1/0] = [];
1949
1950 // Rust currently will not evaluate the function `foo` at compile time
1951 fn foo() -> usize { 12 }
1952 const B: [u32; foo()] = [];
1953
1954 // it is an error to try to add `u8` and `f64`
1955 use std::{f64, u8};
1956 const C: [u32; u8::MAX + f64::EPSILON] = [];
1957 ```
1958 "##,
1959
1960 E0318: r##"
1961 Default impls for a trait must be located in the same crate where the trait was
1962 defined. For more information see the [opt-in builtin traits RFC](https://github
1963 .com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
1964 "##,
1965
1966 E0322: r##"
1967 The `Sized` trait is a special trait built-in to the compiler for types with a
1968 constant size known at compile-time. This trait is automatically implemented
1969 for types as needed by the compiler, and it is currently disallowed to
1970 explicitly implement it for a type.
1971 "##,
1972
1973 E0326: r##"
1974 The types of any associated constants in a trait implementation must match the
1975 types in the trait definition. This error indicates that there was a mismatch.
1976
1977 Here's an example of this error:
1978
1979 ```
1980 trait Foo {
1981     const BAR: bool;
1982 }
1983
1984 struct Bar;
1985
1986 impl Foo for Bar {
1987     const BAR: u32 = 5; // error, expected bool, found u32
1988 }
1989 ```
1990 "##,
1991
1992 E0327: r##"
1993 You cannot use associated items other than constant items as patterns. This
1994 includes method items. Example of erroneous code:
1995
1996 ```
1997 enum B {}
1998
1999 impl B {
2000     fn bb() -> i32 { 0 }
2001 }
2002
2003 fn main() {
2004     match 0 {
2005         B::bb => {} // error: associated items in match patterns must
2006                     // be constants
2007     }
2008 }
2009 ```
2010
2011 Please check that you're not using a method as a pattern. Example:
2012
2013 ```
2014 enum B {
2015     ba,
2016     bb
2017 }
2018
2019 fn main() {
2020     match B::ba {
2021         B::bb => {} // ok!
2022         _ => {}
2023     }
2024 }
2025 ```
2026 "##,
2027
2028 E0368: r##"
2029 This error indicates that a binary assignment operator like `+=` or `^=` was
2030 applied to the wrong types. For example:
2031
2032 ```
2033 let mut x: u16 = 5;
2034 x ^= true; // error, `^=` cannot be applied to types `u16` and `bool`
2035 x += ();   // error, `+=` cannot be applied to types `u16` and `()`
2036 ```
2037
2038 Another problem you might be facing is this: suppose you've overloaded the `+`
2039 operator for some type `Foo` by implementing the `std::ops::Add` trait for
2040 `Foo`, but you find that using `+=` does not work, as in this example:
2041
2042 ```
2043 use std::ops::Add;
2044
2045 struct Foo(u32);
2046
2047 impl Add for Foo {
2048     type Output = Foo;
2049
2050     fn add(self, rhs: Foo) -> Foo {
2051         Foo(self.0 + rhs.0)
2052     }
2053 }
2054
2055 fn main() {
2056     let mut x: Foo = Foo(5);
2057     x += Foo(7); // error, `+= cannot be applied to types `Foo` and `Foo`
2058 }
2059 ```
2060
2061 This is because the binary assignment operators currently do not work off of
2062 traits, so it is not possible to overload them. See [RFC 953] for a proposal
2063 to change this.
2064
2065 [RFC 953]: https://github.com/rust-lang/rfcs/pull/953
2066 "##,
2067
2068 E0371: r##"
2069 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
2070 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
2071 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
2072 definition, so it is not useful to do this.
2073
2074 Example:
2075
2076 ```
2077 trait Foo { fn foo(&self) { } }
2078 trait Bar: Foo { }
2079 trait Baz: Bar { }
2080
2081 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
2082 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
2083 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
2084 impl Baz for Bar { } // Note: This is OK
2085 ```
2086 "##,
2087
2088 E0372: r##"
2089 Trying to implement a trait for a trait object (as in `impl Trait1 for
2090 Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
2091 [RFC 255] for more details on object safety rules.
2092
2093 [RFC 255]: https://github.com/rust-lang/rfcs/pull/255
2094 "##,
2095
2096 E0379: r##"
2097 Trait methods cannot be declared `const` by design. For more information, see
2098 [RFC 911].
2099
2100 [RFC 911]: https://github.com/rust-lang/rfcs/pull/911
2101 "##,
2102
2103 E0380: r##"
2104 Default impls are only allowed for traits with no methods or associated items.
2105 For more information see the [opt-in builtin traits RFC](https://github.com/rust
2106 -lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
2107 "##
2108
2109 }
2110
2111 register_diagnostics! {
2112     E0068,
2113     E0074,
2114     E0075,
2115     E0076,
2116     E0077,
2117     E0085,
2118     E0086,
2119     E0090,
2120     E0102,
2121     E0103,
2122     E0104,
2123     E0118,
2124     E0120,
2125     E0122,
2126     E0123,
2127     E0127,
2128     E0129,
2129     E0141,
2130     E0163,
2131     E0164,
2132     E0167,
2133     E0168,
2134     E0172,
2135     E0173, // manual implementations of unboxed closure traits are experimental
2136     E0174, // explicit use of unboxed closure methods are experimental
2137     E0182,
2138     E0183,
2139     E0187, // can't infer the kind of the closure
2140     E0188, // can not cast a immutable reference to a mutable pointer
2141     E0189, // deprecated: can only cast a boxed pointer to a boxed object
2142     E0190, // deprecated: can only cast a &-pointer to an &-object
2143     E0193, // cannot bound type where clause bounds may only be attached to types
2144            // involving type parameters
2145     E0194,
2146     E0196, // cannot determine a type for this closure
2147     E0203, // type parameter has more than one relaxed default bound,
2148            // and only one is supported
2149     E0208,
2150     E0209, // builtin traits can only be implemented on structs or enums
2151     E0210, // type parameter is not constrained by any local type
2152     E0212, // cannot extract an associated type from a higher-ranked trait bound
2153     E0213, // associated types are not accepted in this context
2154     E0214, // parenthesized parameters may only be used with a trait
2155     E0215, // angle-bracket notation is not stable with `Fn`
2156     E0216, // parenthetical notation is only stable with `Fn`
2157     E0217, // ambiguous associated type, defined in multiple supertraits
2158     E0218, // no associated type defined
2159     E0219, // associated type defined in higher-ranked supertrait
2160     E0221, // ambiguous associated type in bounds
2161     //E0222, // Error code E0045 (variadic function must have C calling
2162              // convention) duplicate
2163     E0223, // ambiguous associated type
2164     E0224, // at least one non-builtin train is required for an object type
2165     E0225, // only the builtin traits can be used as closure or object bounds
2166     E0226, // only a single explicit lifetime bound is permitted
2167     E0227, // ambiguous lifetime bound, explicit lifetime bound required
2168     E0228, // explicit lifetime bound required
2169     E0229, // associated type bindings are not allowed here
2170     E0230, // there is no type parameter on trait
2171     E0231, // only named substitution parameters are allowed
2172     E0233,
2173     E0234,
2174     E0235, // structure constructor specifies a structure of type but
2175     E0236, // no lang item for range syntax
2176     E0237, // no lang item for range syntax
2177     E0238, // parenthesized parameters may only be used with a trait
2178     E0239, // `next` method of `Iterator` trait has unexpected type
2179     E0240,
2180     E0241,
2181     E0242, // internal error looking up a definition
2182     E0245, // not a trait
2183     E0246, // illegal recursive type
2184     E0247, // found module name used as a type
2185     E0248, // found value name used as a type
2186     E0319, // trait impls for defaulted traits allowed just for structs/enums
2187     E0320, // recursive overflow during dropck
2188     E0321, // extended coherence rules for defaulted traits violated
2189     E0323, // implemented an associated const when another trait item expected
2190     E0324, // implemented a method when another trait item expected
2191     E0325, // implemented an associated type when another trait item expected
2192     E0328, // cannot implement Unsize explicitly
2193     E0329, // associated const depends on type parameter or Self.
2194     E0366, // dropck forbid specialization to concrete type or region
2195     E0367, // dropck forbid specialization to predicate not in struct/enum
2196     E0369, // binary operation `<op>` cannot be applied to types
2197     E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
2198            // between structures with one field being coerced, none found
2199     E0375, // the trait `CoerceUnsized` may only be implemented for a coercion
2200            // between structures with one field being coerced, but multiple
2201            // fields need coercions
2202     E0376, // the trait `CoerceUnsized` may only be implemented for a coercion
2203            // between structures
2204     E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
2205            // between structures with the same definition
2206     E0390, // only a single inherent implementation marked with
2207            // `#[lang = \"{}\"]` is allowed for the `{}` primitive
2208     E0391, // unsupported cyclic reference between types/traits detected
2209     E0392, // parameter `{}` is never used
2210     E0393, // the type parameter `{}` must be explicitly specified in an object
2211            // type because its default value `{}` references the type `Self`"
2212     E0399  // trait items need to be implemented because the associated
2213            // type `{}` was overridden
2214 }