]> git.lizzy.rs Git - rust.git/blob - src/librustc_resolve/diagnostics.rs
Rollup merge of #41957 - llogiq:clippy-libsyntax, r=petrochenkov
[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
894 ```compile_fail,E0422
895 fn main () {
896     let x = Foo { x: 1, y: 2 };
897 }
898 ```
899
900 In this case, `Foo` is undefined, so it inherently isn't anything, and
901 definitely not a struct.
902
903 ```compile_fail
904 fn main () {
905     let foo = 1;
906     let x = foo { x: 1, y: 2 };
907 }
908 ```
909
910 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
911 one.
912 "##,
913
914 E0423: r##"
915 A `struct` variant name was used like a function name.
916
917 Erroneous code example:
918
919 ```compile_fail,E0423
920 struct Foo { a: bool };
921
922 let f = Foo();
923 // error: `Foo` is a struct variant name, but this expression uses
924 //        it like a function name
925 ```
926
927 Please verify you didn't misspell the name of what you actually wanted to use
928 here. Example:
929
930 ```
931 fn Foo() -> u32 { 0 }
932
933 let f = Foo(); // ok!
934 ```
935 "##,
936
937 E0424: r##"
938 The `self` keyword was used in a static method.
939
940 Erroneous code example:
941
942 ```compile_fail,E0424
943 struct Foo;
944
945 impl Foo {
946     fn bar(self) {}
947
948     fn foo() {
949         self.bar(); // error: `self` is not available in a static method.
950     }
951 }
952 ```
953
954 Please check if the method's argument list should have contained `self`,
955 `&self`, or `&mut self` (in case you didn't want to create a static
956 method), and add it if so. Example:
957
958 ```
959 struct Foo;
960
961 impl Foo {
962     fn bar(self) {}
963
964     fn foo(self) {
965         self.bar(); // ok!
966     }
967 }
968 ```
969 "##,
970
971 E0425: r##"
972 An unresolved name was used.
973
974 Erroneous code examples:
975
976 ```compile_fail,E0425
977 something_that_doesnt_exist::foo;
978 // error: unresolved name `something_that_doesnt_exist::foo`
979
980 // or:
981
982 trait Foo {
983     fn bar() {
984         Self; // error: unresolved name `Self`
985     }
986 }
987
988 // or:
989
990 let x = unknown_variable;  // error: unresolved name `unknown_variable`
991 ```
992
993 Please verify that the name wasn't misspelled and ensure that the
994 identifier being referred to is valid for the given situation. Example:
995
996 ```
997 enum something_that_does_exist {
998     Foo,
999 }
1000 ```
1001
1002 Or:
1003
1004 ```
1005 mod something_that_does_exist {
1006     pub static foo : i32 = 0i32;
1007 }
1008
1009 something_that_does_exist::foo; // ok!
1010 ```
1011
1012 Or:
1013
1014 ```
1015 let unknown_variable = 12u32;
1016 let x = unknown_variable; // ok!
1017 ```
1018
1019 If the item is not defined in the current module, it must be imported using a
1020 `use` statement, like so:
1021
1022 ```ignore
1023 use foo::bar;
1024 bar();
1025 ```
1026
1027 If the item you are importing is not defined in some super-module of the
1028 current module, then it must also be declared as public (e.g., `pub fn`).
1029 "##,
1030
1031 E0426: r##"
1032 An undeclared label was used.
1033
1034 Erroneous code example:
1035
1036 ```compile_fail,E0426
1037 loop {
1038     break 'a; // error: use of undeclared label `'a`
1039 }
1040 ```
1041
1042 Please verify you spelt or declare the label correctly. Example:
1043
1044 ```
1045 'a: loop {
1046     break 'a; // ok!
1047 }
1048 ```
1049 "##,
1050
1051 E0428: r##"
1052 A type or module has been defined more than once.
1053
1054 Erroneous code example:
1055
1056 ```compile_fail,E0428
1057 struct Bar;
1058 struct Bar; // error: duplicate definition of value `Bar`
1059 ```
1060
1061 Please verify you didn't misspell the type/module's name or remove/rename the
1062 duplicated one. Example:
1063
1064 ```
1065 struct Bar;
1066 struct Bar2; // ok!
1067 ```
1068 "##,
1069
1070 E0429: r##"
1071 The `self` keyword cannot appear alone as the last segment in a `use`
1072 declaration.
1073
1074 Erroneous code example:
1075
1076 ```compile_fail,E0429
1077 use std::fmt::self; // error: `self` imports are only allowed within a { } list
1078 ```
1079
1080 To use a namespace itself in addition to some of its members, `self` may appear
1081 as part of a brace-enclosed list of imports:
1082
1083 ```
1084 use std::fmt::{self, Debug};
1085 ```
1086
1087 If you only want to import the namespace, do so directly:
1088
1089 ```
1090 use std::fmt;
1091 ```
1092 "##,
1093
1094 E0430: r##"
1095 The `self` import appears more than once in the list.
1096
1097 Erroneous code example:
1098
1099 ```compile_fail,E0430
1100 use something::{self, self}; // error: `self` import can only appear once in
1101                              //        the list
1102 ```
1103
1104 Please verify you didn't misspell the import name or remove the duplicated
1105 `self` import. Example:
1106
1107 ```ignore
1108 use something::self; // ok!
1109 ```
1110 "##,
1111
1112 E0431: r##"
1113 An invalid `self` import was made.
1114
1115 Erroneous code example:
1116
1117 ```compile_fail,E0431
1118 use {self}; // error: `self` import can only appear in an import list with a
1119             //        non-empty prefix
1120 ```
1121
1122 You cannot import the current module into itself, please remove this import
1123 or verify you didn't misspell it.
1124 "##,
1125
1126 E0432: r##"
1127 An import was unresolved.
1128
1129 Erroneous code example:
1130
1131 ```compile_fail,E0432
1132 use something::Foo; // error: unresolved import `something::Foo`.
1133 ```
1134
1135 Paths in `use` statements are relative to the crate root. To import items
1136 relative to the current and parent modules, use the `self::` and `super::`
1137 prefixes, respectively. Also verify that you didn't misspell the import
1138 name and that the import exists in the module from where you tried to
1139 import it. Example:
1140
1141 ```ignore
1142 use self::something::Foo; // ok!
1143
1144 mod something {
1145     pub struct Foo;
1146 }
1147 ```
1148
1149 Or, if you tried to use a module from an external crate, you may have missed
1150 the `extern crate` declaration (which is usually placed in the crate root):
1151
1152 ```ignore
1153 extern crate homura; // Required to use the `homura` crate
1154
1155 use homura::Madoka;
1156 ```
1157 "##,
1158
1159 E0433: r##"
1160 An undeclared type or module was used.
1161
1162 Erroneous code example:
1163
1164 ```compile_fail,E0433
1165 let map = HashMap::new();
1166 // error: failed to resolve. Use of undeclared type or module `HashMap`
1167 ```
1168
1169 Please verify you didn't misspell the type/module's name or that you didn't
1170 forgot to import it:
1171
1172
1173 ```
1174 use std::collections::HashMap; // HashMap has been imported.
1175 let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1176 ```
1177 "##,
1178
1179 E0434: r##"
1180 This error indicates that a variable usage inside an inner function is invalid
1181 because the variable comes from a dynamic environment. Inner functions do not
1182 have access to their containing environment.
1183
1184 Erroneous code example:
1185
1186 ```compile_fail,E0434
1187 fn foo() {
1188     let y = 5;
1189     fn bar() -> u32 {
1190         y // error: can't capture dynamic environment in a fn item; use the
1191           //        || { ... } closure form instead.
1192     }
1193 }
1194 ```
1195
1196 Functions do not capture local variables. To fix this error, you can replace the
1197 function with a closure:
1198
1199 ```
1200 fn foo() {
1201     let y = 5;
1202     let bar = || {
1203         y
1204     };
1205 }
1206 ```
1207
1208 or replace the captured variable with a constant or a static item:
1209
1210 ```
1211 fn foo() {
1212     static mut X: u32 = 4;
1213     const Y: u32 = 5;
1214     fn bar() -> u32 {
1215         unsafe {
1216             X = 3;
1217         }
1218         Y
1219     }
1220 }
1221 ```
1222 "##,
1223
1224 E0435: r##"
1225 A non-constant value was used in a constant expression.
1226
1227 Erroneous code example:
1228
1229 ```compile_fail,E0435
1230 let foo = 42;
1231 let a: [u8; foo]; // error: attempt to use a non-constant value in a constant
1232 ```
1233
1234 To fix this error, please replace the value with a constant. Example:
1235
1236 ```
1237 let a: [u8; 42]; // ok!
1238 ```
1239
1240 Or:
1241
1242 ```
1243 const FOO: usize = 42;
1244 let a: [u8; FOO]; // ok!
1245 ```
1246 "##,
1247
1248 E0437: r##"
1249 Trait implementations can only implement associated types that are members of
1250 the trait in question. This error indicates that you attempted to implement
1251 an associated type whose name does not match the name of any associated type
1252 in the trait.
1253
1254 Erroneous code example:
1255
1256 ```compile_fail,E0437
1257 trait Foo {}
1258
1259 impl Foo for i32 {
1260     type Bar = bool;
1261 }
1262 ```
1263
1264 The solution to this problem is to remove the extraneous associated type:
1265
1266 ```
1267 trait Foo {}
1268
1269 impl Foo for i32 {}
1270 ```
1271 "##,
1272
1273 E0438: r##"
1274 Trait implementations can only implement associated constants that are
1275 members of the trait in question. This error indicates that you
1276 attempted to implement an associated constant whose name does not
1277 match the name of any associated constant in the trait.
1278
1279 Erroneous code example:
1280
1281 ```compile_fail,E0438
1282 #![feature(associated_consts)]
1283
1284 trait Foo {}
1285
1286 impl Foo for i32 {
1287     const BAR: bool = true;
1288 }
1289 ```
1290
1291 The solution to this problem is to remove the extraneous associated constant:
1292
1293 ```
1294 trait Foo {}
1295
1296 impl Foo for i32 {}
1297 ```
1298 "##,
1299
1300 E0466: r##"
1301 Macro import declarations were malformed.
1302
1303 Erroneous code examples:
1304
1305 ```compile_fail,E0466
1306 #[macro_use(a_macro(another_macro))] // error: invalid import declaration
1307 extern crate core as some_crate;
1308
1309 #[macro_use(i_want = "some_macros")] // error: invalid import declaration
1310 extern crate core as another_crate;
1311 ```
1312
1313 This is a syntax error at the level of attribute declarations. The proper
1314 syntax for macro imports is the following:
1315
1316 ```ignore
1317 // In some_crate:
1318 #[macro_export]
1319 macro_rules! get_tacos {
1320     ...
1321 }
1322
1323 #[macro_export]
1324 macro_rules! get_pimientos {
1325     ...
1326 }
1327
1328 // In your crate:
1329 #[macro_use(get_tacos, get_pimientos)] // It imports `get_tacos` and
1330 extern crate some_crate;               // `get_pimientos` macros from some_crate
1331 ```
1332
1333 If you would like to import all exported macros, write `macro_use` with no
1334 arguments.
1335 "##,
1336
1337 E0467: r##"
1338 Macro reexport declarations were empty or malformed.
1339
1340 Erroneous code examples:
1341
1342 ```compile_fail,E0467
1343 #[macro_reexport]                    // error: no macros listed for export
1344 extern crate core as macros_for_good;
1345
1346 #[macro_reexport(fun_macro = "foo")] // error: not a macro identifier
1347 extern crate core as other_macros_for_good;
1348 ```
1349
1350 This is a syntax error at the level of attribute declarations.
1351
1352 Currently, `macro_reexport` requires at least one macro name to be listed.
1353 Unlike `macro_use`, listing no names does not reexport all macros from the
1354 given crate.
1355
1356 Decide which macros you would like to export and list them properly.
1357
1358 These are proper reexport declarations:
1359
1360 ```ignore
1361 #[macro_reexport(some_macro, another_macro)]
1362 extern crate macros_for_good;
1363 ```
1364 "##,
1365
1366 E0468: r##"
1367 A non-root module attempts to import macros from another crate.
1368
1369 Example of erroneous code:
1370
1371 ```compile_fail,E0468
1372 mod foo {
1373     #[macro_use(helpful_macro)] // error: must be at crate root to import
1374     extern crate core;          //        macros from another crate
1375     helpful_macro!(...);
1376 }
1377 ```
1378
1379 Only `extern crate` imports at the crate root level are allowed to import
1380 macros.
1381
1382 Either move the macro import to crate root or do without the foreign macros.
1383 This will work:
1384
1385 ```ignore
1386 #[macro_use(helpful_macro)]
1387 extern crate some_crate;
1388
1389 mod foo {
1390     helpful_macro!(...)
1391 }
1392 ```
1393 "##,
1394
1395 E0469: r##"
1396 A macro listed for import was not found.
1397
1398 Erroneous code example:
1399
1400 ```compile_fail,E0469
1401 #[macro_use(drink, be_merry)] // error: imported macro not found
1402 extern crate collections;
1403
1404 fn main() {
1405     // ...
1406 }
1407 ```
1408
1409 Either the listed macro is not contained in the imported crate, or it is not
1410 exported from the given crate.
1411
1412 This could be caused by a typo. Did you misspell the macro's name?
1413
1414 Double-check the names of the macros listed for import, and that the crate
1415 in question exports them.
1416
1417 A working version would be:
1418
1419 ```ignore
1420 // In some_crate crate:
1421 #[macro_export]
1422 macro_rules! eat {
1423     ...
1424 }
1425
1426 #[macro_export]
1427 macro_rules! drink {
1428     ...
1429 }
1430
1431 // In your crate:
1432 #[macro_use(eat, drink)]
1433 extern crate some_crate; //ok!
1434 ```
1435 "##,
1436
1437 E0470: r##"
1438 A macro listed for reexport was not found.
1439
1440 Erroneous code example:
1441
1442 ```compile_fail,E0470
1443 #[macro_reexport(drink, be_merry)]
1444 extern crate collections;
1445
1446 fn main() {
1447     // ...
1448 }
1449 ```
1450
1451 Either the listed macro is not contained in the imported crate, or it is not
1452 exported from the given crate.
1453
1454 This could be caused by a typo. Did you misspell the macro's name?
1455
1456 Double-check the names of the macros listed for reexport, and that the crate
1457 in question exports them.
1458
1459 A working version:
1460
1461 ```ignore
1462 // In some_crate crate:
1463 #[macro_export]
1464 macro_rules! eat {
1465     ...
1466 }
1467
1468 #[macro_export]
1469 macro_rules! drink {
1470     ...
1471 }
1472
1473 // In your_crate:
1474 #[macro_reexport(eat, drink)]
1475 extern crate some_crate;
1476 ```
1477 "##,
1478
1479 E0530: r##"
1480 A binding shadowed something it shouldn't.
1481
1482 Erroneous code example:
1483
1484 ```compile_fail,E0530
1485 static TEST: i32 = 0;
1486
1487 let r: (i32, i32) = (0, 0);
1488 match r {
1489     TEST => {} // error: match bindings cannot shadow statics
1490 }
1491 ```
1492
1493 To fix this error, just change the binding's name in order to avoid shadowing
1494 one of the following:
1495
1496 * struct name
1497 * struct/enum variant
1498 * static
1499 * const
1500 * associated const
1501
1502 Fixed example:
1503
1504 ```
1505 static TEST: i32 = 0;
1506
1507 let r: (i32, i32) = (0, 0);
1508 match r {
1509     something => {} // ok!
1510 }
1511 ```
1512 "##,
1513
1514 E0532: r##"
1515 Pattern arm did not match expected kind.
1516
1517 Erroneous code example:
1518
1519 ```compile_fail,E0532
1520 enum State {
1521     Succeeded,
1522     Failed(String),
1523 }
1524
1525 fn print_on_failure(state: &State) {
1526     match *state {
1527         // error: expected unit struct/variant or constant, found tuple
1528         //        variant `State::Failed`
1529         State::Failed => println!("Failed"),
1530         _ => ()
1531     }
1532 }
1533 ```
1534
1535 To fix this error, ensure the match arm kind is the same as the expression
1536 matched.
1537
1538 Fixed example:
1539
1540 ```
1541 enum State {
1542     Succeeded,
1543     Failed(String),
1544 }
1545
1546 fn print_on_failure(state: &State) {
1547     match *state {
1548         State::Failed(ref msg) => println!("Failed with {}", msg),
1549         _ => ()
1550     }
1551 }
1552 ```
1553 "##,
1554
1555 }
1556
1557 register_diagnostics! {
1558 //  E0153, unused error code
1559 //  E0157, unused error code
1560 //  E0257,
1561 //  E0258,
1562 //  E0402, // cannot use an outer type parameter in this context
1563 //  E0406, merged into 420
1564 //  E0410, merged into 408
1565 //  E0413, merged into 530
1566 //  E0414, merged into 530
1567 //  E0417, merged into 532
1568 //  E0418, merged into 532
1569 //  E0419, merged into 531
1570 //  E0420, merged into 532
1571 //  E0421, merged into 531
1572     E0531, // unresolved pattern path kind `name`
1573 //  E0427, merged into 530
1574     E0573,
1575     E0574,
1576     E0575,
1577     E0576,
1578     E0577,
1579     E0578,
1580 }