1 #![allow(non_snake_case)]
3 use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
5 // Error messages for EXXXX errors. Each message should start and end with a
6 // new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
7 // use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
8 register_long_diagnostics! {
11 Type parameter defaults can only use parameters that occur before them.
12 Erroneous code example:
15 struct Foo<T=U, U=()> {
19 // error: type parameters with a default cannot use forward declared
23 Since type parameters are evaluated in-order, you may be able to fix this issue
27 struct Foo<U=(), T=U> {
33 Please also verify that this wasn't because of a name-clash and rename the type
38 #### Note: this error code is no longer emitted by the compiler.
40 Imports (`use` statements) are not allowed after non-item statements, such as
41 variable declarations and expression statements.
43 Here is an example that demonstrates the error:
47 // Variable declaration before import
54 The solution is to declare the imports at the top of the block, function, or
57 Here is the previous example again, with the correct order:
67 See the Declaration Statements section of the reference for more information
68 about what constitutes an Item declaration and what does not:
70 https://doc.rust-lang.org/reference.html#statements
74 #### Note: this error code is no longer emitted by the compiler.
76 Two items of the same name cannot be imported without rebinding one of the
77 items under a new local name.
79 An example of this error:
83 use bar::*; // error, do `use foo::baz as quux` instead on the previous line
98 Two items of the same name cannot be imported without rebinding one of the
99 items under a new local name.
101 Erroneous code example:
103 ```compile_fail,E0252
105 use bar::baz; // error, do `use bar::baz as quux` instead
118 You can use aliases in order to fix this error. Example:
121 use foo::baz as foo_baz;
135 Or you can reference the item with its parent:
141 let x = foo::baz; // ok!
155 Attempt was made to import an unimportable value. This can happen when trying
156 to import a method from a trait.
158 Erroneous code example:
160 ```compile_fail,E0253
167 use foo::MyTrait::do_something;
168 // error: `do_something` is not directly importable
173 It's invalid to directly import methods belonging to a trait or concrete type.
177 Attempt was made to import an item whereas an extern crate with this name has
178 already been imported.
180 Erroneous code example:
182 ```compile_fail,E0254
191 use foo::core; // error: an extern crate named `core` has already
192 // been imported in this module
197 To fix this issue, you have to rename at least one of the two imports.
201 extern crate core as libcore; // ok!
216 You can't import a value whose name is the same as another value defined in the
219 Erroneous code example:
221 ```compile_fail,E0255
222 use bar::foo; // error: an item named `foo` is already in scope
233 You can use aliases in order to fix this error. Example:
236 use bar::foo as bar_foo; // ok!
247 Or you can reference the item with its parent:
257 bar::foo(); // we get the item by referring to its parent
263 #### Note: this error code is no longer emitted by the compiler.
265 You can't import a type or module when the name of the item being imported is
266 the same as another type or submodule defined in the module.
268 An example of this error:
271 use foo::Bar; // error
284 The name chosen for an external crate conflicts with another external crate
285 that has been imported into the current module.
287 Erroneous code example:
289 ```compile_fail,E0259
291 extern crate std as core;
296 The solution is to choose a different name that doesn't conflict with any
297 external crate imported into the current module.
303 extern crate std as other_name;
310 The name for an item declaration conflicts with an external crate's name.
312 Erroneous code example:
314 ```compile_fail,E0260
322 There are two possible solutions:
324 Solution #1: Rename the item.
332 Solution #2: Import the crate with a different name.
335 extern crate core as xyz;
340 See the Declaration Statements section of the reference for more information
341 about what constitutes an Item declaration and what does not:
343 https://doc.rust-lang.org/reference.html#statements
347 Private items cannot be publicly re-exported. This error indicates that you
348 attempted to `pub use` a type or value that was not itself public.
350 Erroneous code example:
362 The solution to this problem is to ensure that the items that you are
363 re-exporting are themselves marked with `pub`:
367 pub const X: u32 = 1;
375 See the 'Use Declarations' section of the reference for more information on
378 https://doc.rust-lang.org/reference.html#use-declarations
382 Private modules cannot be publicly re-exported. This error indicates that you
383 attempted to `pub use` a module that was not itself public.
385 Erroneous code example:
387 ```compile_fail,E0365
389 pub const X: u32 = 1;
397 The solution to this problem is to ensure that the module that you are
398 re-exporting is itself marked with `pub`:
402 pub const X: u32 = 1;
410 See the 'Use Declarations' section of the reference for more information
413 https://doc.rust-lang.org/reference.html#use-declarations
417 Inner items do not inherit type or const parameters from the functions
418 they are embedded in.
420 Erroneous code example:
422 ```compile_fail,E0401
424 fn bar(y: T) { // T is defined in the "outer" function
433 ```compile_fail,E0401
435 type MaybeT = Option<T>;
442 ```compile_fail,E0401
451 Items inside functions are basically just like top-level items, except
452 that they can only be used from the function they are in.
454 There are a couple of solutions for this.
456 If the item is a function, you may use a closure:
460 let bar = |y: T| { // explicit type annotation may not be necessary
467 For a generic item, you can copy over the parameters:
480 type MaybeT<T> = Option<T>;
484 Be sure to copy over any bounds as well:
487 fn foo<T: Copy>(x: T) {
488 fn bar<T: Copy>(y: T) {
496 fn foo<T: Copy>(x: T) {
497 struct Foo<T: Copy> {
503 This may require additional type hints in the function body.
505 In case the item is a function inside an `impl`, defining a private helper
506 function might be easier:
511 pub fn foo(&self, x: T) {
515 fn bar(&self, y: T) {
521 For default impls in traits, the private helper solution won't work, however
522 closures or copying the parameters should still work.
526 Some type parameters have the same name.
528 Erroneous code example:
530 ```compile_fail,E0403
531 fn foo<T, T>(s: T, u: T) {} // error: the name `T` is already used for a type
532 // parameter in this type parameter list
535 Please verify that none of the type parameters are misspelled, and rename any
536 clashing parameters. Example:
539 fn foo<T, Y>(s: T, u: Y) {} // ok!
544 You tried to use something which is not a trait in a trait position, such as
547 Erroneous code example:
549 ```compile_fail,E0404
553 impl Foo for Bar {} // error: `Foo` is not a trait
556 Another erroneous code example:
558 ```compile_fail,E0404
561 fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait
564 Please verify that you didn't misspell the trait's name or otherwise use the
565 wrong identifier. Example:
573 impl Foo for Bar { // ok!
574 // functions implementation
585 fn bar<T: Foo>(t: T) {} // ok!
591 The code refers to a trait that is not in scope.
593 Erroneous code example:
595 ```compile_fail,E0405
598 impl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope
601 Please verify that the name of the trait wasn't misspelled and ensure that it
602 was imported. Example:
605 # #[cfg(for_demonstration_only)]
607 use some_file::SomeTrait;
616 impl SomeTrait for Foo { // ok!
617 // implements functions
623 A definition of a method not in the implemented trait was given in a trait
626 Erroneous code example:
628 ```compile_fail,E0407
637 fn b() {} // error: method `b` is not a member of trait `Foo`
641 Please verify you didn't misspell the method name and you used the correct
642 trait. First example:
678 An "or" pattern was used where the variable bindings are not consistently bound
681 Erroneous code example:
683 ```compile_fail,E0408
685 Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is
686 // not bound in pattern #2
691 Here, `y` is bound to the contents of the `Some` and can be used within the
692 block corresponding to the match arm. However, in case `x` is `None`, we have
693 not specified what `y` is, and the block will use a nonexistent variable.
695 To fix this error, either split into multiple match arms:
700 Some(y) => { /* use y */ }
701 None => { /* ... */ }
705 or, bind the variable to a field of the same type in all sub-patterns of the
711 (0, y) | (y, 0) => { /* use y */}
716 In this example, if `x` matches the pattern `(0, _)`, the second field is set
717 to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
718 cases `y` is set to some value.
722 An "or" pattern was used where the variable bindings are not consistently bound
725 Erroneous code example:
727 ```compile_fail,E0409
730 (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
731 // different mode in pattern #2
732 // than in pattern #1
737 Here, `y` is bound by-value in one case and by-reference in the other.
739 To fix this error, just use the same mode in both cases.
740 Generally using `ref` or `ref mut` where not already used will fix this:
745 (0, ref y) | (ref y, 0) => { /* use y */}
750 Alternatively, split the pattern:
755 (y, 0) => { /* use y */ }
756 (0, ref y) => { /* use y */}
763 The `Self` keyword was used outside an impl, trait, or type definition.
765 Erroneous code example:
767 ```compile_fail,E0411
768 <Self>::foo; // error: use of `Self` outside of an impl, trait, or type
772 The `Self` keyword represents the current type, which explains why it can only
773 be used inside an impl, trait, or type definition. It gives access to the
774 associated items of a type:
782 fn bar() -> Self::Bar; // like this
786 However, be careful when two types have a common associated type:
797 trait Baz : Foo + Foo2 {
798 fn bar() -> Self::Bar;
799 // error: ambiguous associated type `Bar` in bounds of `Self`
803 This problem can be solved by specifying from which trait we want to use the
815 trait Baz : Foo + Foo2 {
816 fn bar() -> <Self as Foo>::Bar; // ok!
822 The type name used is not in scope.
824 Erroneous code examples:
826 ```compile_fail,E0412
827 impl Something {} // error: type name `Something` is not in scope
832 fn bar(N); // error: type name `N` is not in scope
837 fn foo(x: T) {} // type name `T` is not in scope
840 To fix this error, please verify you didn't misspell the type name, you did
841 declare it or imported it into the scope. Examples:
846 impl Something {} // ok!
853 fn bar(_: Self::N); // ok!
858 fn foo<T>(x: T) {} // ok!
861 Another case that causes this error is when a type is imported into a parent
862 module. To fix this, you can follow the suggestion and use File directly or
863 `use super::File;` which will import the types from the parent namespace. An
864 example that causes this error is below:
866 ```compile_fail,E0412
870 fn some_function(f: File) {}
881 // use std::fs::File;
884 # fn main() {} // don't insert it for us; that'll break imports
889 More than one function parameter have the same name.
891 Erroneous code example:
893 ```compile_fail,E0415
894 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
895 // once in this parameter list
898 Please verify you didn't misspell parameters' name. Example:
901 fn foo(f: i32, g: i32) {} // ok!
906 An identifier is bound more than once in a pattern.
908 Erroneous code example:
910 ```compile_fail,E0416
912 (x, x) => {} // error: identifier `x` is bound more than once in the
917 Please verify you didn't misspell identifiers' name. Example:
925 Or maybe did you mean to unify? Consider using a guard:
928 # let (A, B, C) = (1, 2, 3);
930 (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
931 (y, z, see) => { /* A and B unequal; do another thing */ }
937 You are trying to use an identifier that is either undefined or not a struct.
938 Erroneous code example:
940 ```compile_fail,E0422
942 let x = Foo { x: 1, y: 2 };
946 In this case, `Foo` is undefined, so it inherently isn't anything, and
947 definitely not a struct.
952 let x = foo { x: 1, y: 2 };
956 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
961 An identifier was used like a function name or a value was expected and the
962 identifier exists but it belongs to a different namespace.
964 For (an erroneous) example, here a `struct` variant name were used as a
967 ```compile_fail,E0423
968 struct Foo { a: bool };
971 // error: expected function, found `Foo`
972 // `Foo` is a struct name, but this expression uses it like a function name
975 Please verify you didn't misspell the name of what you actually wanted to use
979 fn Foo() -> u32 { 0 }
981 let f = Foo(); // ok!
984 It is common to forget the trailing `!` on macro invocations, which would also
987 ```compile_fail,E0423
989 // error: expected function, found macro `println`
990 // did you mean `println!(...)`? (notice the trailing `!`)
993 Another case where this error is emitted is when a value is expected, but
994 something else is found:
996 ```compile_fail,E0423
998 pub const I: i32 = 1;
1003 //~^ ERROR expected value, found module `a`
1004 // did you mean `a::I`?
1010 The `self` keyword was used in a static method.
1012 Erroneous code example:
1014 ```compile_fail,E0424
1021 self.bar(); // error: `self` is not available in a static method.
1026 Please check if the method's argument list should have contained `self`,
1027 `&self`, or `&mut self` (in case you didn't want to create a static
1028 method), and add it if so. Example:
1044 An unresolved name was used.
1046 Erroneous code examples:
1048 ```compile_fail,E0425
1049 something_that_doesnt_exist::foo;
1050 // error: unresolved name `something_that_doesnt_exist::foo`
1056 Self; // error: unresolved name `Self`
1062 let x = unknown_variable; // error: unresolved name `unknown_variable`
1065 Please verify that the name wasn't misspelled and ensure that the
1066 identifier being referred to is valid for the given situation. Example:
1069 enum something_that_does_exist {
1077 mod something_that_does_exist {
1078 pub static foo : i32 = 0i32;
1081 something_that_does_exist::foo; // ok!
1087 let unknown_variable = 12u32;
1088 let x = unknown_variable; // ok!
1091 If the item is not defined in the current module, it must be imported using a
1092 `use` statement, like so:
1095 # mod foo { pub fn bar() {} }
1102 If the item you are importing is not defined in some super-module of the
1103 current module, then it must also be declared as public (e.g., `pub fn`).
1107 An undeclared label was used.
1109 Erroneous code example:
1111 ```compile_fail,E0426
1113 break 'a; // error: use of undeclared label `'a`
1117 Please verify you spelt or declare the label correctly. Example:
1127 A type or module has been defined more than once.
1129 Erroneous code example:
1131 ```compile_fail,E0428
1133 struct Bar; // error: duplicate definition of value `Bar`
1136 Please verify you didn't misspell the type/module's name or remove/rename the
1137 duplicated one. Example:
1146 The `self` keyword cannot appear alone as the last segment in a `use`
1149 Erroneous code example:
1151 ```compile_fail,E0429
1152 use std::fmt::self; // error: `self` imports are only allowed within a { } list
1155 To use a namespace itself in addition to some of its members, `self` may appear
1156 as part of a brace-enclosed list of imports:
1159 use std::fmt::{self, Debug};
1162 If you only want to import the namespace, do so directly:
1170 The `self` import appears more than once in the list.
1172 Erroneous code example:
1174 ```compile_fail,E0430
1175 use something::{self, self}; // error: `self` import can only appear once in
1179 Please verify you didn't misspell the import name or remove the duplicated
1180 `self` import. Example:
1185 use something::{self}; // ok!
1191 An invalid `self` import was made.
1193 Erroneous code example:
1195 ```compile_fail,E0431
1196 use {self}; // error: `self` import can only appear in an import list with a
1200 You cannot import the current module into itself, please remove this import
1201 or verify you didn't misspell it.
1205 An import was unresolved.
1207 Erroneous code example:
1209 ```compile_fail,E0432
1210 use something::Foo; // error: unresolved import `something::Foo`.
1213 Paths in `use` statements are relative to the crate root. To import items
1214 relative to the current and parent modules, use the `self::` and `super::`
1215 prefixes, respectively. Also verify that you didn't misspell the import
1216 name and that the import exists in the module from where you tried to
1220 use self::something::Foo; // ok!
1228 Or, if you tried to use a module from an external crate, you may have missed
1229 the `extern crate` declaration (which is usually placed in the crate root):
1232 extern crate core; // Required to use the `core` crate
1240 An undeclared type or module was used.
1242 Erroneous code example:
1244 ```compile_fail,E0433
1245 let map = HashMap::new();
1246 // error: failed to resolve: use of undeclared type or module `HashMap`
1249 Please verify you didn't misspell the type/module's name or that you didn't
1250 forget to import it:
1254 use std::collections::HashMap; // HashMap has been imported.
1255 let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1260 This error indicates that a variable usage inside an inner function is invalid
1261 because the variable comes from a dynamic environment. Inner functions do not
1262 have access to their containing environment.
1264 Erroneous code example:
1266 ```compile_fail,E0434
1270 y // error: can't capture dynamic environment in a fn item; use the
1271 // || { ... } closure form instead.
1276 Functions do not capture local variables. To fix this error, you can replace the
1277 function with a closure:
1288 or replace the captured variable with a constant or a static item:
1292 static mut X: u32 = 4;
1305 A non-constant value was used in a constant expression.
1307 Erroneous code example:
1309 ```compile_fail,E0435
1311 let a: [u8; foo]; // error: attempt to use a non-constant value in a constant
1314 To fix this error, please replace the value with a constant. Example:
1317 let a: [u8; 42]; // ok!
1323 const FOO: usize = 42;
1324 let a: [u8; FOO]; // ok!
1329 Trait implementations can only implement associated types that are members of
1330 the trait in question. This error indicates that you attempted to implement
1331 an associated type whose name does not match the name of any associated type
1334 Erroneous code example:
1336 ```compile_fail,E0437
1344 The solution to this problem is to remove the extraneous associated type:
1354 Trait implementations can only implement associated constants that are
1355 members of the trait in question. This error indicates that you
1356 attempted to implement an associated constant whose name does not
1357 match the name of any associated constant in the trait.
1359 Erroneous code example:
1361 ```compile_fail,E0438
1365 const BAR: bool = true;
1369 The solution to this problem is to remove the extraneous associated constant:
1379 Macro import declarations were malformed.
1381 Erroneous code examples:
1383 ```compile_fail,E0466
1384 #[macro_use(a_macro(another_macro))] // error: invalid import declaration
1385 extern crate core as some_crate;
1387 #[macro_use(i_want = "some_macros")] // error: invalid import declaration
1388 extern crate core as another_crate;
1391 This is a syntax error at the level of attribute declarations. The proper
1392 syntax for macro imports is the following:
1394 ```ignore (cannot-doctest-multicrate-project)
1397 macro_rules! get_tacos {
1402 macro_rules! get_pimientos {
1407 #[macro_use(get_tacos, get_pimientos)] // It imports `get_tacos` and
1408 extern crate some_crate; // `get_pimientos` macros from some_crate
1411 If you would like to import all exported macros, write `macro_use` with no
1416 A non-root module attempts to import macros from another crate.
1418 Example of erroneous code:
1420 ```compile_fail,E0468
1422 #[macro_use(debug_assert)] // error: must be at crate root to import
1423 extern crate core; // macros from another crate
1424 fn run_macro() { debug_assert!(true); }
1428 Only `extern crate` imports at the crate root level are allowed to import
1431 Either move the macro import to crate root or do without the foreign macros.
1435 #[macro_use(debug_assert)]
1439 fn run_macro() { debug_assert!(true); }
1446 A macro listed for import was not found.
1448 Erroneous code example:
1450 ```compile_fail,E0469
1451 #[macro_use(drink, be_merry)] // error: imported macro not found
1459 Either the listed macro is not contained in the imported crate, or it is not
1460 exported from the given crate.
1462 This could be caused by a typo. Did you misspell the macro's name?
1464 Double-check the names of the macros listed for import, and that the crate
1465 in question exports them.
1467 A working version would be:
1469 ```ignore (cannot-doctest-multicrate-project)
1470 // In some_crate crate:
1477 macro_rules! drink {
1482 #[macro_use(eat, drink)]
1483 extern crate some_crate; //ok!
1488 A binding shadowed something it shouldn't.
1490 Erroneous code example:
1492 ```compile_fail,E0530
1493 static TEST: i32 = 0;
1495 let r: (i32, i32) = (0, 0);
1497 TEST => {} // error: match bindings cannot shadow statics
1501 To fix this error, just change the binding's name in order to avoid shadowing
1502 one of the following:
1505 * struct/enum variant
1513 static TEST: i32 = 0;
1515 let r: (i32, i32) = (0, 0);
1517 something => {} // ok!
1523 Pattern arm did not match expected kind.
1525 Erroneous code example:
1527 ```compile_fail,E0532
1533 fn print_on_failure(state: &State) {
1535 // error: expected unit struct/variant or constant, found tuple
1536 // variant `State::Failed`
1537 State::Failed => println!("Failed"),
1543 To fix this error, ensure the match arm kind is the same as the expression
1554 fn print_on_failure(state: &State) {
1556 State::Failed(ref msg) => println!("Failed with {}", msg),
1564 A private item was used outside its scope.
1566 Erroneous code example:
1568 ```compile_fail,E0603
1570 const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
1571 // can't use it outside of the
1572 // `SomeModule` module.
1575 println!("const value: {}", SomeModule::PRIVATE); // error: constant `PRIVATE`
1579 In order to fix this error, you need to make the item public by using the `pub`
1584 pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
1588 println!("const value: {}", SomeModule::PRIVATE); // ok!
1593 An item usage is ambiguous.
1595 Erroneous code example:
1597 ```compile_fail,E0659
1612 collider::foo(); // ERROR: `foo` is ambiguous
1616 This error generally appears when two items with the same name are imported into
1617 a module. Here, the `foo` functions are imported and reexported from the
1618 `collider` module and therefore, when we're using `collider::foo()`, both
1621 To solve this error, the best solution is generally to keep the path before the
1622 item when using it. Example:
1639 collider::moon::foo(); // ok!
1640 collider::earth::foo(); // ok!
1646 Const parameters cannot depend on type parameters.
1647 The following is therefore invalid:
1648 ```compile_fail,E0671
1649 #![feature(const_generics)]
1651 fn const_id<T, const N: T>() -> T { // error: const parameter
1652 // depends on type parameter
1660 register_diagnostics! {
1661 // E0153, unused error code
1662 // E0157, unused error code
1665 // E0402, // cannot use an outer type parameter in this context
1666 // E0406, merged into 420
1667 // E0410, merged into 408
1668 // E0413, merged into 530
1669 // E0414, merged into 530
1670 // E0417, merged into 532
1671 // E0418, merged into 532
1672 // E0419, merged into 531
1673 // E0420, merged into 532
1674 // E0421, merged into 531
1675 E0531, // unresolved pattern path kind `name`
1676 // E0427, merged into 530