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