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