]> git.lizzy.rs Git - rust.git/blob - src/librustc_resolve/diagnostics.rs
8f6b1b8971e5b9ffb1967dbb72629227735966fe
[rust.git] / src / librustc_resolve / 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 // Error messages for EXXXX errors.  Each message should start and end with a
14 // new line, and be wrapped to 80 characters.  In vim you can `:set tw=80` and
15 // use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
16 register_long_diagnostics! {
17
18 E0128: r##"
19 Type parameter defaults can only use parameters that occur before them.
20 Erroneous code example:
21
22 ```compile_fail,E0128
23 struct Foo<T=U, U=()> {
24     field1: T,
25     filed2: U,
26 }
27 // error: type parameters with a default cannot use forward declared
28 // identifiers
29 ```
30
31 Since type parameters are evaluated in-order, you may be able to fix this issue
32 by doing:
33
34 ```
35 struct Foo<U=(), T=U> {
36     field1: T,
37     filed2: U,
38 }
39 ```
40
41 Please also verify that this wasn't because of a name-clash and rename the type
42 parameter if so.
43 "##,
44
45 E0154: r##"
46 ## Note: this error code is no longer emitted by the compiler.
47
48 Imports (`use` statements) are not allowed after non-item statements, such as
49 variable declarations and expression statements.
50
51 Here is an example that demonstrates the error:
52
53 ```ignore
54 fn f() {
55     // Variable declaration before import
56     let x = 0;
57     use std::io::Read;
58     // ...
59 }
60 ```
61
62 The solution is to declare the imports at the top of the block, function, or
63 file.
64
65 Here is the previous example again, with the correct order:
66
67 ```
68 fn f() {
69     use std::io::Read;
70     let x = 0;
71     // ...
72 }
73 ```
74
75 See the Declaration Statements section of the reference for more information
76 about what constitutes an Item declaration and what does not:
77
78 https://doc.rust-lang.org/reference.html#statements
79 "##,
80
81 E0251: r##"
82 ## Note: this error code is no longer emitted by the compiler.
83
84 Two items of the same name cannot be imported without rebinding one of the
85 items under a new local name.
86
87 An example of this error:
88
89 ```ignore
90 use foo::baz;
91 use bar::*; // error, do `use foo::baz as quux` instead on the previous line
92
93 fn main() {}
94
95 mod foo {
96     pub struct baz;
97 }
98
99 mod bar {
100     pub mod baz {}
101 }
102 ```
103 "##,
104
105 E0252: r##"
106 Two items of the same name cannot be imported without rebinding one of the
107 items under a new local name.
108
109 Erroneous code example:
110
111 ```compile_fail,E0252
112 use foo::baz;
113 use bar::baz; // error, do `use bar::baz as quux` instead
114
115 fn main() {}
116
117 mod foo {
118     pub struct baz;
119 }
120
121 mod bar {
122     pub mod baz {}
123 }
124 ```
125
126 You can use aliases in order to fix this error. Example:
127
128 ```
129 use foo::baz as foo_baz;
130 use bar::baz; // ok!
131
132 fn main() {}
133
134 mod foo {
135     pub struct baz;
136 }
137
138 mod bar {
139     pub mod baz {}
140 }
141 ```
142
143 Or you can reference the item with its parent:
144
145 ```
146 use bar::baz;
147
148 fn main() {
149     let x = foo::baz; // ok!
150 }
151
152 mod foo {
153     pub struct baz;
154 }
155
156 mod bar {
157     pub mod baz {}
158 }
159 ```
160 "##,
161
162 E0253: r##"
163 Attempt was made to import an unimportable value. This can happen when trying
164 to import a method from a trait.
165
166 Erroneous code example:
167
168 ```compile_fail,E0253
169 mod foo {
170     pub trait MyTrait {
171         fn do_something();
172     }
173 }
174
175 use foo::MyTrait::do_something;
176 // error: `do_something` is not directly importable
177
178 fn main() {}
179 ```
180
181 It's invalid to directly import methods belonging to a trait or concrete type.
182 "##,
183
184 E0254: r##"
185 Attempt was made to import an item whereas an extern crate with this name has
186 already been imported.
187
188 Erroneous code example:
189
190 ```compile_fail,E0254
191 extern crate collections;
192
193 mod foo {
194     pub trait collections {
195         fn do_something();
196     }
197 }
198
199 use foo::collections; // error: an extern crate named `collections` has already
200                       //        been imported in this module
201
202 fn main() {}
203 ```
204
205 To fix issue issue, you have to rename at least one of the two imports.
206 Example:
207
208 ```ignore
209 extern crate collections as libcollections; // ok!
210
211 mod foo {
212     pub trait collections {
213         fn do_something();
214     }
215 }
216
217 use foo::collections;
218
219 fn main() {}
220 ```
221 "##,
222
223 E0255: r##"
224 You can't import a value whose name is the same as another value defined in the
225 module.
226
227 Erroneous code example:
228
229 ```compile_fail,E0255
230 use bar::foo; // error: an item named `foo` is already in scope
231
232 fn foo() {}
233
234 mod bar {
235      pub fn foo() {}
236 }
237
238 fn main() {}
239 ```
240
241 You can use aliases in order to fix this error. Example:
242
243 ```
244 use bar::foo as bar_foo; // ok!
245
246 fn foo() {}
247
248 mod bar {
249      pub fn foo() {}
250 }
251
252 fn main() {}
253 ```
254
255 Or you can reference the item with its parent:
256
257 ```
258 fn foo() {}
259
260 mod bar {
261      pub fn foo() {}
262 }
263
264 fn main() {
265     bar::foo(); // we get the item by referring to its parent
266 }
267 ```
268 "##,
269
270 E0256: r##"
271 ## Note: this error code is no longer emitted by the compiler.
272
273 You can't import a type or module when the name of the item being imported is
274 the same as another type or submodule defined in the module.
275
276 An example of this error:
277
278 ```compile_fail
279 use foo::Bar; // error
280
281 type Bar = u32;
282
283 mod foo {
284     pub mod Bar { }
285 }
286
287 fn main() {}
288 ```
289 "##,
290
291 E0259: r##"
292 The name chosen for an external crate conflicts with another external crate
293 that has been imported into the current module.
294
295 Erroneous code example:
296
297 ```compile_fail,E0259
298 extern crate std;
299 extern crate libc as std;
300
301 fn main() {}
302 ```
303
304 The solution is to choose a different name that doesn't conflict with any
305 external crate imported into the current module.
306
307 Correct example:
308
309 ```ignore
310 extern crate std;
311 extern crate libc as other_name;
312 ```
313 "##,
314
315 E0260: r##"
316 The name for an item declaration conflicts with an external crate's name.
317
318 Erroneous code example:
319
320 ```ignore,E0260
321 extern crate abc;
322
323 struct abc;
324 ```
325
326 There are two possible solutions:
327
328 Solution #1: Rename the item.
329
330 ```ignore
331 extern crate abc;
332
333 struct xyz;
334 ```
335
336 Solution #2: Import the crate with a different name.
337
338 ```ignore
339 extern crate abc as xyz;
340
341 struct abc;
342 ```
343
344 See the Declaration Statements section of the reference for more information
345 about what constitutes an Item declaration and what does not:
346
347 https://doc.rust-lang.org/reference.html#statements
348 "##,
349
350 E0364: r##"
351 Private items cannot be publicly re-exported. This error indicates that you
352 attempted to `pub use` a type or value that was not itself public.
353
354 Erroneous code example:
355
356 ```compile_fail
357 mod foo {
358     const X: u32 = 1;
359 }
360
361 pub use foo::X;
362
363 fn main() {}
364 ```
365
366 The solution to this problem is to ensure that the items that you are
367 re-exporting are themselves marked with `pub`:
368
369 ```
370 mod foo {
371     pub const X: u32 = 1;
372 }
373
374 pub use foo::X;
375
376 fn main() {}
377 ```
378
379 See the 'Use Declarations' section of the reference for more information on
380 this topic:
381
382 https://doc.rust-lang.org/reference.html#use-declarations
383 "##,
384
385 E0365: r##"
386 Private modules cannot be publicly re-exported. This error indicates that you
387 attempted to `pub use` a module that was not itself public.
388
389 Erroneous code example:
390
391 ```compile_fail,E0365
392 mod foo {
393     pub const X: u32 = 1;
394 }
395
396 pub use foo as foo2;
397
398 fn main() {}
399 ```
400
401 The solution to this problem is to ensure that the module that you are
402 re-exporting is itself marked with `pub`:
403
404 ```
405 pub mod foo {
406     pub const X: u32 = 1;
407 }
408
409 pub use foo as foo2;
410
411 fn main() {}
412 ```
413
414 See the 'Use Declarations' section of the reference for more information
415 on this topic:
416
417 https://doc.rust-lang.org/reference.html#use-declarations
418 "##,
419
420 E0401: r##"
421 Inner items do not inherit type parameters from the functions they are embedded
422 in.
423
424 Erroneous code example:
425
426 ```compile_fail,E0401
427 fn foo<T>(x: T) {
428     fn bar(y: T) { // T is defined in the "outer" function
429         // ..
430     }
431     bar(x);
432 }
433 ```
434
435 Nor will this:
436
437 ```compile_fail,E0401
438 fn foo<T>(x: T) {
439     type MaybeT = Option<T>;
440     // ...
441 }
442 ```
443
444 Or this:
445
446 ```compile_fail,E0401
447 fn foo<T>(x: T) {
448     struct Foo {
449         x: T,
450     }
451     // ...
452 }
453 ```
454
455 Items inside functions are basically just like top-level items, except
456 that they can only be used from the function they are in.
457
458 There are a couple of solutions for this.
459
460 If the item is a function, you may use a closure:
461
462 ```
463 fn foo<T>(x: T) {
464     let bar = |y: T| { // explicit type annotation may not be necessary
465         // ..
466     };
467     bar(x);
468 }
469 ```
470
471 For a generic item, you can copy over the parameters:
472
473 ```
474 fn foo<T>(x: T) {
475     fn bar<T>(y: T) {
476         // ..
477     }
478     bar(x);
479 }
480 ```
481
482 ```
483 fn foo<T>(x: T) {
484     type MaybeT<T> = Option<T>;
485 }
486 ```
487
488 Be sure to copy over any bounds as well:
489
490 ```
491 fn foo<T: Copy>(x: T) {
492     fn bar<T: Copy>(y: T) {
493         // ..
494     }
495     bar(x);
496 }
497 ```
498
499 ```
500 fn foo<T: Copy>(x: T) {
501     struct Foo<T: Copy> {
502         x: T,
503     }
504 }
505 ```
506
507 This may require additional type hints in the function body.
508
509 In case the item is a function inside an `impl`, defining a private helper
510 function might be easier:
511
512 ```ignore
513 impl<T> Foo<T> {
514     pub fn foo(&self, x: T) {
515         self.bar(x);
516     }
517
518     fn bar(&self, y: T) {
519         // ..
520     }
521 }
522 ```
523
524 For default impls in traits, the private helper solution won't work, however
525 closures or copying the parameters should still work.
526 "##,
527
528 E0403: r##"
529 Some type parameters have the same name.
530
531 Erroneous code example:
532
533 ```compile_fail,E0403
534 fn foo<T, T>(s: T, u: T) {} // error: the name `T` is already used for a type
535                             //        parameter in this type parameter list
536 ```
537
538 Please verify that none of the type parameterss are misspelled, and rename any
539 clashing parameters. Example:
540
541 ```
542 fn foo<T, Y>(s: T, u: Y) {} // ok!
543 ```
544 "##,
545
546 E0404: r##"
547 You tried to implement something which was not a trait on an object.
548
549 Erroneous code example:
550
551 ```compile_fail,E0404
552 struct Foo;
553 struct Bar;
554
555 impl Foo for Bar {} // error: `Foo` is not a trait
556 ```
557
558 Please verify that you didn't misspell the trait's name or otherwise use the
559 wrong identifier. Example:
560
561 ```
562 trait Foo {
563     // some functions
564 }
565 struct Bar;
566
567 impl Foo for Bar { // ok!
568     // functions implementation
569 }
570 ```
571 "##,
572
573 E0405: r##"
574 The code refers to a trait that is not in scope.
575
576 Erroneous code example:
577
578 ```compile_fail,E0405
579 struct Foo;
580
581 impl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope
582 ```
583
584 Please verify that the name of the trait wasn't misspelled and ensure that it
585 was imported. Example:
586
587 ```ignore
588 // solution 1:
589 use some_file::SomeTrait;
590
591 // solution 2:
592 trait SomeTrait {
593     // some functions
594 }
595
596 struct Foo;
597
598 impl SomeTrait for Foo { // ok!
599     // implements functions
600 }
601 ```
602 "##,
603
604 E0407: r##"
605 A definition of a method not in the implemented trait was given in a trait
606 implementation.
607
608 Erroneous code example:
609
610 ```compile_fail,E0407
611 trait Foo {
612     fn a();
613 }
614
615 struct Bar;
616
617 impl Foo for Bar {
618     fn a() {}
619     fn b() {} // error: method `b` is not a member of trait `Foo`
620 }
621 ```
622
623 Please verify you didn't misspell the method name and you used the correct
624 trait. First example:
625
626 ```
627 trait Foo {
628     fn a();
629     fn b();
630 }
631
632 struct Bar;
633
634 impl Foo for Bar {
635     fn a() {}
636     fn b() {} // ok!
637 }
638 ```
639
640 Second example:
641
642 ```
643 trait Foo {
644     fn a();
645 }
646
647 struct Bar;
648
649 impl Foo for Bar {
650     fn a() {}
651 }
652
653 impl Bar {
654     fn b() {}
655 }
656 ```
657 "##,
658
659 E0408: r##"
660 An "or" pattern was used where the variable bindings are not consistently bound
661 across patterns.
662
663 Erroneous code example:
664
665 ```compile_fail,E0408
666 match x {
667     Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is
668                                       //        not bound in pattern #2
669     _ => ()
670 }
671 ```
672
673 Here, `y` is bound to the contents of the `Some` and can be used within the
674 block corresponding to the match arm. However, in case `x` is `None`, we have
675 not specified what `y` is, and the block will use a nonexistent variable.
676
677 To fix this error, either split into multiple match arms:
678
679 ```
680 let x = Some(1);
681 match x {
682     Some(y) => { /* use y */ }
683     None => { /* ... */ }
684 }
685 ```
686
687 or, bind the variable to a field of the same type in all sub-patterns of the
688 or pattern:
689
690 ```
691 let x = (0, 2);
692 match x {
693     (0, y) | (y, 0) => { /* use y */}
694     _ => {}
695 }
696 ```
697
698 In this example, if `x` matches the pattern `(0, _)`, the second field is set
699 to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
700 cases `y` is set to some value.
701 "##,
702
703 E0409: r##"
704 An "or" pattern was used where the variable bindings are not consistently bound
705 across patterns.
706
707 Erroneous code example:
708
709 ```compile_fail,E0409
710 let x = (0, 2);
711 match x {
712     (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
713                                           //        different mode in pattern #2
714                                           //        than in pattern #1
715     _ => ()
716 }
717 ```
718
719 Here, `y` is bound by-value in one case and by-reference in the other.
720
721 To fix this error, just use the same mode in both cases.
722 Generally using `ref` or `ref mut` where not already used will fix this:
723
724 ```ignore
725 let x = (0, 2);
726 match x {
727     (0, ref y) | (ref y, 0) => { /* use y */}
728     _ => ()
729 }
730 ```
731
732 Alternatively, split the pattern:
733
734 ```
735 let x = (0, 2);
736 match x {
737     (y, 0) => { /* use y */ }
738     (0, ref y) => { /* use y */}
739     _ => ()
740 }
741 ```
742 "##,
743
744 E0411: r##"
745 The `Self` keyword was used outside an impl or a trait.
746
747 Erroneous code example:
748
749 ```compile_fail,E0411
750 <Self>::foo; // error: use of `Self` outside of an impl or trait
751 ```
752
753 The `Self` keyword represents the current type, which explains why it can only
754 be used inside an impl or a trait. It gives access to the associated items of a
755 type:
756
757 ```
758 trait Foo {
759     type Bar;
760 }
761
762 trait Baz : Foo {
763     fn bar() -> Self::Bar; // like this
764 }
765 ```
766
767 However, be careful when two types have a common associated type:
768
769 ```compile_fail
770 trait Foo {
771     type Bar;
772 }
773
774 trait Foo2 {
775     type Bar;
776 }
777
778 trait Baz : Foo + Foo2 {
779     fn bar() -> Self::Bar;
780     // error: ambiguous associated type `Bar` in bounds of `Self`
781 }
782 ```
783
784 This problem can be solved by specifying from which trait we want to use the
785 `Bar` type:
786
787 ```
788 trait Foo {
789     type Bar;
790 }
791
792 trait Foo2 {
793     type Bar;
794 }
795
796 trait Baz : Foo + Foo2 {
797     fn bar() -> <Self as Foo>::Bar; // ok!
798 }
799 ```
800 "##,
801
802 E0412: r##"
803 The type name used is not in scope.
804
805 Erroneous code examples:
806
807 ```compile_fail,E0412
808 impl Something {} // error: type name `Something` is not in scope
809
810 // or:
811
812 trait Foo {
813     fn bar(N); // error: type name `N` is not in scope
814 }
815
816 // or:
817
818 fn foo(x: T) {} // type name `T` is not in scope
819 ```
820
821 To fix this error, please verify you didn't misspell the type name, you did
822 declare it or imported it into the scope. Examples:
823
824 ```
825 struct Something;
826
827 impl Something {} // ok!
828
829 // or:
830
831 trait Foo {
832     type N;
833
834     fn bar(Self::N); // ok!
835 }
836
837 // or:
838
839 fn foo<T>(x: T) {} // ok!
840 ```
841 "##,
842
843 E0415: r##"
844 More than one function parameter have the same name.
845
846 Erroneous code example:
847
848 ```compile_fail,E0415
849 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
850                           //        once in this parameter list
851 ```
852
853 Please verify you didn't misspell parameters' name. Example:
854
855 ```
856 fn foo(f: i32, g: i32) {} // ok!
857 ```
858 "##,
859
860 E0416: r##"
861 An identifier is bound more than once in a pattern.
862
863 Erroneous code example:
864
865 ```compile_fail,E0416
866 match (1, 2) {
867     (x, x) => {} // error: identifier `x` is bound more than once in the
868                  //        same pattern
869 }
870 ```
871
872 Please verify you didn't misspell identifiers' name. Example:
873
874 ```
875 match (1, 2) {
876     (x, y) => {} // ok!
877 }
878 ```
879
880 Or maybe did you mean to unify? Consider using a guard:
881
882 ```ignore
883 match (A, B, C) {
884     (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
885     (y, z, see) => { /* A and B unequal; do another thing */ }
886 }
887 ```
888 "##,
889
890 E0422: r##"
891 You are trying to use an identifier that is either undefined or not a struct.
892 Erroneous code example:
893 ``` compile_fail,E0422
894 fn main () {
895     let x = Foo { x: 1, y: 2 };
896 }
897 ```
898 In this case, `Foo` is undefined, so it inherently isn't anything, and
899 definitely not a struct.
900 ```compile_fail
901 fn main () {
902     let foo = 1;
903     let x = foo { x: 1, y: 2 };
904 }
905 ```
906 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
907 one.
908 "##,
909
910 E0423: r##"
911 A `struct` variant name was used like a function name.
912
913 Erroneous code example:
914
915 ```compile_fail,E0423
916 struct Foo { a: bool };
917
918 let f = Foo();
919 // error: `Foo` is a struct variant name, but this expression uses
920 //        it like a function name
921 ```
922
923 Please verify you didn't misspell the name of what you actually wanted to use
924 here. Example:
925
926 ```
927 fn Foo() -> u32 { 0 }
928
929 let f = Foo(); // ok!
930 ```
931 "##,
932
933 E0424: r##"
934 The `self` keyword was used in a static method.
935
936 Erroneous code example:
937
938 ```compile_fail,E0424
939 struct Foo;
940
941 impl Foo {
942     fn bar(self) {}
943
944     fn foo() {
945         self.bar(); // error: `self` is not available in a static method.
946     }
947 }
948 ```
949
950 Please check if the method's argument list should have contained `self`,
951 `&self`, or `&mut self` (in case you didn't want to create a static
952 method), and add it if so. Example:
953
954 ```
955 struct Foo;
956
957 impl Foo {
958     fn bar(self) {}
959
960     fn foo(self) {
961         self.bar(); // ok!
962     }
963 }
964 ```
965 "##,
966
967 E0425: r##"
968 An unresolved name was used.
969
970 Erroneous code examples:
971
972 ```compile_fail,E0425
973 something_that_doesnt_exist::foo;
974 // error: unresolved name `something_that_doesnt_exist::foo`
975
976 // or:
977
978 trait Foo {
979     fn bar() {
980         Self; // error: unresolved name `Self`
981     }
982 }
983
984 // or:
985
986 let x = unknown_variable;  // error: unresolved name `unknown_variable`
987 ```
988
989 Please verify that the name wasn't misspelled and ensure that the
990 identifier being referred to is valid for the given situation. Example:
991
992 ```
993 enum something_that_does_exist {
994     Foo,
995 }
996 ```
997
998 Or:
999
1000 ```
1001 mod something_that_does_exist {
1002     pub static foo : i32 = 0i32;
1003 }
1004
1005 something_that_does_exist::foo; // ok!
1006 ```
1007
1008 Or:
1009
1010 ```
1011 let unknown_variable = 12u32;
1012 let x = unknown_variable; // ok!
1013 ```
1014
1015 If the item is not defined in the current module, it must be imported using a
1016 `use` statement, like so:
1017
1018 ```ignore
1019 use foo::bar;
1020 bar();
1021 ```
1022
1023 If the item you are importing is not defined in some super-module of the
1024 current module, then it must also be declared as public (e.g., `pub fn`).
1025 "##,
1026
1027 E0426: r##"
1028 An undeclared label was used.
1029
1030 Erroneous code example:
1031
1032 ```compile_fail,E0426
1033 loop {
1034     break 'a; // error: use of undeclared label `'a`
1035 }
1036 ```
1037
1038 Please verify you spelt or declare the label correctly. Example:
1039
1040 ```
1041 'a: loop {
1042     break 'a; // ok!
1043 }
1044 ```
1045 "##,
1046
1047 E0428: r##"
1048 A type or module has been defined more than once.
1049
1050 Erroneous code example:
1051
1052 ```compile_fail,E0428
1053 struct Bar;
1054 struct Bar; // error: duplicate definition of value `Bar`
1055 ```
1056
1057 Please verify you didn't misspell the type/module's name or remove/rename the
1058 duplicated one. Example:
1059
1060 ```
1061 struct Bar;
1062 struct Bar2; // ok!
1063 ```
1064 "##,
1065
1066 E0429: r##"
1067 The `self` keyword cannot appear alone as the last segment in a `use`
1068 declaration.
1069
1070 Erroneous code example:
1071
1072 ```compile_fail,E0429
1073 use std::fmt::self; // error: `self` imports are only allowed within a { } list
1074 ```
1075
1076 To use a namespace itself in addition to some of its members, `self` may appear
1077 as part of a brace-enclosed list of imports:
1078
1079 ```
1080 use std::fmt::{self, Debug};
1081 ```
1082
1083 If you only want to import the namespace, do so directly:
1084
1085 ```
1086 use std::fmt;
1087 ```
1088 "##,
1089
1090 E0430: r##"
1091 The `self` import appears more than once in the list.
1092
1093 Erroneous code example:
1094
1095 ```compile_fail,E0430
1096 use something::{self, self}; // error: `self` import can only appear once in
1097                              //        the list
1098 ```
1099
1100 Please verify you didn't misspell the import name or remove the duplicated
1101 `self` import. Example:
1102
1103 ```ignore
1104 use something::self; // ok!
1105 ```
1106 "##,
1107
1108 E0431: r##"
1109 An invalid `self` import was made.
1110
1111 Erroneous code example:
1112
1113 ```compile_fail,E0431
1114 use {self}; // error: `self` import can only appear in an import list with a
1115             //        non-empty prefix
1116 ```
1117
1118 You cannot import the current module into itself, please remove this import
1119 or verify you didn't misspell it.
1120 "##,
1121
1122 E0432: r##"
1123 An import was unresolved.
1124
1125 Erroneous code example:
1126
1127 ```compile_fail,E0432
1128 use something::Foo; // error: unresolved import `something::Foo`.
1129 ```
1130
1131 Paths in `use` statements are relative to the crate root. To import items
1132 relative to the current and parent modules, use the `self::` and `super::`
1133 prefixes, respectively. Also verify that you didn't misspell the import
1134 name and that the import exists in the module from where you tried to
1135 import it. Example:
1136
1137 ```ignore
1138 use self::something::Foo; // ok!
1139
1140 mod something {
1141     pub struct Foo;
1142 }
1143 ```
1144
1145 Or, if you tried to use a module from an external crate, you may have missed
1146 the `extern crate` declaration (which is usually placed in the crate root):
1147
1148 ```ignore
1149 extern crate homura; // Required to use the `homura` crate
1150
1151 use homura::Madoka;
1152 ```
1153 "##,
1154
1155 E0433: r##"
1156 An undeclared type or module was used.
1157
1158 Erroneous code example:
1159
1160 ```compile_fail,E0433
1161 let map = HashMap::new();
1162 // error: failed to resolve. Use of undeclared type or module `HashMap`
1163 ```
1164
1165 Please verify you didn't misspell the type/module's name or that you didn't
1166 forgot to import it:
1167
1168
1169 ```
1170 use std::collections::HashMap; // HashMap has been imported.
1171 let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1172 ```
1173 "##,
1174
1175 E0434: r##"
1176 This error indicates that a variable usage inside an inner function is invalid
1177 because the variable comes from a dynamic environment. Inner functions do not
1178 have access to their containing environment.
1179
1180 Erroneous code example:
1181
1182 ```compile_fail,E0434
1183 fn foo() {
1184     let y = 5;
1185     fn bar() -> u32 {
1186         y // error: can't capture dynamic environment in a fn item; use the
1187           //        || { ... } closure form instead.
1188     }
1189 }
1190 ```
1191
1192 Functions do not capture local variables. To fix this error, you can replace the
1193 function with a closure:
1194
1195 ```
1196 fn foo() {
1197     let y = 5;
1198     let bar = || {
1199         y
1200     };
1201 }
1202 ```
1203
1204 or replace the captured variable with a constant or a static item:
1205
1206 ```
1207 fn foo() {
1208     static mut X: u32 = 4;
1209     const Y: u32 = 5;
1210     fn bar() -> u32 {
1211         unsafe {
1212             X = 3;
1213         }
1214         Y
1215     }
1216 }
1217 ```
1218 "##,
1219
1220 E0435: r##"
1221 A non-constant value was used to initialise a constant.
1222
1223 Erroneous code example:
1224
1225 ```compile_fail,E0435
1226 let foo = 42u32;
1227 const FOO : u32 = foo; // error: attempt to use a non-constant value in a
1228                        //        constant
1229 ```
1230
1231 To fix this error, please replace the value with a constant. Example:
1232
1233 ```
1234 const FOO : u32 = 42u32; // ok!
1235 ```
1236
1237 Or:
1238
1239 ```
1240 const OTHER_FOO : u32 = 42u32;
1241 const FOO : u32 = OTHER_FOO; // ok!
1242 ```
1243 "##,
1244
1245 E0437: r##"
1246 Trait implementations can only implement associated types that are members of
1247 the trait in question. This error indicates that you attempted to implement
1248 an associated type whose name does not match the name of any associated type
1249 in the trait.
1250
1251 Erroneous code example:
1252
1253 ```compile_fail,E0437
1254 trait Foo {}
1255
1256 impl Foo for i32 {
1257     type Bar = bool;
1258 }
1259 ```
1260
1261 The solution to this problem is to remove the extraneous associated type:
1262
1263 ```
1264 trait Foo {}
1265
1266 impl Foo for i32 {}
1267 ```
1268 "##,
1269
1270 E0438: r##"
1271 Trait implementations can only implement associated constants that are
1272 members of the trait in question. This error indicates that you
1273 attempted to implement an associated constant whose name does not
1274 match the name of any associated constant in the trait.
1275
1276 Erroneous code example:
1277
1278 ```compile_fail,E0438
1279 #![feature(associated_consts)]
1280
1281 trait Foo {}
1282
1283 impl Foo for i32 {
1284     const BAR: bool = true;
1285 }
1286 ```
1287
1288 The solution to this problem is to remove the extraneous associated constant:
1289
1290 ```
1291 trait Foo {}
1292
1293 impl Foo for i32 {}
1294 ```
1295 "##,
1296
1297 E0466: r##"
1298 Macro import declarations were malformed.
1299
1300 Erroneous code examples:
1301
1302 ```compile_fail,E0466
1303 #[macro_use(a_macro(another_macro))] // error: invalid import declaration
1304 extern crate core as some_crate;
1305
1306 #[macro_use(i_want = "some_macros")] // error: invalid import declaration
1307 extern crate core as another_crate;
1308 ```
1309
1310 This is a syntax error at the level of attribute declarations. The proper
1311 syntax for macro imports is the following:
1312
1313 ```ignore
1314 // In some_crate:
1315 #[macro_export]
1316 macro_rules! get_tacos {
1317     ...
1318 }
1319
1320 #[macro_export]
1321 macro_rules! get_pimientos {
1322     ...
1323 }
1324
1325 // In your crate:
1326 #[macro_use(get_tacos, get_pimientos)] // It imports `get_tacos` and
1327 extern crate some_crate;               // `get_pimientos` macros from some_crate
1328 ```
1329
1330 If you would like to import all exported macros, write `macro_use` with no
1331 arguments.
1332 "##,
1333
1334 E0467: r##"
1335 Macro reexport declarations were empty or malformed.
1336
1337 Erroneous code examples:
1338
1339 ```compile_fail,E0467
1340 #[macro_reexport]                    // error: no macros listed for export
1341 extern crate core as macros_for_good;
1342
1343 #[macro_reexport(fun_macro = "foo")] // error: not a macro identifier
1344 extern crate core as other_macros_for_good;
1345 ```
1346
1347 This is a syntax error at the level of attribute declarations.
1348
1349 Currently, `macro_reexport` requires at least one macro name to be listed.
1350 Unlike `macro_use`, listing no names does not reexport all macros from the
1351 given crate.
1352
1353 Decide which macros you would like to export and list them properly.
1354
1355 These are proper reexport declarations:
1356
1357 ```ignore
1358 #[macro_reexport(some_macro, another_macro)]
1359 extern crate macros_for_good;
1360 ```
1361 "##,
1362
1363 E0468: r##"
1364 A non-root module attempts to import macros from another crate.
1365
1366 Example of erroneous code:
1367
1368 ```compile_fail,E0468
1369 mod foo {
1370     #[macro_use(helpful_macro)] // error: must be at crate root to import
1371     extern crate core;          //        macros from another crate
1372     helpful_macro!(...);
1373 }
1374 ```
1375
1376 Only `extern crate` imports at the crate root level are allowed to import
1377 macros.
1378
1379 Either move the macro import to crate root or do without the foreign macros.
1380 This will work:
1381
1382 ```ignore
1383 #[macro_use(helpful_macro)]
1384 extern crate some_crate;
1385
1386 mod foo {
1387     helpful_macro!(...)
1388 }
1389 ```
1390 "##,
1391
1392 E0469: r##"
1393 A macro listed for import was not found.
1394
1395 Erroneous code example:
1396
1397 ```compile_fail,E0469
1398 #[macro_use(drink, be_merry)] // error: imported macro not found
1399 extern crate collections;
1400
1401 fn main() {
1402     // ...
1403 }
1404 ```
1405
1406 Either the listed macro is not contained in the imported crate, or it is not
1407 exported from the given crate.
1408
1409 This could be caused by a typo. Did you misspell the macro's name?
1410
1411 Double-check the names of the macros listed for import, and that the crate
1412 in question exports them.
1413
1414 A working version would be:
1415
1416 ```ignore
1417 // In some_crate crate:
1418 #[macro_export]
1419 macro_rules! eat {
1420     ...
1421 }
1422
1423 #[macro_export]
1424 macro_rules! drink {
1425     ...
1426 }
1427
1428 // In your crate:
1429 #[macro_use(eat, drink)]
1430 extern crate some_crate; //ok!
1431 ```
1432 "##,
1433
1434 E0470: r##"
1435 A macro listed for reexport was not found.
1436
1437 Erroneous code example:
1438
1439 ```compile_fail,E0470
1440 #[macro_reexport(drink, be_merry)]
1441 extern crate collections;
1442
1443 fn main() {
1444     // ...
1445 }
1446 ```
1447
1448 Either the listed macro is not contained in the imported crate, or it is not
1449 exported from the given crate.
1450
1451 This could be caused by a typo. Did you misspell the macro's name?
1452
1453 Double-check the names of the macros listed for reexport, and that the crate
1454 in question exports them.
1455
1456 A working version:
1457
1458 ```ignore
1459 // In some_crate crate:
1460 #[macro_export]
1461 macro_rules! eat {
1462     ...
1463 }
1464
1465 #[macro_export]
1466 macro_rules! drink {
1467     ...
1468 }
1469
1470 // In your_crate:
1471 #[macro_reexport(eat, drink)]
1472 extern crate some_crate;
1473 ```
1474 "##,
1475
1476 E0530: r##"
1477 A binding shadowed something it shouldn't.
1478
1479 Erroneous code example:
1480
1481 ```compile_fail,E0530
1482 static TEST: i32 = 0;
1483
1484 let r: (i32, i32) = (0, 0);
1485 match r {
1486     TEST => {} // error: match bindings cannot shadow statics
1487 }
1488 ```
1489
1490 To fix this error, just change the binding's name in order to avoid shadowing
1491 one of the following:
1492
1493 * struct name
1494 * struct/enum variant
1495 * static
1496 * const
1497 * associated const
1498
1499 Fixed example:
1500
1501 ```
1502 static TEST: i32 = 0;
1503
1504 let r: (i32, i32) = (0, 0);
1505 match r {
1506     something => {} // ok!
1507 }
1508 ```
1509 "##,
1510
1511 E0532: r##"
1512 Pattern arm did not match expected kind.
1513
1514 Erroneous code example:
1515
1516 ```compile_fail,E0532
1517 enum State {
1518     Succeeded,
1519     Failed(String),
1520 }
1521
1522 fn print_on_failure(state: &State) {
1523     match *state {
1524         // error: expected unit struct/variant or constant, found tuple
1525         //        variant `State::Failed`
1526         State::Failed => println!("Failed"),
1527         _ => ()
1528     }
1529 }
1530 ```
1531
1532 To fix this error, ensure the match arm kind is the same as the expression
1533 matched.
1534
1535 Fixed example:
1536
1537 ```
1538 enum State {
1539     Succeeded,
1540     Failed(String),
1541 }
1542
1543 fn print_on_failure(state: &State) {
1544     match *state {
1545         State::Failed(ref msg) => println!("Failed with {}", msg),
1546         _ => ()
1547     }
1548 }
1549 ```
1550 "##,
1551
1552 }
1553
1554 register_diagnostics! {
1555 //  E0153, unused error code
1556 //  E0157, unused error code
1557 //  E0257,
1558 //  E0258,
1559     E0402, // cannot use an outer type parameter in this context
1560 //  E0406, merged into 420
1561 //  E0410, merged into 408
1562 //  E0413, merged into 530
1563 //  E0414, merged into 530
1564 //  E0417, merged into 532
1565 //  E0418, merged into 532
1566 //  E0419, merged into 531
1567 //  E0420, merged into 532
1568 //  E0421, merged into 531
1569     E0531, // unresolved pattern path kind `name`
1570 //  E0427, merged into 530
1571     E0573,
1572     E0574,
1573     E0575,
1574     E0576,
1575     E0577,
1576     E0578,
1577 }