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 trying
98 to import a method from a trait. An example of this error:
107 use foo::MyTrait::do_something;
110 It's invalid to directly import methods belonging to a trait or concrete type.
114 You can't import a value whose name is the same as another value defined in the
117 An example of this error:
120 use bar::foo; // error, do `use bar::foo as baz` instead
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.
136 An example of this error:
139 use foo::Bar; // error
152 The name chosen for an external crate conflicts with another external crate
153 that has been imported into the current module.
155 Erroneous code example:
159 extern crate crate_a as a;
162 The solution is to choose a different name that doesn't conflict with any
163 external crate imported into the current module.
169 extern crate crate_a as other_name;
174 The name for an item declaration conflicts with an external crate's name.
184 There are two possible solutions:
186 Solution #1: Rename the item.
194 Solution #2: Import the crate with a different name.
197 extern crate abc as xyz;
202 See the Declaration Statements section of the reference for more information
203 about what constitutes an Item declaration and what does not:
205 https://doc.rust-lang.org/reference.html#statements
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.
212 Here is an example that demonstrates the error:
222 The solution to this problem is to ensure that the items that you are
223 re-exporting are themselves marked with `pub`:
227 pub const X: u32 = 1;
233 See the 'Use Declarations' section of the reference for more information on
236 https://doc.rust-lang.org/reference.html#use-declarations
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.
243 Here is an example that demonstrates the error:
247 pub const X: u32 = 1;
253 The solution to this problem is to ensure that the module that you are
254 re-exporting is itself marked with `pub`:
258 pub const X: u32 = 1;
264 See the 'Use Declarations' section of the reference for more information
267 https://doc.rust-lang.org/reference.html#use-declarations
271 Inner items do not inherit type parameters from the functions they are embedded
272 in. For example, this will not compile:
276 fn bar(y: T) { // T is defined in the "outer" function
287 type MaybeT = Option<T>;
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.
306 There are a couple of solutions for this.
308 If the item is a function, you may use a closure:
312 let bar = |y: T| { // explicit type annotation may not be necessary
319 For a generic item, you can copy over the parameters:
332 type MaybeT<T> = Option<T>;
336 Be sure to copy over any bounds as well:
339 fn foo<T: Copy>(x: T) {
340 fn bar<T: Copy>(y: T) {
348 fn foo<T: Copy>(x: T) {
349 struct Foo<T: Copy> {
355 This may require additional type hints in the function body.
357 In case the item is a function inside an `impl`, defining a private helper
358 function might be easier:
362 pub fn foo(&self, x: T) {
366 fn bar(&self, y: T) {
372 For default impls in traits, the private helper solution won't work, however
373 closures or copying the parameters should still work.
377 Some type parameters have the same name. Example of erroneous code:
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
384 Please verify that none of the type parameterss are misspelled, and rename any
385 clashing parameters. Example:
388 fn foo<T, Y>(s: T, u: Y) {} // ok!
393 You tried to implement something which was not a trait on an object. Example of
400 impl Foo for Bar {} // error: `Foo` is not a trait
403 Please verify that you didn't misspell the trait's name or otherwise use the
404 wrong identifier. Example:
412 impl Foo for Bar { // ok!
413 // functions implementation
419 The code refers to a trait that is not in scope. Example of erroneous code:
424 impl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope
427 Please verify that the name of the trait wasn't misspelled and ensure that it
428 was imported. Example:
432 use some_file::SomeTrait;
441 impl SomeTrait for Foo { // ok!
442 // implements functions
448 A definition of a method not in the implemented trait was given in a trait
449 implementation. Example of erroneous code:
460 fn b() {} // error: method `b` is not a member of trait `Foo`
464 Please verify you didn't misspell the method name and you used the correct
465 trait. First example:
501 The `Self` keyword was used outside an impl or a trait. Erroneous code example:
504 <Self>::foo; // error: use of `Self` outside of an impl or trait
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
517 fn bar() -> Self::Bar; // like this
521 However, be careful when two types have a common associated type:
532 trait Baz : Foo + Foo2 {
533 fn bar() -> Self::Bar;
534 // error: ambiguous associated type `Bar` in bounds of `Self`
538 This problem can be solved by specifying from which trait we want to use the
550 trait Baz : Foo + Foo2 {
551 fn bar() -> <Self as Foo>::Bar; // ok!
557 The type name used is not in scope. Example of erroneous codes:
560 impl Something {} // error: type name `Something` is not in scope
565 fn bar(N); // error: type name `N` is not in scope
570 fn foo(x: T) {} // type name `T` is not in scope
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:
579 impl Something {} // ok!
586 fn bar(Self::N); // ok!
591 fn foo<T>(x: T) {} // ok!
596 A declaration shadows an enum variant or unit-like struct in scope. Example of
602 let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
603 // unit-like struct in scope
606 To fix this error, rename the variable such that it doesn't shadow any enum
607 variable or structure in scope. Example:
612 let foo = 12i32; // ok!
620 let Foo = 12i32; // ok!
623 The goal here is to avoid a conflict of names.
627 More than one function parameter have the same name. Example of erroneous code:
630 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
631 // once in this parameter list
634 Please verify you didn't misspell parameters' name. Example:
637 fn foo(f: i32, g: i32) {} // ok!
642 An identifier is bound more than once in a pattern. Example of erroneous code:
646 (x, x) => {} // error: identifier `x` is bound more than once in the
651 Please verify you didn't misspell identifiers' name. Example:
659 Or maybe did you mean to unify? Consider using a guard:
663 (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
664 (y, z, see) => { /* A and B unequal; do another thing */ }
670 A static variable was referenced in a pattern. Example of erroneous code:
673 static FOO : i32 = 0;
676 FOO => {} // error: static variables cannot be referenced in a
677 // pattern, use a `const` instead
682 The compiler needs to know the value of the pattern at compile time;
683 compile-time patterns can defined via const or enum items. Please verify
684 that the identifier is spelled correctly, and if so, use a const instead
685 of static to define it. Example:
698 An unknown enum variant, struct or const was used. Example of erroneous code:
702 Something::Foo => {} // error: unresolved enum variant, struct
707 Please verify you didn't misspell it and the enum variant, struct or const has
708 been declared and imported into scope. Example:
716 match Something::NotFoo {
717 Something::Foo => {} // ok!
724 You are trying to use an identifier that is either undefined or not a struct.
729 let x = Foo { x: 1, y: 2 };
733 In this case, `Foo` is undefined, so it inherently isn't anything, and
734 definitely not a struct.
739 let x = foo { x: 1, y: 2 };
743 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
748 A `struct` variant name was used like a function name. Example of erroneous
752 struct Foo { a: bool};
755 // error: `Foo` is a struct variant name, but this expression uses
756 // it like a function name
759 Please verify you didn't misspell the name of what you actually wanted to use
763 fn Foo() -> u32 { 0 }
765 let f = Foo(); // ok!
770 The `self` keyword was used in a static method. Example of erroneous code:
779 self.bar(); // error: `self` is not available in a static method.
784 Please check if the method's argument list should have contained `self`,
785 `&self`, or `&mut self` (in case you didn't want to create a static
786 method), and add it if so. Example:
802 An unresolved name was used. Example of erroneous codes:
805 something_that_doesnt_exist::foo;
806 // error: unresolved name `something_that_doesnt_exist::foo`
812 Self; // error: unresolved name `Self`
818 let x = unknown_variable; // error: unresolved name `unknown_variable`
821 Please verify that the name wasn't misspelled and ensure that the
822 identifier being referred to is valid for the given situation. Example:
825 enum something_that_does_exist {
833 mod something_that_does_exist {
834 pub static foo : i32 = 0i32;
837 something_that_does_exist::foo; // ok!
843 let unknown_variable = 12u32;
844 let x = unknown_variable; // ok!
849 An undeclared label was used. Example of erroneous code:
853 break 'a; // error: use of undeclared label `'a`
857 Please verify you spelt or declare the label correctly. Example:
867 A type or module has been defined more than once. Example of erroneous
872 struct Bar; // error: duplicate definition of value `Bar`
875 Please verify you didn't misspell the type/module's name or remove/rename the
876 duplicated one. Example:
885 The `self` import appears more than once in the list. Erroneous code example:
888 use something::{self, self}; // error: `self` import can only appear once in
892 Please verify you didn't misspell the import name or remove the duplicated
893 `self` import. Example:
896 use something::self; // ok!
901 An invalid `self` import was made. Erroneous code example:
904 use {self}; // error: `self` import can only appear in an import list with a
908 You cannot import the current module into itself, please remove this import
909 or verify you didn't misspell it.
913 An import was unresolved. Erroneous code example:
916 use something::Foo; // error: unresolved import `something::Foo`.
919 Please verify you didn't misspell the import name or the import does exist
920 in the module from where you tried to import it. Example:
923 use something::Foo; // ok!
930 Or, if you tried to use a module from an external crate, you may have missed
931 the `extern crate` declaration:
934 extern crate homura; // Required to use the `homura` crate
941 Invalid import. Example of erroneous code:
944 use something_which_doesnt_exist;
945 // error: unresolved import `something_which_doesnt_exist`
948 Please verify you didn't misspell the import's name.
952 A non-constant value was used to initialise a constant. Example of erroneous
957 const FOO : u32 = foo; // error: attempt to use a non-constant value in a
961 To fix this error, please replace the value with a constant. Example:
964 const FOO : u32 = 42u32; // ok!
970 const OTHER_FOO : u32 = 42u32;
971 const FOO : u32 = OTHER_FOO; // ok!
976 Trait implementations can only implement associated types that are members of
977 the trait in question. This error indicates that you attempted to implement
978 an associated type whose name does not match the name of any associated type
981 Here is an example that demonstrates the error:
991 The solution to this problem is to remove the extraneous associated type:
1001 Trait implementations can only implement associated constants that are
1002 members of the trait in question. This error indicates that you
1003 attempted to implement an associated constant whose name does not
1004 match the name of any associated constant in the trait.
1006 Here is an example that demonstrates the error:
1009 #![feature(associated_consts)]
1014 const BAR: bool = true;
1018 The solution to this problem is to remove the extraneous associated constant:
1029 register_diagnostics
! {
1030 // E0153, unused error code
1031 // E0157, unused error code
1032 E0254
, // import conflicts with imported crate in this module
1035 E0402
, // cannot use an outer type parameter in this context
1036 E0406
, // undeclared associated type
1037 E0408
, // variable from pattern #1 is not bound in pattern #
1038 E0409
, // variable is bound with different mode in pattern # than in
1040 E0410
, // variable from pattern is not bound in pattern 1
1041 E0414
, // only irrefutable patterns allowed here
1042 E0418
, // is not an enum variant, struct or const
1043 E0420
, // is not an associated const
1044 E0421
, // unresolved associated const
1045 E0427
, // cannot use `ref` binding mode with ...
1046 E0429
, // `self` imports are only allowed within a { } list
1047 E0434
, // can't capture dynamic environment in a fn item