]> git.lizzy.rs Git - rust.git/blob - src/librustc_resolve/diagnostics.rs
Auto merge of #33478 - xen0n:normalize-callee-trait-ref, r=eddyb
[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 E0411: r##"
501 The `Self` keyword was used outside an impl or a trait. Erroneous code example:
502
503 ```compile_fail
504 <Self>::foo; // error: use of `Self` outside of an impl or trait
505 ```
506
507 The `Self` keyword represents the current type, which explains why it can only
508 be used inside an impl or a trait. It gives access to the associated items of a
509 type:
510
511 ```
512 trait Foo {
513     type Bar;
514 }
515
516 trait Baz : Foo {
517     fn bar() -> Self::Bar; // like this
518 }
519 ```
520
521 However, be careful when two types have a common associated type:
522
523 ```compile_fail
524 trait Foo {
525     type Bar;
526 }
527
528 trait Foo2 {
529     type Bar;
530 }
531
532 trait Baz : Foo + Foo2 {
533     fn bar() -> Self::Bar;
534     // error: ambiguous associated type `Bar` in bounds of `Self`
535 }
536 ```
537
538 This problem can be solved by specifying from which trait we want to use the
539 `Bar` type:
540
541 ```
542 trait Foo {
543     type Bar;
544 }
545
546 trait Foo2 {
547     type Bar;
548 }
549
550 trait Baz : Foo + Foo2 {
551     fn bar() -> <Self as Foo>::Bar; // ok!
552 }
553 ```
554 "##,
555
556 E0412: r##"
557 The type name used is not in scope. Example of erroneous codes:
558
559 ```compile_fail
560 impl Something {} // error: type name `Something` is not in scope
561
562 // or:
563
564 trait Foo {
565     fn bar(N); // error: type name `N` is not in scope
566 }
567
568 // or:
569
570 fn foo(x: T) {} // type name `T` is not in scope
571 ```
572
573 To fix this error, please verify you didn't misspell the type name, you did
574 declare it or imported it into the scope. Examples:
575
576 ```
577 struct Something;
578
579 impl Something {} // ok!
580
581 // or:
582
583 trait Foo {
584     type N;
585
586     fn bar(Self::N); // ok!
587 }
588
589 // or:
590
591 fn foo<T>(x: T) {} // ok!
592 ```
593 "##,
594
595 E0413: r##"
596 A declaration shadows an enum variant or unit-like struct in scope. Example of
597 erroneous code:
598
599 ```compile_fail
600 struct Foo;
601
602 let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
603                  //        unit-like struct in scope
604 ```
605
606 To fix this error, rename the variable such that it doesn't shadow any enum
607 variable or structure in scope. Example:
608
609 ```
610 struct Foo;
611
612 let foo = 12i32; // ok!
613 ```
614
615 Or:
616
617 ```
618 struct FooStruct;
619
620 let Foo = 12i32; // ok!
621 ```
622
623 The goal here is to avoid a conflict of names.
624 "##,
625
626 E0414: r##"
627 A variable binding in an irrefutable pattern is shadowing the name of a
628 constant. Example of erroneous code:
629
630 ```compile_fail
631 const FOO: u8 = 7;
632
633 let FOO = 5; // error: variable bindings cannot shadow constants
634
635 // or
636
637 fn bar(FOO: u8) { // error: variable bindings cannot shadow constants
638
639 }
640
641 // or
642
643 for FOO in bar {
644
645 }
646 ```
647
648 Introducing a new variable in Rust is done through a pattern. Thus you can have
649 `let` bindings like `let (a, b) = ...`. However, patterns also allow constants
650 in them, e.g. if you want to match over a constant:
651
652 ```ignore
653 const FOO: u8 = 1;
654
655 match (x,y) {
656  (3, 4) => { .. }, // it is (3,4)
657  (FOO, 1) => { .. }, // it is (1,1)
658  (foo, 1) => { .. }, // it is (anything, 1)
659                      // call the value in the first slot "foo"
660  _ => { .. } // it is anything
661 }
662 ```
663
664 Here, the second arm matches the value of `x` against the constant `FOO`,
665 whereas the third arm will accept any value of `x` and call it `foo`.
666
667 This works for `match`, however in cases where an irrefutable pattern is
668 required, constants can't be used. An irrefutable pattern is one which always
669 matches, whose purpose is only to bind variable names to values. These are
670 required by let, for, and function argument patterns.
671
672 Refutable patterns in such a situation do not make sense, for example:
673
674 ```ignore
675 let Some(x) = foo; // what if foo is None, instead?
676
677 let (1, x) = foo; // what if foo.0 is not 1?
678
679 let (SOME_CONST, x) = foo; // what if foo.0 is not SOME_CONST?
680
681 let SOME_CONST = foo; // what if foo is not SOME_CONST?
682 ```
683
684 Thus, an irrefutable variable binding can't contain a constant.
685
686 To fix this error, just give the marked variable a different name.
687 "##,
688
689 E0415: r##"
690 More than one function parameter have the same name. Example of erroneous code:
691
692 ```compile_fail
693 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
694                           //        once in this parameter list
695 ```
696
697 Please verify you didn't misspell parameters' name. Example:
698
699 ```
700 fn foo(f: i32, g: i32) {} // ok!
701 ```
702 "##,
703
704 E0416: r##"
705 An identifier is bound more than once in a pattern. Example of erroneous code:
706
707 ```compile_fail
708 match (1, 2) {
709     (x, x) => {} // error: identifier `x` is bound more than once in the
710                  //        same pattern
711 }
712 ```
713
714 Please verify you didn't misspell identifiers' name. Example:
715
716 ```
717 match (1, 2) {
718     (x, y) => {} // ok!
719 }
720 ```
721
722 Or maybe did you mean to unify? Consider using a guard:
723
724 ```ignore
725 match (A, B, C) {
726     (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
727     (y, z, see) => { /* A and B unequal; do another thing */ }
728 }
729 ```
730 "##,
731
732 E0417: r##"
733 A static variable was referenced in a pattern. Example of erroneous code:
734
735 ```compile_fail
736 static FOO : i32 = 0;
737
738 match 0 {
739     FOO => {} // error: static variables cannot be referenced in a
740               //        pattern, use a `const` instead
741     _ => {}
742 }
743 ```
744
745 The compiler needs to know the value of the pattern at compile time;
746 compile-time patterns can defined via const or enum items. Please verify
747 that the identifier is spelled correctly, and if so, use a const instead
748 of static to define it. Example:
749
750 ```
751 const FOO : i32 = 0;
752
753 match 0 {
754     FOO => {} // ok!
755     _ => {}
756 }
757 ```
758 "##,
759
760 E0419: r##"
761 An unknown enum variant, struct or const was used. Example of erroneous code:
762
763 ```compile_fail
764 match 0 {
765     Something::Foo => {} // error: unresolved enum variant, struct
766                          //        or const `Foo`
767 }
768 ```
769
770 Please verify you didn't misspell it and the enum variant, struct or const has
771 been declared and imported into scope. Example:
772
773 ```
774 enum Something {
775     Foo,
776     NotFoo,
777 }
778
779 match Something::NotFoo {
780     Something::Foo => {} // ok!
781     _ => {}
782 }
783 ```
784 "##,
785
786 E0422: r##"
787 You are trying to use an identifier that is either undefined or not a struct.
788 For instance:
789
790 ``` compile_fail
791 fn main () {
792     let x = Foo { x: 1, y: 2 };
793 }
794 ```
795
796 In this case, `Foo` is undefined, so it inherently isn't anything, and
797 definitely not a struct.
798
799 ```compile_fail
800 fn main () {
801     let foo = 1;
802     let x = foo { x: 1, y: 2 };
803 }
804 ```
805
806 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
807 one.
808 "##,
809
810 E0423: r##"
811 A `struct` variant name was used like a function name. Example of erroneous
812 code:
813
814 ```compile_fail
815 struct Foo { a: bool};
816
817 let f = Foo();
818 // error: `Foo` is a struct variant name, but this expression uses
819 //        it like a function name
820 ```
821
822 Please verify you didn't misspell the name of what you actually wanted to use
823 here. Example:
824
825 ```
826 fn Foo() -> u32 { 0 }
827
828 let f = Foo(); // ok!
829 ```
830 "##,
831
832 E0424: r##"
833 The `self` keyword was used in a static method. Example of erroneous code:
834
835 ```compile_fail
836 struct Foo;
837
838 impl Foo {
839     fn bar(self) {}
840
841     fn foo() {
842         self.bar(); // error: `self` is not available in a static method.
843     }
844 }
845 ```
846
847 Please check if the method's argument list should have contained `self`,
848 `&self`, or `&mut self` (in case you didn't want to create a static
849 method), and add it if so. Example:
850
851 ```
852 struct Foo;
853
854 impl Foo {
855     fn bar(self) {}
856
857     fn foo(self) {
858         self.bar(); // ok!
859     }
860 }
861 ```
862 "##,
863
864 E0425: r##"
865 An unresolved name was used. Example of erroneous codes:
866
867 ```compile_fail
868 something_that_doesnt_exist::foo;
869 // error: unresolved name `something_that_doesnt_exist::foo`
870
871 // or:
872
873 trait Foo {
874     fn bar() {
875         Self; // error: unresolved name `Self`
876     }
877 }
878
879 // or:
880
881 let x = unknown_variable;  // error: unresolved name `unknown_variable`
882 ```
883
884 Please verify that the name wasn't misspelled and ensure that the
885 identifier being referred to is valid for the given situation. Example:
886
887 ```
888 enum something_that_does_exist {
889     Foo,
890 }
891 ```
892
893 Or:
894
895 ```
896 mod something_that_does_exist {
897     pub static foo : i32 = 0i32;
898 }
899
900 something_that_does_exist::foo; // ok!
901 ```
902
903 Or:
904
905 ```
906 let unknown_variable = 12u32;
907 let x = unknown_variable; // ok!
908 ```
909 "##,
910
911 E0426: r##"
912 An undeclared label was used. Example of erroneous code:
913
914 ```compile_fail
915 loop {
916     break 'a; // error: use of undeclared label `'a`
917 }
918 ```
919
920 Please verify you spelt or declare the label correctly. Example:
921
922 ```
923 'a: loop {
924     break 'a; // ok!
925 }
926 ```
927 "##,
928
929 E0428: r##"
930 A type or module has been defined more than once. Example of erroneous
931 code:
932
933 ```compile_fail
934 struct Bar;
935 struct Bar; // error: duplicate definition of value `Bar`
936 ```
937
938 Please verify you didn't misspell the type/module's name or remove/rename the
939 duplicated one. Example:
940
941 ```
942 struct Bar;
943 struct Bar2; // ok!
944 ```
945 "##,
946
947 E0430: r##"
948 The `self` import appears more than once in the list. Erroneous code example:
949
950 ```compile_fail
951 use something::{self, self}; // error: `self` import can only appear once in
952                              //        the list
953 ```
954
955 Please verify you didn't misspell the import name or remove the duplicated
956 `self` import. Example:
957
958 ```ignore
959 use something::self; // ok!
960 ```
961 "##,
962
963 E0431: r##"
964 An invalid `self` import was made. Erroneous code example:
965
966 ```compile_fail
967 use {self}; // error: `self` import can only appear in an import list with a
968             //        non-empty prefix
969 ```
970
971 You cannot import the current module into itself, please remove this import
972 or verify you didn't misspell it.
973 "##,
974
975 E0432: r##"
976 An import was unresolved. Erroneous code example:
977
978 ```compile_fail
979 use something::Foo; // error: unresolved import `something::Foo`.
980 ```
981
982 Paths in `use` statements are relative to the crate root. To import items
983 relative to the current and parent modules, use the `self::` and `super::`
984 prefixes, respectively. Also verify that you didn't misspell the import
985 name and that the import exists in the module from where you tried to
986 import it. Example:
987
988 ```ignore
989 use self::something::Foo; // ok!
990
991 mod something {
992     pub struct Foo;
993 }
994 ```
995
996 Or, if you tried to use a module from an external crate, you may have missed
997 the `extern crate` declaration (which is usually placed in the crate root):
998
999 ```ignore
1000 extern crate homura; // Required to use the `homura` crate
1001
1002 use homura::Madoka;
1003 ```
1004 "##,
1005
1006 E0433: r##"
1007 Invalid import. Example of erroneous code:
1008
1009 ```compile_fail
1010 use something_which_doesnt_exist;
1011 // error: unresolved import `something_which_doesnt_exist`
1012 ```
1013
1014 Please verify you didn't misspell the import's name.
1015 "##,
1016
1017 E0434: r##"
1018 This error indicates that a variable usage inside an inner function is invalid
1019 because the variable comes from a dynamic environment. Inner functions do not
1020 have access to their containing environment.
1021
1022 Example of erroneous code:
1023
1024 ```compile_fail
1025 fn foo() {
1026     let y = 5;
1027     fn bar() -> u32 {
1028         y // error: can't capture dynamic environment in a fn item; use the
1029           //        || { ... } closure form instead.
1030     }
1031 }
1032 ```
1033
1034 Functions do not capture local variables. To fix this error, you can replace the
1035 function with a closure:
1036
1037 ```
1038 fn foo() {
1039     let y = 5;
1040     let bar = || {
1041         y
1042     };
1043 }
1044 ```
1045
1046 or replace the captured variable with a constant or a static item:
1047
1048 ```
1049 fn foo() {
1050     static mut X: u32 = 4;
1051     const Y: u32 = 5;
1052     fn bar() -> u32 {
1053         unsafe {
1054             X = 3;
1055         }
1056         Y
1057     }
1058 }
1059 ```
1060 "##,
1061
1062 E0435: r##"
1063 A non-constant value was used to initialise a constant. Example of erroneous
1064 code:
1065
1066 ```compile_fail
1067 let foo = 42u32;
1068 const FOO : u32 = foo; // error: attempt to use a non-constant value in a
1069                        //        constant
1070 ```
1071
1072 To fix this error, please replace the value with a constant. Example:
1073
1074 ```
1075 const FOO : u32 = 42u32; // ok!
1076 ```
1077
1078 Or:
1079
1080 ```
1081 const OTHER_FOO : u32 = 42u32;
1082 const FOO : u32 = OTHER_FOO; // ok!
1083 ```
1084 "##,
1085
1086 E0437: r##"
1087 Trait implementations can only implement associated types that are members of
1088 the trait in question. This error indicates that you attempted to implement
1089 an associated type whose name does not match the name of any associated type
1090 in the trait.
1091
1092 Here is an example that demonstrates the error:
1093
1094 ```compile_fail
1095 trait Foo {}
1096
1097 impl Foo for i32 {
1098     type Bar = bool;
1099 }
1100 ```
1101
1102 The solution to this problem is to remove the extraneous associated type:
1103
1104 ```
1105 trait Foo {}
1106
1107 impl Foo for i32 {}
1108 ```
1109 "##,
1110
1111 E0438: r##"
1112 Trait implementations can only implement associated constants that are
1113 members of the trait in question. This error indicates that you
1114 attempted to implement an associated constant whose name does not
1115 match the name of any associated constant in the trait.
1116
1117 Here is an example that demonstrates the error:
1118
1119 ```compile_fail
1120 #![feature(associated_consts)]
1121
1122 trait Foo {}
1123
1124 impl Foo for i32 {
1125     const BAR: bool = true;
1126 }
1127 ```
1128
1129 The solution to this problem is to remove the extraneous associated constant:
1130
1131 ```
1132 trait Foo {}
1133
1134 impl Foo for i32 {}
1135 ```
1136 "##
1137
1138 }
1139
1140 register_diagnostics! {
1141 //  E0153, unused error code
1142 //  E0157, unused error code
1143     E0254, // import conflicts with imported crate in this module
1144 //  E0257,
1145 //  E0258,
1146     E0402, // cannot use an outer type parameter in this context
1147     E0406, // undeclared associated type
1148     E0408, // variable from pattern #1 is not bound in pattern #
1149     E0409, // variable is bound with different mode in pattern # than in
1150            // pattern #1
1151     E0410, // variable from pattern is not bound in pattern 1
1152     E0418, // is not an enum variant, struct or const
1153     E0420, // is not an associated const
1154     E0421, // unresolved associated const
1155     E0427, // cannot use `ref` binding mode with ...
1156     E0429, // `self` imports are only allowed within a { } list
1157 }