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.
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.
11 #![allow(non_snake_case)]
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! {
19 Imports (`use` statements) are not allowed after non-item statements, such as
20 variable declarations and expression statements.
22 Here is an example that demonstrates the error:
26 // Variable declaration before import
33 The solution is to declare the imports at the top of the block, function, or
36 Here is the previous example again, with the correct order:
46 See the Declaration Statements section of the reference for more information
47 about what constitutes an Item declaration and what does not:
49 https://doc.rust-lang.org/reference.html#statements
53 Two items of the same name cannot be imported without rebinding one of the
54 items under a new local name.
56 An example of this error:
60 use bar::*; // error, do `use foo::baz as quux` instead on the previous line
75 Two items of the same name cannot be imported without rebinding one of the
76 items under a new local name.
78 An example of this error:
82 use bar::baz; // error, do `use bar::baz as quux` instead
97 Attempt was made to import an unimportable value. This can happen when
98 trying to import a method from a trait. An example of this error:
106 use foo::MyTrait::do_something;
109 It's invalid to directly import methods belonging to a trait or concrete type.
113 You can't import a value whose name is the same as another value defined in the
116 An example of this error:
119 use bar::foo; // error, do `use bar::foo as baz` instead
132 You can't import a type or module when the name of the item being imported is
133 the same as another type or submodule defined in the module.
135 An example of this error:
138 use foo::Bar; // error
151 The name chosen for an external crate conflicts with another external crate that
152 has been imported into the current module.
158 extern crate crate_a as a;
161 The solution is to choose a different name that doesn't conflict with any
162 external crate imported into the current module.
168 extern crate crate_a as other_name;
173 The name for an item declaration conflicts with an external crate's name.
183 There are two possible solutions:
185 Solution #1: Rename the item.
193 Solution #2: Import the crate with a different name.
196 extern crate abc as xyz;
201 See the Declaration Statements section of the reference for more information
202 about what constitutes an Item declaration and what does not:
204 https://doc.rust-lang.org/reference.html#statements
208 User-defined types or type parameters cannot shadow the primitive types.
209 This error indicates you tried to define a type, struct or enum with the same
210 name as an existing primitive type.
212 See the Types section of the reference for more information about the primitive
215 https://doc.rust-lang.org/reference.html#types
219 Private items cannot be publicly re-exported. This error indicates that
220 you attempted to `pub use` a type or value that was not itself public.
222 Here is an example that demonstrates the error:
231 The solution to this problem is to ensure that the items that you are
232 re-exporting are themselves marked with `pub`:
236 pub const X: u32 = 1;
241 See the 'Use Declarations' section of the reference for more information
244 https://doc.rust-lang.org/reference.html#use-declarations
248 Private modules cannot be publicly re-exported. This error indicates
249 that you attempted to `pub use` a module that was not itself public.
251 Here is an example that demonstrates the error:
255 pub const X: u32 = 1;
260 The solution to this problem is to ensure that the module that you are
261 re-exporting is itself marked with `pub`:
265 pub const X: u32 = 1;
270 See the 'Use Declarations' section of the reference for more information
273 https://doc.rust-lang.org/reference.html#use-declarations
277 Inner items do not inherit type parameters from the functions they are
278 embedded in. For example, this will not compile:
282 fn bar(y: T) { // T is defined in the "outer" function
293 type MaybeT = Option<T>;
309 Items inside functions are basically just like top-level items, except
310 that they can only be used from the function they are in.
312 There are a couple of solutions for this.
314 If the item is a function, you may use a closure:
318 let bar = |y: T| { // explicit type annotation may not be necessary
325 For a generic item, you can copy over the parameters:
338 type MaybeT<T> = Option<T>;
342 Be sure to copy over any bounds as well:
345 fn foo<T: Copy>(x: T) {
346 fn bar<T: Copy>(y: T) {
354 fn foo<T: Copy>(x: T) {
355 struct Foo<T: Copy> {
361 This may require additional type hints in the function body.
363 In case the item is a function inside an `impl`, defining a private helper
364 function might be easier:
368 pub fn foo(&self, x: T) {
371 fn bar(&self, y: T) {
377 For default impls in traits, the private helper solution won't work, however
378 closures or copying the parameters should still work.
382 Some type parameters have the same name. Example of erroneous code:
385 fn foo<T, T>(s: T, u: T) {} // error: the name `T` is already used for a type
386 // parameter in this type parameter list
389 Please verify that none of the type parameterss are misspelled, and rename any
390 clashing parameters. Example:
393 fn foo<T, Y>(s: T, u: Y) {} // ok!
398 You tried to implement something which was not a trait on an object. Example of
405 impl Foo for Bar {} // error: `Foo` is not a trait
408 Please verify that you didn't misspell the trait's name or otherwise use the
409 wrong identifier. Example:
417 impl Foo for Bar { // ok!
418 // functions implementation
424 An unknown trait was implemented. Example of erroneous code:
429 impl SomeTrait for Foo {} // error: use of undeclared trait name `SomeTrait`
432 Please verify that the name of the trait wasn't misspelled and ensure that it
433 was imported. Example:
437 use some_file::SomeTrait;
446 impl SomeTrait for Foo { // ok!
447 // implements functions
453 A definition of a method not in the implemented trait was given in a trait
454 implementation. Example of erroneous code:
465 fn b() {} // error: method `b` is not a member of trait `Foo`
469 Please verify you didn't misspell the method name and you used the correct
470 trait. First example:
506 The `Self` keyword was used outside an impl or a trait. Erroneous
510 <Self>::foo; // error: use of `Self` outside of an impl or trait
513 The `Self` keyword represents the current type, which explains why it
514 can only be used inside an impl or a trait. It gives access to the
515 associated items of a type:
523 fn bar() -> Self::Bar; // like this
527 However, be careful when two types has a common associated type:
538 trait Baz : Foo + Foo2 {
539 fn bar() -> Self::Bar;
540 // error: ambiguous associated type `Bar` in bounds of `Self`
544 This problem can be solved by specifying from which trait we want
545 to use the `Bar` type:
548 trait Baz : Foo + Foo2 {
549 fn bar() -> <Self as Foo>::Bar; // ok!
555 An undeclared type name was used. Example of erroneous codes:
558 impl Something {} // error: use of undeclared type name `Something`
561 fn bar(N); // error: use of undeclared type name `N`
564 fn foo(x: T) {} // error: use of undeclared type name `T`
567 To fix this error, please verify you didn't misspell the type name,
568 you did declare it or imported it into the scope. Examples:
573 impl Something {} // ok!
578 fn bar(Self::N); // ok!
581 fn foo<T>(x: T) {} // ok!
586 A declaration shadows an enum variant or unit-like struct in scope.
587 Example of erroneous code:
592 let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
593 // unit-like struct in scope
597 To fix this error, rename the variable such that it doesn't shadow any enum
598 variable or structure in scope. Example:
603 let foo = 12i32; // ok!
611 let Foo = 12i32; // ok!
614 The goal here is to avoid a conflict of names.
618 More than one function parameter have the same name. Example of erroneous
622 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
623 // once in this parameter list
626 Please verify you didn't misspell parameters' name. Example:
629 fn foo(f: i32, g: i32) {} // ok!
634 An identifier is bound more than once in a pattern. Example of erroneous
639 (x, x) => {} // error: identifier `x` is bound more than once in the
644 Please verify you didn't misspell identifiers' name. Example:
652 Or maybe did you mean to unify? Consider using a guard:
656 (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
657 (y, z, see) => { /* A and B unequal; do another thing */ }
663 A static variable was referenced in a pattern. Example of erroneous code:
666 static FOO : i32 = 0;
669 FOO => {} // error: static variables cannot be referenced in a
670 // pattern, use a `const` instead
675 The compiler needs to know the value of the pattern at compile time;
676 compile-time patterns can defined via const or enum items. Please verify
677 that the identifier is spelled correctly, and if so, use a const instead
678 of static to define it. Example:
691 An unknown enum variant, struct or const was used. Example of
696 Something::Foo => {} // error: unresolved enum variant, struct
701 Please verify you didn't misspell it and the enum variant, struct or const has
702 been declared and imported into scope. Example:
710 match Something::NotFoo {
711 Something::Foo => {} // ok!
718 You are trying to use an identifier that is either undefined or not a
719 struct. For instance:
722 let x = Foo { x: 1, y: 2 };
726 In this case, `Foo` is undefined, so it inherently isn't anything, and
727 definitely not a struct.
732 let x = foo { x: 1, y: 2 };
736 In this case, `foo` is defined, but is not a struct, so Rust can't use
741 A `struct` variant name was used like a function name. Example of
745 struct Foo { a: bool};
748 // error: `Foo` is a struct variant name, but this expression uses
749 // it like a function name
752 Please verify you didn't misspell the name of what you actually wanted
753 to use here. Example:
756 fn Foo() -> u32 { 0 }
758 let f = Foo(); // ok!
763 The `self` keyword was used in a static method. Example of erroneous code:
772 self.bar(); // error: `self` is not available in a static method.
777 Please check if the method's argument list should have contained `self`,
778 `&self`, or `&mut self` (in case you didn't want to create a static
779 method), and add it if so. Example:
795 An unresolved name was used. Example of erroneous codes:
798 something_that_doesnt_exist::foo;
799 // error: unresolved name `something_that_doesnt_exist::foo`
804 Self; // error: unresolved name `Self`
809 let x = unknown_variable; // error: unresolved name `unknown_variable`
812 Please verify that the name wasn't misspelled and ensure that the
813 identifier being referred to is valid for the given situation. Example:
816 enum something_that_does_exist {
821 mod something_that_does_exist {
822 pub static foo : i32 = 0i32;
825 something_that_does_exist::foo; // ok!
828 let unknown_variable = 12u32;
829 let x = unknown_variable; // ok!
834 An undeclared label was used. Example of erroneous code:
838 break 'a; // error: use of undeclared label `'a`
842 Please verify you spelt or declare the label correctly. Example:
852 A type or module has been defined more than once. Example of erroneous
857 struct Bar; // error: duplicate definition of value `Bar`
860 Please verify you didn't misspell the type/module's name or remove/rename the
861 duplicated one. Example:
870 The `self` import appears more than once in the list. Erroneous code example:
873 use something::{self, self}; // error: `self` import can only appear once in
877 Please verify you didn't misspell the import name or remove the duplicated
878 `self` import. Example:
881 use something::self; // ok!
886 `self` import was made. Erroneous code example:
889 use {self}; // error: `self` import can only appear in an import list with a
893 You cannot import the current module into itself, please remove this import
894 or verify you didn't misspell it.
898 An import was unresolved. Erroneous code example:
901 use something::Foo; // error: unresolved import `something::Foo`.
904 Please verify you didn't misspell the import name or the import does exist
905 in the module from where you tried to import it. Example:
908 use something::Foo; // ok!
915 Or, if you tried to use a module from an external crate, you may have missed
916 the `extern crate` declaration:
919 extern crate homura; // Required to use the `homura` crate
926 Invalid import. Example of erroneous code:
929 use something_which_doesnt_exist;
930 // error: unresolved import `something_which_doesnt_exist`
933 Please verify you didn't misspell the import's name.
937 A non-constant value was used to initialise a constant. Example of erroneous
942 const FOO : u32 = foo; // error: attempt to use a non-constant value in a
946 To fix this error, please replace the value with a constant. Example:
949 const FOO : u32 = 42u32; // ok!
952 const OTHER_FOO : u32 = 42u32;
953 const FOO : u32 = OTHER_FOO; // ok!
958 Trait implementations can only implement associated types that are members of
959 the trait in question. This error indicates that you attempted to implement
960 an associated type whose name does not match the name of any associated type
963 Here is an example that demonstrates the error:
973 The solution to this problem is to remove the extraneous associated type:
983 Trait implementations can only implement associated constants that are
984 members of the trait in question. This error indicates that you
985 attempted to implement an associated constant whose name does not
986 match the name of any associated constant in the trait.
988 Here is an example that demonstrates the error:
991 #![feature(associated_consts)]
996 const BAR: bool = true;
1000 The solution to this problem is to remove the extraneous associated constant:
1011 register_diagnostics! {
1012 // E0153, unused error code
1013 // E0157, unused error code
1014 E0254, // import conflicts with imported crate in this module
1017 E0402, // cannot use an outer type parameter in this context
1018 E0406, // undeclared associated type
1019 E0408, // variable from pattern #1 is not bound in pattern #
1020 E0409, // variable is bound with different mode in pattern # than in
1022 E0410, // variable from pattern is not bound in pattern 1
1023 E0414, // only irrefutable patterns allowed here
1024 E0418, // is not an enum variant, struct or const
1025 E0420, // is not an associated const
1026 E0421, // unresolved associated const
1027 E0427, // cannot use `ref` binding mode with ...
1028 E0429, // `self` imports are only allowed within a { } list
1029 E0434, // can't capture dynamic environment in a fn item