]> git.lizzy.rs Git - rust.git/blob - src/librustc_resolve/diagnostics.rs
add explanation for E0429 (`self` use declaration must use brace syntax)
[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 E0154: r##"
19 Imports (`use` statements) are not allowed after non-item statements, such as
20 variable declarations and expression statements.
21
22 Here is an example that demonstrates the error:
23
24 ```compile_fail
25 fn f() {
26     // Variable declaration before import
27     let x = 0;
28     use std::io::Read;
29     // ...
30 }
31 ```
32
33 The solution is to declare the imports at the top of the block, function, or
34 file.
35
36 Here is the previous example again, with the correct order:
37
38 ```
39 fn f() {
40     use std::io::Read;
41     let x = 0;
42     // ...
43 }
44 ```
45
46 See the Declaration Statements section of the reference for more information
47 about what constitutes an Item declaration and what does not:
48
49 https://doc.rust-lang.org/reference.html#statements
50 "##,
51
52 E0251: r##"
53 Two items of the same name cannot be imported without rebinding one of the
54 items under a new local name.
55
56 An example of this error:
57
58 ```compile_fail
59 use foo::baz;
60 use bar::*; // error, do `use foo::baz as quux` instead on the previous line
61
62 fn main() {}
63
64 mod foo {
65     pub struct baz;
66 }
67
68 mod bar {
69     pub mod baz {}
70 }
71 ```
72 "##,
73
74 E0252: r##"
75 Two items of the same name cannot be imported without rebinding one of the
76 items under a new local name.
77
78 An example of this error:
79
80 ```compile_fail
81 use foo::baz;
82 use bar::baz; // error, do `use bar::baz as quux` instead
83
84 fn main() {}
85
86 mod foo {
87     pub struct baz;
88 }
89
90 mod bar {
91     pub mod baz {}
92 }
93 ```
94 "##,
95
96 E0253: r##"
97 Attempt was made to import an unimportable value. This can happen when trying
98 to import a method from a trait. An example of this error:
99
100 ```compile_fail
101 mod foo {
102     pub trait MyTrait {
103         fn do_something();
104     }
105 }
106
107 use foo::MyTrait::do_something;
108 ```
109
110 It's invalid to directly import methods belonging to a trait or concrete type.
111 "##,
112
113 E0255: r##"
114 You can't import a value whose name is the same as another value defined in the
115 module.
116
117 An example of this error:
118
119 ```compile_fail
120 use bar::foo; // error, do `use bar::foo as baz` instead
121
122 fn foo() {}
123
124 mod bar {
125      pub fn foo() {}
126 }
127
128 fn main() {}
129 ```
130 "##,
131
132 E0256: r##"
133 You can't import a type or module when the name of the item being imported is
134 the same as another type or submodule defined in the module.
135
136 An example of this error:
137
138 ```compile_fail
139 use foo::Bar; // error
140
141 type Bar = u32;
142
143 mod foo {
144     pub mod Bar { }
145 }
146
147 fn main() {}
148 ```
149 "##,
150
151 E0259: r##"
152 The name chosen for an external crate conflicts with another external crate
153 that has been imported into the current module.
154
155 Erroneous code example:
156
157 ```compile_fail
158 extern crate a;
159 extern crate crate_a as a;
160 ```
161
162 The solution is to choose a different name that doesn't conflict with any
163 external crate imported into the current module.
164
165 Correct example:
166
167 ```ignore
168 extern crate a;
169 extern crate crate_a as other_name;
170 ```
171 "##,
172
173 E0260: r##"
174 The name for an item declaration conflicts with an external crate's name.
175
176 For instance:
177
178 ```ignore
179 extern crate abc;
180
181 struct abc;
182 ```
183
184 There are two possible solutions:
185
186 Solution #1: Rename the item.
187
188 ```ignore
189 extern crate abc;
190
191 struct xyz;
192 ```
193
194 Solution #2: Import the crate with a different name.
195
196 ```ignore
197 extern crate abc as xyz;
198
199 struct abc;
200 ```
201
202 See the Declaration Statements section of the reference for more information
203 about what constitutes an Item declaration and what does not:
204
205 https://doc.rust-lang.org/reference.html#statements
206 "##,
207
208 E0364: r##"
209 Private items cannot be publicly re-exported.  This error indicates that you
210 attempted to `pub use` a type or value that was not itself public.
211
212 Here is an example that demonstrates the error:
213
214 ```compile_fail
215 mod foo {
216     const X: u32 = 1;
217 }
218
219 pub use foo::X;
220 ```
221
222 The solution to this problem is to ensure that the items that you are
223 re-exporting are themselves marked with `pub`:
224
225 ```ignore
226 mod foo {
227     pub const X: u32 = 1;
228 }
229
230 pub use foo::X;
231 ```
232
233 See the 'Use Declarations' section of the reference for more information on
234 this topic:
235
236 https://doc.rust-lang.org/reference.html#use-declarations
237 "##,
238
239 E0365: r##"
240 Private modules cannot be publicly re-exported. This error indicates that you
241 attempted to `pub use` a module that was not itself public.
242
243 Here is an example that demonstrates the error:
244
245 ```compile_fail
246 mod foo {
247     pub const X: u32 = 1;
248 }
249
250 pub use foo as foo2;
251 ```
252
253 The solution to this problem is to ensure that the module that you are
254 re-exporting is itself marked with `pub`:
255
256 ```ignore
257 pub mod foo {
258     pub const X: u32 = 1;
259 }
260
261 pub use foo as foo2;
262 ```
263
264 See the 'Use Declarations' section of the reference for more information
265 on this topic:
266
267 https://doc.rust-lang.org/reference.html#use-declarations
268 "##,
269
270 E0401: r##"
271 Inner items do not inherit type parameters from the functions they are embedded
272 in. For example, this will not compile:
273
274 ```compile_fail
275 fn foo<T>(x: T) {
276     fn bar(y: T) { // T is defined in the "outer" function
277         // ..
278     }
279     bar(x);
280 }
281 ```
282
283 Nor will this:
284
285 ```compile_fail
286 fn foo<T>(x: T) {
287     type MaybeT = Option<T>;
288     // ...
289 }
290 ```
291
292 Or this:
293
294 ```compile_fail
295 fn foo<T>(x: T) {
296     struct Foo {
297         x: T,
298     }
299     // ...
300 }
301 ```
302
303 Items inside functions are basically just like top-level items, except
304 that they can only be used from the function they are in.
305
306 There are a couple of solutions for this.
307
308 If the item is a function, you may use a closure:
309
310 ```
311 fn foo<T>(x: T) {
312     let bar = |y: T| { // explicit type annotation may not be necessary
313         // ..
314     };
315     bar(x);
316 }
317 ```
318
319 For a generic item, you can copy over the parameters:
320
321 ```
322 fn foo<T>(x: T) {
323     fn bar<T>(y: T) {
324         // ..
325     }
326     bar(x);
327 }
328 ```
329
330 ```
331 fn foo<T>(x: T) {
332     type MaybeT<T> = Option<T>;
333 }
334 ```
335
336 Be sure to copy over any bounds as well:
337
338 ```
339 fn foo<T: Copy>(x: T) {
340     fn bar<T: Copy>(y: T) {
341         // ..
342     }
343     bar(x);
344 }
345 ```
346
347 ```
348 fn foo<T: Copy>(x: T) {
349     struct Foo<T: Copy> {
350         x: T,
351     }
352 }
353 ```
354
355 This may require additional type hints in the function body.
356
357 In case the item is a function inside an `impl`, defining a private helper
358 function might be easier:
359
360 ```ignore
361 impl<T> Foo<T> {
362     pub fn foo(&self, x: T) {
363         self.bar(x);
364     }
365
366     fn bar(&self, y: T) {
367         // ..
368     }
369 }
370 ```
371
372 For default impls in traits, the private helper solution won't work, however
373 closures or copying the parameters should still work.
374 "##,
375
376 E0403: r##"
377 Some type parameters have the same name. Example of erroneous code:
378
379 ```compile_fail
380 fn foo<T, T>(s: T, u: T) {} // error: the name `T` is already used for a type
381                             //        parameter in this type parameter list
382 ```
383
384 Please verify that none of the type parameterss are misspelled, and rename any
385 clashing parameters. Example:
386
387 ```
388 fn foo<T, Y>(s: T, u: Y) {} // ok!
389 ```
390 "##,
391
392 E0404: r##"
393 You tried to implement something which was not a trait on an object. Example of
394 erroneous code:
395
396 ```compile_fail
397 struct Foo;
398 struct Bar;
399
400 impl Foo for Bar {} // error: `Foo` is not a trait
401 ```
402
403 Please verify that you didn't misspell the trait's name or otherwise use the
404 wrong identifier. Example:
405
406 ```
407 trait Foo {
408     // some functions
409 }
410 struct Bar;
411
412 impl Foo for Bar { // ok!
413     // functions implementation
414 }
415 ```
416 "##,
417
418 E0405: r##"
419 The code refers to a trait that is not in scope. Example of erroneous code:
420
421 ```compile_fail
422 struct Foo;
423
424 impl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope
425 ```
426
427 Please verify that the name of the trait wasn't misspelled and ensure that it
428 was imported. Example:
429
430 ```ignore
431 // solution 1:
432 use some_file::SomeTrait;
433
434 // solution 2:
435 trait SomeTrait {
436     // some functions
437 }
438
439 struct Foo;
440
441 impl SomeTrait for Foo { // ok!
442     // implements functions
443 }
444 ```
445 "##,
446
447 E0407: r##"
448 A definition of a method not in the implemented trait was given in a trait
449 implementation. Example of erroneous code:
450
451 ```compile_fail
452 trait Foo {
453     fn a();
454 }
455
456 struct Bar;
457
458 impl Foo for Bar {
459     fn a() {}
460     fn b() {} // error: method `b` is not a member of trait `Foo`
461 }
462 ```
463
464 Please verify you didn't misspell the method name and you used the correct
465 trait. First example:
466
467 ```
468 trait Foo {
469     fn a();
470     fn b();
471 }
472
473 struct Bar;
474
475 impl Foo for Bar {
476     fn a() {}
477     fn b() {} // ok!
478 }
479 ```
480
481 Second example:
482
483 ```
484 trait Foo {
485     fn a();
486 }
487
488 struct Bar;
489
490 impl Foo for Bar {
491     fn a() {}
492 }
493
494 impl Bar {
495     fn b() {}
496 }
497 ```
498 "##,
499
500 E0408: r##"
501 An "or" pattern was used where the variable bindings are not consistently bound
502 across patterns.
503
504 Example of erroneous code:
505
506 ```compile_fail
507 match x {
508     Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is
509                                       //        not bound in pattern #2
510     _ => ()
511 }
512 ```
513
514 Here, `y` is bound to the contents of the `Some` and can be used within the
515 block corresponding to the match arm. However, in case `x` is `None`, we have
516 not specified what `y` is, and the block will use a nonexistent variable.
517
518 To fix this error, either split into multiple match arms:
519
520 ```
521 let x = Some(1);
522 match x {
523     Some(y) => { /* use y */ }
524     None => { /* ... */ }
525 }
526 ```
527
528 or, bind the variable to a field of the same type in all sub-patterns of the
529 or pattern:
530
531 ```
532 let x = (0, 2);
533 match x {
534     (0, y) | (y, 0) => { /* use y */}
535     _ => {}
536 }
537 ```
538
539 In this example, if `x` matches the pattern `(0, _)`, the second field is set
540 to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
541 cases `y` is set to some value.
542 "##,
543
544 E0409: r##"
545 An "or" pattern was used where the variable bindings are not consistently bound
546 across patterns.
547
548 Example of erroneous code:
549
550 ```compile_fail
551 let x = (0, 2);
552 match x {
553     (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
554                                           //        different mode in pattern #2
555                                           //        than in pattern #1
556     _ => ()
557 }
558 ```
559
560 Here, `y` is bound by-value in one case and by-reference in the other.
561
562 To fix this error, just use the same mode in both cases.
563 Generally using `ref` or `ref mut` where not already used will fix this:
564
565 ```ignore
566 let x = (0, 2);
567 match x {
568     (0, ref y) | (ref y, 0) => { /* use y */}
569     _ => ()
570 }
571 ```
572
573 Alternatively, split the pattern:
574
575 ```
576 let x = (0, 2);
577 match x {
578     (y, 0) => { /* use y */ }
579     (0, ref y) => { /* use y */}
580     _ => ()
581 }
582 ```
583 "##,
584
585 E0411: r##"
586 The `Self` keyword was used outside an impl or a trait. Erroneous code example:
587
588 ```compile_fail
589 <Self>::foo; // error: use of `Self` outside of an impl or trait
590 ```
591
592 The `Self` keyword represents the current type, which explains why it can only
593 be used inside an impl or a trait. It gives access to the associated items of a
594 type:
595
596 ```
597 trait Foo {
598     type Bar;
599 }
600
601 trait Baz : Foo {
602     fn bar() -> Self::Bar; // like this
603 }
604 ```
605
606 However, be careful when two types have a common associated type:
607
608 ```compile_fail
609 trait Foo {
610     type Bar;
611 }
612
613 trait Foo2 {
614     type Bar;
615 }
616
617 trait Baz : Foo + Foo2 {
618     fn bar() -> Self::Bar;
619     // error: ambiguous associated type `Bar` in bounds of `Self`
620 }
621 ```
622
623 This problem can be solved by specifying from which trait we want to use the
624 `Bar` type:
625
626 ```
627 trait Foo {
628     type Bar;
629 }
630
631 trait Foo2 {
632     type Bar;
633 }
634
635 trait Baz : Foo + Foo2 {
636     fn bar() -> <Self as Foo>::Bar; // ok!
637 }
638 ```
639 "##,
640
641 E0412: r##"
642 The type name used is not in scope. Example of erroneous codes:
643
644 ```compile_fail
645 impl Something {} // error: type name `Something` is not in scope
646
647 // or:
648
649 trait Foo {
650     fn bar(N); // error: type name `N` is not in scope
651 }
652
653 // or:
654
655 fn foo(x: T) {} // type name `T` is not in scope
656 ```
657
658 To fix this error, please verify you didn't misspell the type name, you did
659 declare it or imported it into the scope. Examples:
660
661 ```
662 struct Something;
663
664 impl Something {} // ok!
665
666 // or:
667
668 trait Foo {
669     type N;
670
671     fn bar(Self::N); // ok!
672 }
673
674 // or:
675
676 fn foo<T>(x: T) {} // ok!
677 ```
678 "##,
679
680 E0413: r##"
681 A declaration shadows an enum variant or unit-like struct in scope. Example of
682 erroneous code:
683
684 ```compile_fail
685 struct Foo;
686
687 let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
688                  //        unit-like struct in scope
689 ```
690
691 To fix this error, rename the variable such that it doesn't shadow any enum
692 variable or structure in scope. Example:
693
694 ```
695 struct Foo;
696
697 let foo = 12i32; // ok!
698 ```
699
700 Or:
701
702 ```
703 struct FooStruct;
704
705 let Foo = 12i32; // ok!
706 ```
707
708 The goal here is to avoid a conflict of names.
709 "##,
710
711 E0414: r##"
712 A variable binding in an irrefutable pattern is shadowing the name of a
713 constant. Example of erroneous code:
714
715 ```compile_fail
716 const FOO: u8 = 7;
717
718 let FOO = 5; // error: variable bindings cannot shadow constants
719
720 // or
721
722 fn bar(FOO: u8) { // error: variable bindings cannot shadow constants
723
724 }
725
726 // or
727
728 for FOO in bar {
729
730 }
731 ```
732
733 Introducing a new variable in Rust is done through a pattern. Thus you can have
734 `let` bindings like `let (a, b) = ...`. However, patterns also allow constants
735 in them, e.g. if you want to match over a constant:
736
737 ```ignore
738 const FOO: u8 = 1;
739
740 match (x,y) {
741  (3, 4) => { .. }, // it is (3,4)
742  (FOO, 1) => { .. }, // it is (1,1)
743  (foo, 1) => { .. }, // it is (anything, 1)
744                      // call the value in the first slot "foo"
745  _ => { .. } // it is anything
746 }
747 ```
748
749 Here, the second arm matches the value of `x` against the constant `FOO`,
750 whereas the third arm will accept any value of `x` and call it `foo`.
751
752 This works for `match`, however in cases where an irrefutable pattern is
753 required, constants can't be used. An irrefutable pattern is one which always
754 matches, whose purpose is only to bind variable names to values. These are
755 required by let, for, and function argument patterns.
756
757 Refutable patterns in such a situation do not make sense, for example:
758
759 ```ignore
760 let Some(x) = foo; // what if foo is None, instead?
761
762 let (1, x) = foo; // what if foo.0 is not 1?
763
764 let (SOME_CONST, x) = foo; // what if foo.0 is not SOME_CONST?
765
766 let SOME_CONST = foo; // what if foo is not SOME_CONST?
767 ```
768
769 Thus, an irrefutable variable binding can't contain a constant.
770
771 To fix this error, just give the marked variable a different name.
772 "##,
773
774 E0415: r##"
775 More than one function parameter have the same name. Example of erroneous code:
776
777 ```compile_fail
778 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
779                           //        once in this parameter list
780 ```
781
782 Please verify you didn't misspell parameters' name. Example:
783
784 ```
785 fn foo(f: i32, g: i32) {} // ok!
786 ```
787 "##,
788
789 E0416: r##"
790 An identifier is bound more than once in a pattern. Example of erroneous code:
791
792 ```compile_fail
793 match (1, 2) {
794     (x, x) => {} // error: identifier `x` is bound more than once in the
795                  //        same pattern
796 }
797 ```
798
799 Please verify you didn't misspell identifiers' name. Example:
800
801 ```
802 match (1, 2) {
803     (x, y) => {} // ok!
804 }
805 ```
806
807 Or maybe did you mean to unify? Consider using a guard:
808
809 ```ignore
810 match (A, B, C) {
811     (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
812     (y, z, see) => { /* A and B unequal; do another thing */ }
813 }
814 ```
815 "##,
816
817 E0417: r##"
818 A static variable was referenced in a pattern. Example of erroneous code:
819
820 ```compile_fail
821 static FOO : i32 = 0;
822
823 match 0 {
824     FOO => {} // error: static variables cannot be referenced in a
825               //        pattern, use a `const` instead
826     _ => {}
827 }
828 ```
829
830 The compiler needs to know the value of the pattern at compile time;
831 compile-time patterns can defined via const or enum items. Please verify
832 that the identifier is spelled correctly, and if so, use a const instead
833 of static to define it. Example:
834
835 ```
836 const FOO : i32 = 0;
837
838 match 0 {
839     FOO => {} // ok!
840     _ => {}
841 }
842 ```
843 "##,
844
845 E0419: r##"
846 An unknown enum variant, struct or const was used. Example of erroneous code:
847
848 ```compile_fail
849 match 0 {
850     Something::Foo => {} // error: unresolved enum variant, struct
851                          //        or const `Foo`
852 }
853 ```
854
855 Please verify you didn't misspell it and the enum variant, struct or const has
856 been declared and imported into scope. Example:
857
858 ```
859 enum Something {
860     Foo,
861     NotFoo,
862 }
863
864 match Something::NotFoo {
865     Something::Foo => {} // ok!
866     _ => {}
867 }
868 ```
869 "##,
870
871 E0422: r##"
872 You are trying to use an identifier that is either undefined or not a struct.
873 For instance:
874
875 ``` compile_fail
876 fn main () {
877     let x = Foo { x: 1, y: 2 };
878 }
879 ```
880
881 In this case, `Foo` is undefined, so it inherently isn't anything, and
882 definitely not a struct.
883
884 ```compile_fail
885 fn main () {
886     let foo = 1;
887     let x = foo { x: 1, y: 2 };
888 }
889 ```
890
891 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
892 one.
893 "##,
894
895 E0423: r##"
896 A `struct` variant name was used like a function name. Example of erroneous
897 code:
898
899 ```compile_fail
900 struct Foo { a: bool};
901
902 let f = Foo();
903 // error: `Foo` is a struct variant name, but this expression uses
904 //        it like a function name
905 ```
906
907 Please verify you didn't misspell the name of what you actually wanted to use
908 here. Example:
909
910 ```
911 fn Foo() -> u32 { 0 }
912
913 let f = Foo(); // ok!
914 ```
915 "##,
916
917 E0424: r##"
918 The `self` keyword was used in a static method. Example of erroneous code:
919
920 ```compile_fail
921 struct Foo;
922
923 impl Foo {
924     fn bar(self) {}
925
926     fn foo() {
927         self.bar(); // error: `self` is not available in a static method.
928     }
929 }
930 ```
931
932 Please check if the method's argument list should have contained `self`,
933 `&self`, or `&mut self` (in case you didn't want to create a static
934 method), and add it if so. Example:
935
936 ```
937 struct Foo;
938
939 impl Foo {
940     fn bar(self) {}
941
942     fn foo(self) {
943         self.bar(); // ok!
944     }
945 }
946 ```
947 "##,
948
949 E0425: r##"
950 An unresolved name was used. Example of erroneous codes:
951
952 ```compile_fail
953 something_that_doesnt_exist::foo;
954 // error: unresolved name `something_that_doesnt_exist::foo`
955
956 // or:
957
958 trait Foo {
959     fn bar() {
960         Self; // error: unresolved name `Self`
961     }
962 }
963
964 // or:
965
966 let x = unknown_variable;  // error: unresolved name `unknown_variable`
967 ```
968
969 Please verify that the name wasn't misspelled and ensure that the
970 identifier being referred to is valid for the given situation. Example:
971
972 ```
973 enum something_that_does_exist {
974     Foo,
975 }
976 ```
977
978 Or:
979
980 ```
981 mod something_that_does_exist {
982     pub static foo : i32 = 0i32;
983 }
984
985 something_that_does_exist::foo; // ok!
986 ```
987
988 Or:
989
990 ```
991 let unknown_variable = 12u32;
992 let x = unknown_variable; // ok!
993 ```
994 "##,
995
996 E0426: r##"
997 An undeclared label was used. Example of erroneous code:
998
999 ```compile_fail
1000 loop {
1001     break 'a; // error: use of undeclared label `'a`
1002 }
1003 ```
1004
1005 Please verify you spelt or declare the label correctly. Example:
1006
1007 ```
1008 'a: loop {
1009     break 'a; // ok!
1010 }
1011 ```
1012 "##,
1013
1014 E0428: r##"
1015 A type or module has been defined more than once. Example of erroneous
1016 code:
1017
1018 ```compile_fail
1019 struct Bar;
1020 struct Bar; // error: duplicate definition of value `Bar`
1021 ```
1022
1023 Please verify you didn't misspell the type/module's name or remove/rename the
1024 duplicated one. Example:
1025
1026 ```
1027 struct Bar;
1028 struct Bar2; // ok!
1029 ```
1030 "##,
1031
1032 E0429: r##"
1033 To import a namespace itself in addition to some of its members, the `self`
1034 keyword may appear in a brace-enclosed list as the last segment in a `use`
1035 declaration. However, `self` cannot be used alone, without the brace
1036 syntax.
1037
1038 Example of erroneous code:
1039
1040 ```compile_fail
1041 use std::fmt::self; // error: `self` imports are only allowed within a { } list
1042 ```
1043
1044 If you only want to import the namespace, do so directly:
1045
1046 ```
1047 use std::fmt;
1048 ```
1049
1050 If you also want to import members in the same statement, you may use the brace
1051 syntax:
1052
1053 ```
1054 use std::fmt::{self, Debug};
1055 ```
1056 "##,
1057
1058 E0430: r##"
1059 The `self` import appears more than once in the list. Erroneous code example:
1060
1061 ```compile_fail
1062 use something::{self, self}; // error: `self` import can only appear once in
1063                              //        the list
1064 ```
1065
1066 Please verify you didn't misspell the import name or remove the duplicated
1067 `self` import. Example:
1068
1069 ```ignore
1070 use something::self; // ok!
1071 ```
1072 "##,
1073
1074 E0431: r##"
1075 An invalid `self` import was made. Erroneous code example:
1076
1077 ```compile_fail
1078 use {self}; // error: `self` import can only appear in an import list with a
1079             //        non-empty prefix
1080 ```
1081
1082 You cannot import the current module into itself, please remove this import
1083 or verify you didn't misspell it.
1084 "##,
1085
1086 E0432: r##"
1087 An import was unresolved. Erroneous code example:
1088
1089 ```compile_fail
1090 use something::Foo; // error: unresolved import `something::Foo`.
1091 ```
1092
1093 Paths in `use` statements are relative to the crate root. To import items
1094 relative to the current and parent modules, use the `self::` and `super::`
1095 prefixes, respectively. Also verify that you didn't misspell the import
1096 name and that the import exists in the module from where you tried to
1097 import it. Example:
1098
1099 ```ignore
1100 use self::something::Foo; // ok!
1101
1102 mod something {
1103     pub struct Foo;
1104 }
1105 ```
1106
1107 Or, if you tried to use a module from an external crate, you may have missed
1108 the `extern crate` declaration (which is usually placed in the crate root):
1109
1110 ```ignore
1111 extern crate homura; // Required to use the `homura` crate
1112
1113 use homura::Madoka;
1114 ```
1115 "##,
1116
1117 E0433: r##"
1118 Invalid import. Example of erroneous code:
1119
1120 ```compile_fail
1121 use something_which_doesnt_exist;
1122 // error: unresolved import `something_which_doesnt_exist`
1123 ```
1124
1125 Please verify you didn't misspell the import's name.
1126 "##,
1127
1128 E0434: r##"
1129 This error indicates that a variable usage inside an inner function is invalid
1130 because the variable comes from a dynamic environment. Inner functions do not
1131 have access to their containing environment.
1132
1133 Example of erroneous code:
1134
1135 ```compile_fail
1136 fn foo() {
1137     let y = 5;
1138     fn bar() -> u32 {
1139         y // error: can't capture dynamic environment in a fn item; use the
1140           //        || { ... } closure form instead.
1141     }
1142 }
1143 ```
1144
1145 Functions do not capture local variables. To fix this error, you can replace the
1146 function with a closure:
1147
1148 ```
1149 fn foo() {
1150     let y = 5;
1151     let bar = || {
1152         y
1153     };
1154 }
1155 ```
1156
1157 or replace the captured variable with a constant or a static item:
1158
1159 ```
1160 fn foo() {
1161     static mut X: u32 = 4;
1162     const Y: u32 = 5;
1163     fn bar() -> u32 {
1164         unsafe {
1165             X = 3;
1166         }
1167         Y
1168     }
1169 }
1170 ```
1171 "##,
1172
1173 E0435: r##"
1174 A non-constant value was used to initialise a constant. Example of erroneous
1175 code:
1176
1177 ```compile_fail
1178 let foo = 42u32;
1179 const FOO : u32 = foo; // error: attempt to use a non-constant value in a
1180                        //        constant
1181 ```
1182
1183 To fix this error, please replace the value with a constant. Example:
1184
1185 ```
1186 const FOO : u32 = 42u32; // ok!
1187 ```
1188
1189 Or:
1190
1191 ```
1192 const OTHER_FOO : u32 = 42u32;
1193 const FOO : u32 = OTHER_FOO; // ok!
1194 ```
1195 "##,
1196
1197 E0437: r##"
1198 Trait implementations can only implement associated types that are members of
1199 the trait in question. This error indicates that you attempted to implement
1200 an associated type whose name does not match the name of any associated type
1201 in the trait.
1202
1203 Here is an example that demonstrates the error:
1204
1205 ```compile_fail
1206 trait Foo {}
1207
1208 impl Foo for i32 {
1209     type Bar = bool;
1210 }
1211 ```
1212
1213 The solution to this problem is to remove the extraneous associated type:
1214
1215 ```
1216 trait Foo {}
1217
1218 impl Foo for i32 {}
1219 ```
1220 "##,
1221
1222 E0438: r##"
1223 Trait implementations can only implement associated constants that are
1224 members of the trait in question. This error indicates that you
1225 attempted to implement an associated constant whose name does not
1226 match the name of any associated constant in the trait.
1227
1228 Here is an example that demonstrates the error:
1229
1230 ```compile_fail
1231 #![feature(associated_consts)]
1232
1233 trait Foo {}
1234
1235 impl Foo for i32 {
1236     const BAR: bool = true;
1237 }
1238 ```
1239
1240 The solution to this problem is to remove the extraneous associated constant:
1241
1242 ```
1243 trait Foo {}
1244
1245 impl Foo for i32 {}
1246 ```
1247 "##
1248
1249 }
1250
1251 register_diagnostics! {
1252 //  E0153, unused error code
1253 //  E0157, unused error code
1254     E0254, // import conflicts with imported crate in this module
1255 //  E0257,
1256 //  E0258,
1257     E0402, // cannot use an outer type parameter in this context
1258     E0406, // undeclared associated type
1259 //  E0410, merged into 408
1260     E0418, // is not an enum variant, struct or const
1261     E0420, // is not an associated const
1262     E0421, // unresolved associated const
1263     E0427, // cannot use `ref` binding mode with ...
1264 }