]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/diagnostics.rs
Rollup merge of #25614 - parir:patch-2, r=alexcrichton
[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 E0033: r##"
150 This error indicates that a pointer to a trait type cannot be implicitly
151 dereferenced by a pattern. Every trait defines a type, but because the
152 size of trait implementors isn't fixed, this type has no compile-time size.
153 Therefore, all accesses to trait types must be through pointers. If you
154 encounter this error you should try to avoid dereferencing the pointer.
155
156 ```
157 let trait_obj: &SomeTrait = ...;
158
159 // This tries to implicitly dereference to create an unsized local variable.
160 let &invalid = trait_obj;
161
162 // You can call methods without binding to the value being pointed at.
163 trait_obj.method_one();
164 trait_obj.method_two();
165 ```
166
167 You can read more about trait objects in the Trait Object section of the
168 Reference:
169
170 http://doc.rust-lang.org/reference.html#trait-objects
171 "##,
172
173 E0046: r##"
174 When trying to make some type implement a trait `Foo`, you must, at minimum,
175 provide implementations for all of `Foo`'s required methods (meaning the
176 methods that do not have default implementations), as well as any required
177 trait items like associated types or constants.
178 "##,
179
180 E0049: r##"
181 This error indicates that an attempted implementation of a trait method
182 has the wrong number of type parameters.
183
184 For example, the trait below has a method `foo` with a type parameter `T`,
185 but the implementation of `foo` for the type `Bar` is missing this parameter:
186
187 ```
188 trait Foo {
189     fn foo<T: Default>(x: T) -> Self;
190 }
191
192 struct Bar;
193
194 // error: method `foo` has 0 type parameters but its trait declaration has 1
195 // type parameter
196 impl Foo for Bar {
197     fn foo(x: bool) -> Self { Bar }
198 }
199 ```
200 "##,
201
202 E0050: r##"
203 This error indicates that an attempted implementation of a trait method
204 has the wrong number of function parameters.
205
206 For example, the trait below has a method `foo` with two function parameters
207 (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
208 the `u8` parameter:
209
210 ```
211 trait Foo {
212     fn foo(&self, x: u8) -> bool;
213 }
214
215 struct Bar;
216
217 // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo`
218 // has 2
219 impl Foo for Bar {
220     fn foo(&self) -> bool { true }
221 }
222 ```
223 "##,
224
225 E0053: r##"
226 For any given method of a trait, the mutabilities of the parameters must match
227 between the trait definition and the implementation.
228
229 Here's an example where the mutability of the `self` parameter is wrong:
230
231 ```
232 trait Foo { fn foo(&self); }
233
234 struct Bar;
235
236 impl Foo for Bar {
237     // error, the signature should be `fn foo(&self)` instead
238     fn foo(&mut self) { }
239 }
240
241 fn main() {}
242 ```
243
244 Here's another example, this time for a non-`self` parameter:
245
246 ```
247 trait Foo { fn foo(x: &mut bool) -> bool; }
248
249 struct Bar;
250
251 impl Foo for Bar {
252     // error, the type of `x` should be `&mut bool` instead
253     fn foo(x: &bool) -> bool { *x }
254 }
255
256 fn main() {}
257 ```
258
259
260 "##,
261
262 E0054: r##"
263 It is not allowed to cast to a bool. If you are trying to cast a numeric type
264 to a bool, you can compare it with zero instead:
265
266 ```
267 let x = 5;
268
269 // Ok
270 let x_is_nonzero = x != 0;
271
272 // Not allowed, won't compile
273 let x_is_nonzero = x as bool;
274 ```
275 "##,
276
277 E0062: r##"
278 This error indicates that during an attempt to build a struct or struct-like
279 enum variant, one of the fields was specified more than once. Each field should
280 be specified exactly one time.
281 "##,
282
283 E0063: r##"
284 This error indicates that during an attempt to build a struct or struct-like
285 enum variant, one of the fields was not provided. Each field should be specified
286 exactly once.
287 "##,
288
289 E0066: r##"
290 Box placement expressions (like C++'s "placement new") do not yet support any
291 place expression except the exchange heap (i.e. `std::boxed::HEAP`).
292 Furthermore, the syntax is changing to use `in` instead of `box`. See [RFC 470]
293 and [RFC 809] for more details.
294
295 [RFC 470]: https://github.com/rust-lang/rfcs/pull/470
296 [RFC 809]: https://github.com/rust-lang/rfcs/pull/809
297 "##,
298
299 E0067: r##"
300 The left-hand side of an assignment operator must be an lvalue expression. An
301 lvalue expression represents a memory location and includes item paths (ie,
302 namespaced variables), dereferences, indexing expressions, and field references.
303
304 ```
305 use std::collections::LinkedList;
306
307 // Good
308 let mut list = LinkedList::new();
309
310
311 // Bad: assignment to non-lvalue expression
312 LinkedList::new() += 1;
313 ```
314 "##,
315
316 E0069: r##"
317 The compiler found a function whose body contains a `return;` statement but
318 whose return type is not `()`. An example of this is:
319
320 ```
321 // error
322 fn foo() -> u8 {
323     return;
324 }
325 ```
326
327 Since `return;` is just like `return ();`, there is a mismatch between the
328 function's return type and the value being returned.
329 "##,
330
331 E0072: r##"
332 When defining a recursive struct or enum, any use of the type being defined
333 from inside the definition must occur behind a pointer (like `Box` or `&`).
334 This is because structs and enums must have a well-defined size, and without
335 the pointer the size of the type would need to be unbounded.
336
337 Consider the following erroneous definition of a type for a list of bytes:
338
339 ```
340 // error, illegal recursive struct type
341 struct ListNode {
342     head: u8,
343     tail: Option<ListNode>,
344 }
345 ```
346
347 This type cannot have a well-defined size, because it needs to be arbitrarily
348 large (since we would be able to nest `ListNode`s to any depth). Specifically,
349
350 ```
351 size of ListNode = 1 byte for head
352                  + 1 byte for the discriminant of the Option
353                  + size of ListNode
354 ```
355
356 One way to fix this is by wrapping `ListNode` in a `Box`, like so:
357
358 ```
359 struct ListNode {
360     head: u8,
361     tail: Option<Box<ListNode>>,
362 }
363 ```
364
365 This works because `Box` is a pointer, so its size is well-known.
366 "##,
367
368 E0073: r##"
369 You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
370 in order to make a new `Foo` value. This is because there would be no way a
371 first instance of `Foo` could be made to initialize another instance!
372
373 Here's an example of a struct that has this problem:
374
375 ```
376 struct Foo { x: Box<Foo> } // error
377 ```
378
379 One fix is to use `Option`, like so:
380
381 ```
382 struct Foo { x: Option<Box<Foo>> }
383 ```
384
385 Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
386 "##,
387
388 E0081: r##"
389 Enum discriminants are used to differentiate enum variants stored in memory.
390 This error indicates that the same value was used for two or more variants,
391 making them impossible to tell apart.
392
393 ```
394 // Good.
395 enum Enum {
396     P,
397     X = 3,
398     Y = 5
399 }
400
401 // Bad.
402 enum Enum {
403     P = 3,
404     X = 3,
405     Y = 5
406 }
407 ```
408
409 Note that variants without a manually specified discriminant are numbered from
410 top to bottom starting from 0, so clashes can occur with seemingly unrelated
411 variants.
412
413 ```
414 enum Bad {
415     X,
416     Y = 0
417 }
418 ```
419
420 Here `X` will have already been assigned the discriminant 0 by the time `Y` is
421 encountered, so a conflict occurs.
422 "##,
423
424 E0082: r##"
425 The default type for enum discriminants is `isize`, but it can be adjusted by
426 adding the `repr` attribute to the enum declaration. This error indicates that
427 an integer literal given as a discriminant is not a member of the discriminant
428 type. For example:
429
430 ```
431 #[repr(u8)]
432 enum Thing {
433     A = 1024,
434     B = 5
435 }
436 ```
437
438 Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
439 invalid. You may want to change representation types to fix this, or else change
440 invalid discriminant values so that they fit within the existing type.
441
442 Note also that without a representation manually defined, the compiler will
443 optimize by using the smallest integer type possible.
444 "##,
445
446 E0083: r##"
447 At present, it's not possible to define a custom representation for an enum with
448 a single variant. As a workaround you can add a `Dummy` variant.
449
450 See: https://github.com/rust-lang/rust/issues/10292
451 "##,
452
453 E0084: r##"
454 It is impossible to define an integer type to be used to represent zero-variant
455 enum values because there are no zero-variant enum values. There is no way to
456 construct an instance of the following type using only safe code:
457
458 ```
459 enum Empty {}
460 ```
461 "##,
462
463 E0106: r##"
464 This error indicates that a lifetime is missing from a type. If it is an error
465 inside a function signature, the problem may be with failing to adhere to the
466 lifetime elision rules (see below).
467
468 Here are some simple examples of where you'll run into this error:
469
470 ```
471 struct Foo { x: &bool }        // error
472 struct Foo<'a> { x: &'a bool } // correct
473
474 enum Bar { A(u8), B(&bool), }        // error
475 enum Bar<'a> { A(u8), B(&'a bool), } // correct
476
477 type MyStr = &str;        // error
478 type MyStr<'a> = &'a str; //correct
479
480 ```
481
482 Lifetime elision is a special, limited kind of inference for lifetimes in
483 function signatures which allows you to leave out lifetimes in certain cases.
484 For more background on lifetime elision see [the book][book-le].
485
486 The lifetime elision rules require that any function signature with an elided
487 output lifetime must either have
488
489  - exactly one input lifetime
490  - or, multiple input lifetimes, but the function must also be a method with a
491    `&self` or `&mut self` receiver
492
493 In the first case, the output lifetime is inferred to be the same as the unique
494 input lifetime. In the second case, the lifetime is instead inferred to be the
495 same as the lifetime on `&self` or `&mut self`.
496
497 Here are some examples of elision errors:
498
499 ```
500 // error, no input lifetimes
501 fn foo() -> &str { ... }
502
503 // error, `x` and `y` have distinct lifetimes inferred
504 fn bar(x: &str, y: &str) -> &str { ... }
505
506 // error, `y`'s lifetime is inferred to be distinct from `x`'s
507 fn baz<'a>(x: &'a str, y: &str) -> &str { ... }
508 ```
509
510 [book-le]: http://doc.rust-lang.org/nightly/book/lifetimes.html#lifetime-elision
511 "##,
512
513 E0107: r##"
514 This error means that an incorrect number of lifetime parameters were provided
515 for a type (like a struct or enum) or trait.
516
517 Some basic examples include:
518
519 ```
520 struct Foo<'a>(&'a str);
521 enum Bar { A, B, C }
522
523 struct Baz<'a> {
524     foo: Foo,     // error: expected 1, found 0
525     bar: Bar<'a>, // error: expected 0, found 1
526 }
527 ```
528
529 Here's an example that is currently an error, but may work in a future version
530 of Rust:
531
532 ```
533 struct Foo<'a>(&'a str);
534
535 trait Quux { }
536 impl Quux for Foo { } // error: expected 1, found 0
537 ```
538
539 Lifetime elision in implementation headers was part of the lifetime elision
540 RFC. It is, however, [currently unimplemented][iss15872].
541
542 [iss15872]: https://github.com/rust-lang/rust/issues/15872
543 "##,
544
545 E0121: r##"
546 In order to be consistent with Rust's lack of global type inference, type
547 placeholders are disallowed by design in item signatures.
548
549 Examples of this error include:
550
551 ```
552 fn foo() -> _ { 5 } // error, explicitly write out the return type instead
553
554 static BAR: _ = "test"; // error, explicitly write out the type instead
555 ```
556 "##,
557
558 E0131: r##"
559 It is not possible to define `main` with type parameters, or even with function
560 parameters. When `main` is present, it must take no arguments and return `()`.
561 "##,
562
563 E0132: r##"
564 It is not possible to declare type parameters on a function that has the `start`
565 attribute. Such a function must have the following type signature:
566
567 ```
568 fn(isize, *const *const u8) -> isize
569 ```
570 "##,
571
572 E0166: r##"
573 This error means that the compiler found a return expression in a function
574 marked as diverging. A function diverges if it has `!` in the place of the
575 return type in its signature. For example:
576
577 ```
578 fn foo() -> ! { return; } // error
579 ```
580
581 For a function that diverges, every control path in the function must never
582 return, for example with a `loop` that never breaks or a call to another
583 diverging function (such as `panic!()`).
584 "##,
585
586 E0178: r##"
587 In types, the `+` type operator has low precedence, so it is often necessary
588 to use parentheses.
589
590 For example:
591
592 ```
593 trait Foo {}
594
595 struct Bar<'a> {
596     w: &'a Foo + Copy,   // error, use &'a (Foo + Copy)
597     x: &'a Foo + 'a,     // error, use &'a (Foo + 'a)
598     y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
599     z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
600 }
601 ```
602
603 More details can be found in [RFC 438].
604
605 [RFC 438]: https://github.com/rust-lang/rfcs/pull/438
606 "##,
607
608 E0184: r##"
609 Explicitly implementing both Drop and Copy for a type is currently disallowed.
610 This feature can make some sense in theory, but the current implementation is
611 incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so
612 it has been disabled for now.
613
614 [iss20126]: https://github.com/rust-lang/rust/issues/20126
615 "##,
616
617 E0197: r##"
618 Inherent implementations (one that do not implement a trait but provide
619 methods associated with a type) are always safe because they are not
620 implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
621 implementation will resolve this error.
622
623 ```
624 struct Foo;
625
626 // this will cause this error
627 unsafe impl Foo { }
628 // converting it to this will fix it
629 impl Foo { }
630 ```
631
632 "##,
633
634 E0198: r##"
635 A negative implementation is one that excludes a type from implementing a
636 particular trait. Not being able to use a trait is always a safe operation,
637 so negative implementations are always safe and never need to be marked as
638 unsafe.
639
640 ```
641 struct Foo;
642
643 // unsafe is unnecessary
644 unsafe impl !Clone for Foo { }
645 // this will compile
646 impl !Clone for Foo { }
647 ```
648
649 "##,
650
651 E0199: r##"
652 Safe traits should not have unsafe implementations, therefore marking an
653 implementation for a safe trait unsafe will cause a compiler error. Removing the
654 unsafe marker on the trait noted in the error will resolve this problem.
655
656 ```
657 struct Foo;
658
659 trait Bar { }
660
661 // this won't compile because Bar is safe
662 unsafe impl Bar for Foo { }
663 // this will compile
664 impl Bar for Foo { }
665 ```
666
667 "##,
668
669 E0200: r##"
670 Unsafe traits must have unsafe implementations. This error occurs when an
671 implementation for an unsafe trait isn't marked as unsafe. This may be resolved
672 by marking the unsafe implementation as unsafe.
673
674 ```
675 struct Foo;
676
677 unsafe trait Bar { }
678
679 // this won't compile because Bar is unsafe and impl isn't unsafe
680 impl Bar for Foo { }
681 // this will compile
682 unsafe impl Bar for Foo { }
683 ```
684
685 "##,
686
687 E0201: r##"
688 It is an error to define a method--a trait method or an inherent method--more
689 than once.
690
691 For example,
692
693 ```
694 struct Foo(u8);
695
696 impl Foo {
697     fn bar() {}
698
699     // error: duplicate method
700     fn bar(&self) -> bool { self.0 > 5 }
701 }
702 ```
703 "##,
704
705 E0204: r##"
706 An attempt to implement the `Copy` trait for a struct failed because one of the
707 fields does not implement `Copy`. To fix this, you must implement `Copy` for the
708 mentioned field. Note that this may not be possible, as in the example of
709
710 ```
711 struct Foo {
712     foo : Vec<u32>,
713 }
714
715 impl Copy for Foo { }
716 ```
717
718 This fails because `Vec<T>` does not implement `Copy` for any `T`.
719
720 Here's another example that will fail:
721
722 ```
723 #[derive(Copy)]
724 struct Foo<'a> {
725     ty: &'a mut bool,
726 }
727 ```
728
729 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
730 differs from the behavior for `&T`, which is always `Copy`).
731 "##,
732
733 E0205: r##"
734 An attempt to implement the `Copy` trait for an enum failed because one of the
735 variants does not implement `Copy`. To fix this, you must implement `Copy` for
736 the mentioned variant. Note that this may not be possible, as in the example of
737
738 ```
739 enum Foo {
740     Bar(Vec<u32>),
741     Baz,
742 }
743
744 impl Copy for Foo { }
745 ```
746
747 This fails because `Vec<T>` does not implement `Copy` for any `T`.
748
749 Here's another example that will fail:
750
751 ```
752 #[derive(Copy)]
753 enum Foo<'a> {
754     Bar(&'a mut bool),
755     Baz
756 }
757 ```
758
759 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
760 differs from the behavior for `&T`, which is always `Copy`).
761 "##,
762
763 E0206: r##"
764 You can only implement `Copy` for a struct or enum. Both of the following
765 examples will fail, because neither `i32` (primitive type) nor `&'static Bar`
766 (reference to `Bar`) is a struct or enum:
767
768 ```
769 type Foo = i32;
770 impl Copy for Foo { } // error
771
772 #[derive(Copy, Clone)]
773 struct Bar;
774 impl Copy for &'static Bar { } // error
775 ```
776 "##,
777
778 E0243: r##"
779 This error indicates that not enough type parameters were found in a type or
780 trait.
781
782 For example, the `Foo` struct below is defined to be generic in `T`, but the
783 type parameter is missing in the definition of `Bar`:
784
785 ```
786 struct Foo<T> { x: T }
787
788 struct Bar { x: Foo }
789 ```
790 "##,
791
792 E0244: r##"
793 This error indicates that too many type parameters were found in a type or
794 trait.
795
796 For example, the `Foo` struct below has no type parameters, but is supplied
797 with two in the definition of `Bar`:
798
799 ```
800 struct Foo { x: bool }
801
802 struct Bar<S, T> { x: Foo<S, T> }
803 ```
804 "##,
805
806 E0249: r##"
807 This error indicates a constant expression for the array length was found, but
808 it was not an integer (signed or unsigned) expression.
809
810 Some examples of code that produces this error are:
811
812 ```
813 const A: [u32; "hello"] = []; // error
814 const B: [u32; true] = []; // error
815 const C: [u32; 0.0] = []; // error
816 "##,
817
818 E0250: r##"
819 This means there was an error while evaluating the expression for the length of
820 a fixed-size array type.
821
822 Some examples of code that produces this error are:
823
824 ```
825 // divide by zero in the length expression
826 const A: [u32; 1/0] = [];
827
828 // Rust currently will not evaluate the function `foo` at compile time
829 fn foo() -> usize { 12 }
830 const B: [u32; foo()] = [];
831
832 // it is an error to try to add `u8` and `f64`
833 use std::{f64, u8};
834 const C: [u32; u8::MAX + f64::EPSILON] = [];
835 ```
836 "##,
837
838 E0322: r##"
839 The `Sized` trait is a special trait built-in to the compiler for types with a
840 constant size known at compile-time. This trait is automatically implemented
841 for types as needed by the compiler, and it is currently disallowed to
842 explicitly implement it for a type.
843 "##,
844
845 E0368: r##"
846 This error indicates that a binary assignment operator like `+=` or `^=` was
847 applied to the wrong types.
848
849 A couple examples of this are as follows:
850
851 ```
852 let mut x: u16 = 5;
853 x ^= true; // error, `^=` cannot be applied to types `u16` and `bool`
854 x += ();   // error, `+=` cannot be applied to types `u16` and `()`
855 ```
856
857 Another problem you might be facing is this: suppose you've overloaded the `+`
858 operator for some type `Foo` by implementing the `std::ops::Add` trait for
859 `Foo`, but you find that using `+=` does not work, as in this example:
860
861 ```
862 use std::ops::Add;
863
864 struct Foo(u32);
865
866 impl Add for Foo {
867     type Output = Foo;
868
869     fn add(self, rhs: Foo) -> Foo {
870         Foo(self.0 + rhs.0)
871     }
872 }
873
874 fn main() {
875     let mut x: Foo = Foo(5);
876     x += Foo(7); // error, `+= cannot be applied to types `Foo` and `Foo`
877 }
878 ```
879
880 This is because the binary assignment operators currently do not work off of
881 traits, so it is not possible to overload them. See [RFC 953] for a proposal
882 to change this.
883
884 [RFC 953]: https://github.com/rust-lang/rfcs/pull/953
885 "##,
886
887 E0371: r##"
888 When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
889 definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
890 `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
891 definition, so it is not useful to do this.
892
893 Example:
894
895 ```
896 trait Foo { fn foo(&self) { } }
897 trait Bar: Foo { }
898 trait Baz: Bar { }
899
900 impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
901 impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
902 impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
903 impl Baz for Bar { } // Note: This is OK
904 ```
905 "##,
906
907 E0372: r##"
908 Trying to implement a trait for a trait object (as in `impl Trait1 for
909 Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
910 [RFC 255] for more details on object safety rules.
911
912 [RFC 255]:https://github.com/rust-lang/rfcs/blob/master/text/0255-object-\
913 safety.md
914 "##
915
916 }
917
918 register_diagnostics! {
919     E0029,
920     E0030,
921     E0031,
922     E0034, // multiple applicable methods in scope
923     E0035, // does not take type parameters
924     E0036, // incorrect number of type parameters given for this method
925     E0040, // explicit use of destructor method
926     E0044, // foreign items may not have type parameters
927     E0045, // variadic function must have C calling convention
928     E0055, // method has an incompatible type for trait
929     E0057, // method has an incompatible type for trait
930     E0059,
931     E0060,
932     E0061,
933     E0068,
934     E0070,
935     E0071,
936     E0074,
937     E0075,
938     E0076,
939     E0077,
940     E0085,
941     E0086,
942     E0087,
943     E0088,
944     E0089,
945     E0090,
946     E0091,
947     E0092,
948     E0093,
949     E0094,
950     E0101,
951     E0102,
952     E0103,
953     E0104,
954     E0116,
955     E0117,
956     E0118,
957     E0119,
958     E0120,
959     E0122,
960     E0123,
961     E0124,
962     E0127,
963     E0128,
964     E0129,
965     E0130,
966     E0141,
967     E0159,
968     E0163,
969     E0164,
970     E0167,
971     E0168,
972     E0172,
973     E0173, // manual implementations of unboxed closure traits are experimental
974     E0174, // explicit use of unboxed closure methods are experimental
975     E0182,
976     E0183,
977     E0185,
978     E0186,
979     E0187, // can't infer the kind of the closure
980     E0188, // types differ in mutability
981     E0189, // can only cast a boxed pointer to a boxed object
982     E0190, // can only cast a &-pointer to an &-object
983     E0191, // value of the associated type must be specified
984     E0192, // negative imples are allowed just for `Send` and `Sync`
985     E0193, // cannot bound type where clause bounds may only be attached to types
986            // involving type parameters
987     E0194,
988     E0195, // lifetime parameters or bounds on method do not match the trait declaration
989     E0196, // cannot determine a type for this closure
990     E0202, // associated items are not allowed in inherent impls
991     E0203, // type parameter has more than one relaxed default bound,
992            // and only one is supported
993     E0207, // type parameter is not constrained by the impl trait, self type, or predicate
994     E0208,
995     E0209, // builtin traits can only be implemented on structs or enums
996     E0210, // type parameter is not constrained by any local type
997     E0211,
998     E0212, // cannot extract an associated type from a higher-ranked trait bound
999     E0213, // associated types are not accepted in this context
1000     E0214, // parenthesized parameters may only be used with a trait
1001     E0215, // angle-bracket notation is not stable with `Fn`
1002     E0216, // parenthetical notation is only stable with `Fn`
1003     E0217, // ambiguous associated type, defined in multiple supertraits
1004     E0218, // no associated type defined
1005     E0219, // associated type defined in higher-ranked supertrait
1006     E0220, // associated type not found for type parameter
1007     E0221, // ambiguous associated type in bounds
1008     E0222, // variadic function must have C calling convention
1009     E0223, // ambiguous associated type
1010     E0224, // at least one non-builtin train is required for an object type
1011     E0225, // only the builtin traits can be used as closure or object bounds
1012     E0226, // only a single explicit lifetime bound is permitted
1013     E0227, // ambiguous lifetime bound, explicit lifetime bound required
1014     E0228, // explicit lifetime bound required
1015     E0229, // associated type bindings are not allowed here
1016     E0230, // there is no type parameter on trait
1017     E0231, // only named substitution parameters are allowed
1018     E0232, // this attribute must have a value
1019     E0233,
1020     E0234,
1021     E0235, // structure constructor specifies a structure of type but
1022     E0236, // no lang item for range syntax
1023     E0237, // no lang item for range syntax
1024     E0238, // parenthesized parameters may only be used with a trait
1025     E0239, // `next` method of `Iterator` trait has unexpected type
1026     E0240,
1027     E0241,
1028     E0242, // internal error looking up a definition
1029     E0245, // not a trait
1030     E0246, // illegal recursive type
1031     E0247, // found module name used as a type
1032     E0248, // found value name used as a type
1033     E0318, // can't create default impls for traits outside their crates
1034     E0319, // trait impls for defaulted traits allowed just for structs/enums
1035     E0320, // recursive overflow during dropck
1036     E0321, // extended coherence rules for defaulted traits violated
1037     E0323, // implemented an associated const when another trait item expected
1038     E0324, // implemented a method when another trait item expected
1039     E0325, // implemented an associated type when another trait item expected
1040     E0326, // associated const implemented with different type from trait
1041     E0327, // referred to method instead of constant in match pattern
1042     E0328, // cannot implement Unsize explicitly
1043     E0366, // dropck forbid specialization to concrete type or region
1044     E0367, // dropck forbid specialization to predicate not in struct/enum
1045     E0369, // binary operation `<op>` cannot be applied to types
1046     E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
1047            // between structures with one field being coerced, none found
1048     E0375, // the trait `CoerceUnsized` may only be implemented for a coercion
1049            // between structures with one field being coerced, but multiple
1050            // fields need coercions
1051     E0376, // the trait `CoerceUnsized` may only be implemented for a coercion
1052            // between structures
1053     E0377  // the trait `CoerceUnsized` may only be implemented for a coercion
1054            // between structures with the same definition
1055 }