1 // Error messages for EXXXX errors. Each message should start and end with a
2 // new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
3 // use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
4 syntax::register_diagnostics! {
7 Type parameter defaults can only use parameters that occur before them.
8 Erroneous code example:
11 struct Foo<T = U, U = ()> {
15 // error: type parameters with a default cannot use forward declared
19 Since type parameters are evaluated in-order, you may be able to fix this issue
23 struct Foo<U = (), T = U> {
29 Please also verify that this wasn't because of a name-clash and rename the type
34 #### Note: this error code is no longer emitted by the compiler.
36 Imports (`use` statements) are not allowed after non-item statements, such as
37 variable declarations and expression statements.
39 Here is an example that demonstrates the error:
43 // Variable declaration before import
50 The solution is to declare the imports at the top of the block, function, or
53 Here is the previous example again, with the correct order:
63 See the Declaration Statements section of the reference for more information
64 about what constitutes an Item declaration and what does not:
66 https://doc.rust-lang.org/reference.html#statements
70 #### Note: this error code is no longer emitted by the compiler.
72 Two items of the same name cannot be imported without rebinding one of the
73 items under a new local name.
75 An example of this error:
79 use bar::*; // error, do `use foo::baz as quux` instead on the previous line
94 Two items of the same name cannot be imported without rebinding one of the
95 items under a new local name.
97 Erroneous code example:
101 use bar::baz; // error, do `use bar::baz as quux` instead
114 You can use aliases in order to fix this error. Example:
117 use foo::baz as foo_baz;
131 Or you can reference the item with its parent:
137 let x = foo::baz; // ok!
151 Attempt was made to import an unimportable value. This can happen when trying
152 to import a method from a trait.
154 Erroneous code example:
156 ```compile_fail,E0253
163 use foo::MyTrait::do_something;
164 // error: `do_something` is not directly importable
169 It's invalid to directly import methods belonging to a trait or concrete type.
173 Attempt was made to import an item whereas an extern crate with this name has
174 already been imported.
176 Erroneous code example:
178 ```compile_fail,E0254
187 use foo::core; // error: an extern crate named `core` has already
188 // been imported in this module
193 To fix this issue, you have to rename at least one of the two imports.
197 extern crate core as libcore; // ok!
212 You can't import a value whose name is the same as another value defined in the
215 Erroneous code example:
217 ```compile_fail,E0255
218 use bar::foo; // error: an item named `foo` is already in scope
229 You can use aliases in order to fix this error. Example:
232 use bar::foo as bar_foo; // ok!
243 Or you can reference the item with its parent:
253 bar::foo(); // we get the item by referring to its parent
259 #### Note: this error code is no longer emitted by the compiler.
261 You can't import a type or module when the name of the item being imported is
262 the same as another type or submodule defined in the module.
264 An example of this error:
267 use foo::Bar; // error
280 The name chosen for an external crate conflicts with another external crate
281 that has been imported into the current module.
283 Erroneous code example:
285 ```compile_fail,E0259
287 extern crate std as core;
292 The solution is to choose a different name that doesn't conflict with any
293 external crate imported into the current module.
299 extern crate std as other_name;
306 The name for an item declaration conflicts with an external crate's name.
308 Erroneous code example:
310 ```compile_fail,E0260
318 There are two possible solutions:
320 Solution #1: Rename the item.
328 Solution #2: Import the crate with a different name.
331 extern crate core as xyz;
336 See the Declaration Statements section of the reference for more information
337 about what constitutes an Item declaration and what does not:
339 https://doc.rust-lang.org/reference.html#statements
343 Private items cannot be publicly re-exported. This error indicates that you
344 attempted to `pub use` a type or value that was not itself public.
346 Erroneous code example:
358 The solution to this problem is to ensure that the items that you are
359 re-exporting are themselves marked with `pub`:
363 pub const X: u32 = 1;
371 See the 'Use Declarations' section of the reference for more information on
374 https://doc.rust-lang.org/reference.html#use-declarations
378 Private modules cannot be publicly re-exported. This error indicates that you
379 attempted to `pub use` a module that was not itself public.
381 Erroneous code example:
383 ```compile_fail,E0365
385 pub const X: u32 = 1;
393 The solution to this problem is to ensure that the module that you are
394 re-exporting is itself marked with `pub`:
398 pub const X: u32 = 1;
406 See the 'Use Declarations' section of the reference for more information
409 https://doc.rust-lang.org/reference.html#use-declarations
413 Inner items do not inherit type or const parameters from the functions
414 they are embedded in.
416 Erroneous code example:
418 ```compile_fail,E0401
420 fn bar(y: T) { // T is defined in the "outer" function
429 ```compile_fail,E0401
431 type MaybeT = Option<T>;
438 ```compile_fail,E0401
447 Items inside functions are basically just like top-level items, except
448 that they can only be used from the function they are in.
450 There are a couple of solutions for this.
452 If the item is a function, you may use a closure:
456 let bar = |y: T| { // explicit type annotation may not be necessary
463 For a generic item, you can copy over the parameters:
476 type MaybeT<T> = Option<T>;
480 Be sure to copy over any bounds as well:
483 fn foo<T: Copy>(x: T) {
484 fn bar<T: Copy>(y: T) {
492 fn foo<T: Copy>(x: T) {
493 struct Foo<T: Copy> {
499 This may require additional type hints in the function body.
501 In case the item is a function inside an `impl`, defining a private helper
502 function might be easier:
507 pub fn foo(&self, x: T) {
511 fn bar(&self, y: T) {
517 For default impls in traits, the private helper solution won't work, however
518 closures or copying the parameters should still work.
522 Some type parameters have the same name.
524 Erroneous code example:
526 ```compile_fail,E0403
527 fn f<T, T>(s: T, u: T) {} // error: the name `T` is already used for a generic
528 // parameter in this item's generic parameters
531 Please verify that none of the type parameters are misspelled, and rename any
532 clashing parameters. Example:
535 fn f<T, Y>(s: T, u: Y) {} // ok!
538 Type parameters in an associated item also cannot shadow parameters from the
541 ```compile_fail,E0403
543 fn do_something(&self) -> T;
544 fn do_something_else<T: Clone>(&self, bar: T);
550 You tried to use something which is not a trait in a trait position, such as
553 Erroneous code example:
555 ```compile_fail,E0404
559 impl Foo for Bar {} // error: `Foo` is not a trait
562 Another erroneous code example:
564 ```compile_fail,E0404
567 fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait
570 Please verify that you didn't misspell the trait's name or otherwise use the
571 wrong identifier. Example:
579 impl Foo for Bar { // ok!
580 // functions implementation
591 fn bar<T: Foo>(t: T) {} // ok!
597 The code refers to a trait that is not in scope.
599 Erroneous code example:
601 ```compile_fail,E0405
604 impl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope
607 Please verify that the name of the trait wasn't misspelled and ensure that it
608 was imported. Example:
611 # #[cfg(for_demonstration_only)]
613 use some_file::SomeTrait;
622 impl SomeTrait for Foo { // ok!
623 // implements functions
629 A definition of a method not in the implemented trait was given in a trait
632 Erroneous code example:
634 ```compile_fail,E0407
643 fn b() {} // error: method `b` is not a member of trait `Foo`
647 Please verify you didn't misspell the method name and you used the correct
648 trait. First example:
684 An "or" pattern was used where the variable bindings are not consistently bound
687 Erroneous code example:
689 ```compile_fail,E0408
691 Some(y) | None => { /* use y */ } // error: variable `y` from pattern #1 is
692 // not bound in pattern #2
697 Here, `y` is bound to the contents of the `Some` and can be used within the
698 block corresponding to the match arm. However, in case `x` is `None`, we have
699 not specified what `y` is, and the block will use a nonexistent variable.
701 To fix this error, either split into multiple match arms:
706 Some(y) => { /* use y */ }
707 None => { /* ... */ }
711 or, bind the variable to a field of the same type in all sub-patterns of the
717 (0, y) | (y, 0) => { /* use y */}
722 In this example, if `x` matches the pattern `(0, _)`, the second field is set
723 to `y`. If it matches `(_, 0)`, the first field is set to `y`; so in all
724 cases `y` is set to some value.
728 An "or" pattern was used where the variable bindings are not consistently bound
731 Erroneous code example:
733 ```compile_fail,E0409
736 (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
737 // different mode in pattern #2
738 // than in pattern #1
743 Here, `y` is bound by-value in one case and by-reference in the other.
745 To fix this error, just use the same mode in both cases.
746 Generally using `ref` or `ref mut` where not already used will fix this:
751 (0, ref y) | (ref y, 0) => { /* use y */}
756 Alternatively, split the pattern:
761 (y, 0) => { /* use y */ }
762 (0, ref y) => { /* use y */}
769 The `Self` keyword was used outside an impl, trait, or type definition.
771 Erroneous code example:
773 ```compile_fail,E0411
774 <Self>::foo; // error: use of `Self` outside of an impl, trait, or type
778 The `Self` keyword represents the current type, which explains why it can only
779 be used inside an impl, trait, or type definition. It gives access to the
780 associated items of a type:
788 fn bar() -> Self::Bar; // like this
792 However, be careful when two types have a common associated type:
803 trait Baz : Foo + Foo2 {
804 fn bar() -> Self::Bar;
805 // error: ambiguous associated type `Bar` in bounds of `Self`
809 This problem can be solved by specifying from which trait we want to use the
821 trait Baz : Foo + Foo2 {
822 fn bar() -> <Self as Foo>::Bar; // ok!
828 The type name used is not in scope.
830 Erroneous code examples:
832 ```compile_fail,E0412
833 impl Something {} // error: type name `Something` is not in scope
838 fn bar(N); // error: type name `N` is not in scope
843 fn foo(x: T) {} // type name `T` is not in scope
846 To fix this error, please verify you didn't misspell the type name, you did
847 declare it or imported it into the scope. Examples:
852 impl Something {} // ok!
859 fn bar(_: Self::N); // ok!
864 fn foo<T>(x: T) {} // ok!
867 Another case that causes this error is when a type is imported into a parent
868 module. To fix this, you can follow the suggestion and use File directly or
869 `use super::File;` which will import the types from the parent namespace. An
870 example that causes this error is below:
872 ```compile_fail,E0412
876 fn some_function(f: File) {}
887 // use std::fs::File;
890 # fn main() {} // don't insert it for us; that'll break imports
895 More than one function parameter have the same name.
897 Erroneous code example:
899 ```compile_fail,E0415
900 fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
901 // once in this parameter list
904 Please verify you didn't misspell parameters' name. Example:
907 fn foo(f: i32, g: i32) {} // ok!
912 An identifier is bound more than once in a pattern.
914 Erroneous code example:
916 ```compile_fail,E0416
918 (x, x) => {} // error: identifier `x` is bound more than once in the
923 Please verify you didn't misspell identifiers' name. Example:
931 Or maybe did you mean to unify? Consider using a guard:
934 # let (A, B, C) = (1, 2, 3);
936 (x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
937 (y, z, see) => { /* A and B unequal; do another thing */ }
943 You are trying to use an identifier that is either undefined or not a struct.
944 Erroneous code example:
946 ```compile_fail,E0422
948 let x = Foo { x: 1, y: 2 };
952 In this case, `Foo` is undefined, so it inherently isn't anything, and
953 definitely not a struct.
958 let x = foo { x: 1, y: 2 };
962 In this case, `foo` is defined, but is not a struct, so Rust can't use it as
967 An identifier was used like a function name or a value was expected and the
968 identifier exists but it belongs to a different namespace.
970 For (an erroneous) example, here a `struct` variant name were used as a
973 ```compile_fail,E0423
974 struct Foo { a: bool };
977 // error: expected function, tuple struct or tuple variant, found `Foo`
978 // `Foo` is a struct name, but this expression uses it like a function name
981 Please verify you didn't misspell the name of what you actually wanted to use
985 fn Foo() -> u32 { 0 }
987 let f = Foo(); // ok!
990 It is common to forget the trailing `!` on macro invocations, which would also
993 ```compile_fail,E0423
995 // error: expected function, tuple struct or tuple variant,
996 // found macro `println`
997 // did you mean `println!(...)`? (notice the trailing `!`)
1000 Another case where this error is emitted is when a value is expected, but
1001 something else is found:
1003 ```compile_fail,E0423
1005 pub const I: i32 = 1;
1010 //~^ ERROR expected value, found module `a`
1011 // did you mean `a::I`?
1017 The `self` keyword was used inside of an associated function without a "`self`
1018 receiver" parameter.
1020 Erroneous code example:
1022 ```compile_fail,E0424
1026 // `bar` is a method, because it has a receiver parameter.
1029 // `foo` is not a method, because it has no receiver parameter.
1031 self.bar(); // error: `self` value is a keyword only available in
1032 // methods with a `self` parameter
1037 The `self` keyword can only be used inside methods, which are associated
1038 functions (functions defined inside of a `trait` or `impl` block) that have a
1039 `self` receiver as its first parameter, like `self`, `&self`, `&mut self` or
1040 `self: &mut Pin<Self>` (this last one is an example of an ["abitrary `self`
1041 type"](https://github.com/rust-lang/rust/issues/44874)).
1043 Check if the associated function's parameter list should have contained a `self`
1044 receiver for it to be a method, and add it if so. Example:
1052 fn foo(self) { // `foo` is now a method.
1060 An unresolved name was used.
1062 Erroneous code examples:
1064 ```compile_fail,E0425
1065 something_that_doesnt_exist::foo;
1066 // error: unresolved name `something_that_doesnt_exist::foo`
1072 Self; // error: unresolved name `Self`
1078 let x = unknown_variable; // error: unresolved name `unknown_variable`
1081 Please verify that the name wasn't misspelled and ensure that the
1082 identifier being referred to is valid for the given situation. Example:
1085 enum something_that_does_exist {
1093 mod something_that_does_exist {
1094 pub static foo : i32 = 0i32;
1097 something_that_does_exist::foo; // ok!
1103 let unknown_variable = 12u32;
1104 let x = unknown_variable; // ok!
1107 If the item is not defined in the current module, it must be imported using a
1108 `use` statement, like so:
1111 # mod foo { pub fn bar() {} }
1118 If the item you are importing is not defined in some super-module of the
1119 current module, then it must also be declared as public (e.g., `pub fn`).
1123 An undeclared label was used.
1125 Erroneous code example:
1127 ```compile_fail,E0426
1129 break 'a; // error: use of undeclared label `'a`
1133 Please verify you spelt or declare the label correctly. Example:
1143 A type or module has been defined more than once.
1145 Erroneous code example:
1147 ```compile_fail,E0428
1149 struct Bar; // error: duplicate definition of value `Bar`
1152 Please verify you didn't misspell the type/module's name or remove/rename the
1153 duplicated one. Example:
1162 The `self` keyword cannot appear alone as the last segment in a `use`
1165 Erroneous code example:
1167 ```compile_fail,E0429
1168 use std::fmt::self; // error: `self` imports are only allowed within a { } list
1171 To use a namespace itself in addition to some of its members, `self` may appear
1172 as part of a brace-enclosed list of imports:
1175 use std::fmt::{self, Debug};
1178 If you only want to import the namespace, do so directly:
1186 The `self` import appears more than once in the list.
1188 Erroneous code example:
1190 ```compile_fail,E0430
1191 use something::{self, self}; // error: `self` import can only appear once in
1195 Please verify you didn't misspell the import name or remove the duplicated
1196 `self` import. Example:
1201 use something::{self}; // ok!
1207 An invalid `self` import was made.
1209 Erroneous code example:
1211 ```compile_fail,E0431
1212 use {self}; // error: `self` import can only appear in an import list with a
1216 You cannot import the current module into itself, please remove this import
1217 or verify you didn't misspell it.
1221 An import was unresolved.
1223 Erroneous code example:
1225 ```compile_fail,E0432
1226 use something::Foo; // error: unresolved import `something::Foo`.
1229 Paths in `use` statements are relative to the crate root. To import items
1230 relative to the current and parent modules, use the `self::` and `super::`
1231 prefixes, respectively. Also verify that you didn't misspell the import
1232 name and that the import exists in the module from where you tried to
1236 use self::something::Foo; // ok!
1244 Or, if you tried to use a module from an external crate, you may have missed
1245 the `extern crate` declaration (which is usually placed in the crate root):
1248 extern crate core; // Required to use the `core` crate
1256 An undeclared type or module was used.
1258 Erroneous code example:
1260 ```compile_fail,E0433
1261 let map = HashMap::new();
1262 // error: failed to resolve: use of undeclared type or module `HashMap`
1265 Please verify you didn't misspell the type/module's name or that you didn't
1266 forget to import it:
1270 use std::collections::HashMap; // HashMap has been imported.
1271 let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1276 This error indicates that a variable usage inside an inner function is invalid
1277 because the variable comes from a dynamic environment. Inner functions do not
1278 have access to their containing environment.
1280 Erroneous code example:
1282 ```compile_fail,E0434
1286 y // error: can't capture dynamic environment in a fn item; use the
1287 // || { ... } closure form instead.
1292 Functions do not capture local variables. To fix this error, you can replace the
1293 function with a closure:
1304 or replace the captured variable with a constant or a static item:
1308 static mut X: u32 = 4;
1321 A non-constant value was used in a constant expression.
1323 Erroneous code example:
1325 ```compile_fail,E0435
1327 let a: [u8; foo]; // error: attempt to use a non-constant value in a constant
1330 To fix this error, please replace the value with a constant. Example:
1333 let a: [u8; 42]; // ok!
1339 const FOO: usize = 42;
1340 let a: [u8; FOO]; // ok!
1345 Trait implementations can only implement associated types that are members of
1346 the trait in question. This error indicates that you attempted to implement
1347 an associated type whose name does not match the name of any associated type
1350 Erroneous code example:
1352 ```compile_fail,E0437
1360 The solution to this problem is to remove the extraneous associated type:
1370 Trait implementations can only implement associated constants that are
1371 members of the trait in question. This error indicates that you
1372 attempted to implement an associated constant whose name does not
1373 match the name of any associated constant in the trait.
1375 Erroneous code example:
1377 ```compile_fail,E0438
1381 const BAR: bool = true;
1385 The solution to this problem is to remove the extraneous associated constant:
1395 Macro import declarations were malformed.
1397 Erroneous code examples:
1399 ```compile_fail,E0466
1400 #[macro_use(a_macro(another_macro))] // error: invalid import declaration
1401 extern crate core as some_crate;
1403 #[macro_use(i_want = "some_macros")] // error: invalid import declaration
1404 extern crate core as another_crate;
1407 This is a syntax error at the level of attribute declarations. The proper
1408 syntax for macro imports is the following:
1410 ```ignore (cannot-doctest-multicrate-project)
1413 macro_rules! get_tacos {
1418 macro_rules! get_pimientos {
1423 #[macro_use(get_tacos, get_pimientos)] // It imports `get_tacos` and
1424 extern crate some_crate; // `get_pimientos` macros from some_crate
1427 If you would like to import all exported macros, write `macro_use` with no
1432 A non-root module attempts to import macros from another crate.
1434 Example of erroneous code:
1436 ```compile_fail,E0468
1438 #[macro_use(debug_assert)] // error: must be at crate root to import
1439 extern crate core; // macros from another crate
1440 fn run_macro() { debug_assert!(true); }
1444 Only `extern crate` imports at the crate root level are allowed to import
1447 Either move the macro import to crate root or do without the foreign macros.
1451 #[macro_use(debug_assert)]
1455 fn run_macro() { debug_assert!(true); }
1462 A macro listed for import was not found.
1464 Erroneous code example:
1466 ```compile_fail,E0469
1467 #[macro_use(drink, be_merry)] // error: imported macro not found
1475 Either the listed macro is not contained in the imported crate, or it is not
1476 exported from the given crate.
1478 This could be caused by a typo. Did you misspell the macro's name?
1480 Double-check the names of the macros listed for import, and that the crate
1481 in question exports them.
1483 A working version would be:
1485 ```ignore (cannot-doctest-multicrate-project)
1486 // In some_crate crate:
1493 macro_rules! drink {
1498 #[macro_use(eat, drink)]
1499 extern crate some_crate; //ok!
1504 A binding shadowed something it shouldn't.
1506 Erroneous code example:
1508 ```compile_fail,E0530
1509 static TEST: i32 = 0;
1511 let r: (i32, i32) = (0, 0);
1513 TEST => {} // error: match bindings cannot shadow statics
1517 To fix this error, just change the binding's name in order to avoid shadowing
1518 one of the following:
1521 * struct/enum variant
1529 static TEST: i32 = 0;
1531 let r: (i32, i32) = (0, 0);
1533 something => {} // ok!
1539 An unknown tuple struct/variant has been used.
1541 Erroneous code example:
1543 ```compile_fail,E0531
1544 let Type(x) = Type(12); // error!
1546 Bar(x) => {} // error!
1551 In most cases, it's either a forgotten import or a typo. However, let's look at
1552 how you can have such a type:
1555 struct Type(u32); // this is a tuple struct
1558 Bar(u32), // this is a tuple variant
1561 use Foo::*; // To use Foo's variant directly, we need to import them in
1565 Either way, it should work fine with our previous code:
1575 let Type(x) = Type(12); // ok!
1577 Type(x) => {} // ok!
1584 Pattern arm did not match expected kind.
1586 Erroneous code example:
1588 ```compile_fail,E0532
1594 fn print_on_failure(state: &State) {
1596 // error: expected unit struct, unit variant or constant, found tuple
1597 // variant `State::Failed`
1598 State::Failed => println!("Failed"),
1604 To fix this error, ensure the match arm kind is the same as the expression
1615 fn print_on_failure(state: &State) {
1617 State::Failed(ref msg) => println!("Failed with {}", msg),
1625 Something other than a type has been used when one was expected.
1627 Erroneous code examples:
1629 ```compile_fail,E0573
1634 fn oblivion() -> Dragon::Born { // error!
1638 const HOBBIT: u32 = 2;
1639 impl HOBBIT {} // error!
1647 fn wizard(_: Wizard::Saruman); // error!
1651 In all these errors, a type was expected. For example, in the first error, if
1652 we want to return the `Born` variant from the `Dragon` enum, we must set the
1653 function to return the enum and not its variant:
1660 fn oblivion() -> Dragon { // ok!
1665 In the second error, you can't implement something on an item, only on types.
1666 We would need to create a new type if we wanted to do something similar:
1669 struct Hobbit(u32); // we create a new type
1671 const HOBBIT: Hobbit = Hobbit(2);
1672 impl Hobbit {} // ok!
1675 In the third case, we tried to only expect one variant of the `Wizard` enum,
1676 which is not possible. To make this work, we need to using pattern matching
1677 over the `Wizard` enum:
1686 fn wizard(w: Wizard) { // ok!
1688 Wizard::Saruman => {
1691 _ => {} // ignore everything else
1699 Something other than a struct, variant or union has been used when one was
1702 Erroneous code example:
1704 ```compile_fail,E0574
1707 let sauron = Mordor { x: () }; // error!
1710 Daxter { i: isize },
1713 let eco = Jak::Daxter { i: 1 };
1715 Jak { i } => {} // error!
1719 In all these errors, a type was expected. For example, in the first error,
1720 we tried to instantiate the `Mordor` module, which is impossible. If you want
1721 to instantiate a type inside a module, you can do it as follow:
1725 pub struct TheRing {
1730 let sauron = Mordor::TheRing { x: 1 }; // ok!
1733 In the second error, we tried to bind the `Jak` enum directly, which is not
1734 possible: you can only bind one of its variants. To do so:
1738 Daxter { i: isize },
1741 let eco = Jak::Daxter { i: 1 };
1743 Jak::Daxter { i } => {} // ok!
1749 Something other than a type or an associated type was given.
1751 Erroneous code example:
1753 ```compile_fail,E0575
1756 let _: <u8 as Rick>::Morty; // error!
1767 let _: <u8 as Age>::Mythology; // error!
1770 In both cases, we're declaring a variable (called `_`) and we're giving it a
1771 type. However, `<u8 as Rick>::Morty` and `<u8 as Age>::Mythology` aren't types,
1772 therefore the compiler throws an error.
1774 `<u8 as Rick>::Morty` is an enum variant, you cannot use a variant as a type,
1775 you have to use the enum directly:
1783 `<u8 as Age>::Mythology` is a trait method, which is definitely not a type.
1784 However, the `Age` trait provides an associated type `Empire` which can be
1797 let _: <u8 as Age>::Empire; // ok!
1802 An associated item wasn't found in the given type.
1804 Erroneous code example:
1806 ```compile_fail,E0576
1810 fn hello() -> <Self as Hello>::You; // error!
1814 In this example, we tried to use the non-existent associated type `You` of the
1815 `Hello` trait. To fix this error, use an existing associated type:
1821 fn hello() -> <Self as Hello>::Who; // ok!
1827 A private item was used outside its scope.
1829 Erroneous code example:
1831 ```compile_fail,E0603
1833 const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
1834 // can't use it outside of the
1835 // `SomeModule` module.
1838 println!("const value: {}", SomeModule::PRIVATE); // error: constant `PRIVATE`
1842 In order to fix this error, you need to make the item public by using the `pub`
1847 pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
1851 println!("const value: {}", SomeModule::PRIVATE); // ok!
1856 An item usage is ambiguous.
1858 Erroneous code example:
1860 ```compile_fail,edition2018,E0659
1870 pub use crate::moon::*;
1871 pub use crate::earth::*;
1875 crate::collider::foo(); // ERROR: `foo` is ambiguous
1879 This error generally appears when two items with the same name are imported into
1880 a module. Here, the `foo` functions are imported and reexported from the
1881 `collider` module and therefore, when we're using `collider::foo()`, both
1884 To solve this error, the best solution is generally to keep the path before the
1885 item when using it. Example:
1897 pub use crate::moon;
1898 pub use crate::earth;
1902 crate::collider::moon::foo(); // ok!
1903 crate::collider::earth::foo(); // ok!
1909 #### Note: this error code is no longer emitted by the compiler.
1911 Const parameters cannot depend on type parameters.
1912 The following is therefore invalid:
1913 ```compile_fail,E0741
1914 #![feature(const_generics)]
1916 fn const_id<T, const N: T>() -> T { // error
1923 Type parameter defaults cannot use `Self` on structs, enums, or unions.
1925 Erroneous code example:
1927 ```compile_fail,E0735
1928 struct Foo<X = Box<Self>> {
1932 // error: type parameters cannot use `Self` in their defaults.
1937 Visibility is restricted to a module which isn't an ancestor of the current
1940 Erroneous code example:
1942 ```compile_fail,E0741,edition2018
1945 pub (in crate::Sea) struct Shark; // error!
1950 To fix this error, we need to move the `Shark` struct inside the `Sea` module:
1954 pub (in crate::Sea) struct Shark; // ok!
1960 Of course, you can do it as long as the module you're referring to is an
1966 pub (in crate::Earth) struct Shark; // ok!
1975 // E0153, unused error code
1976 // E0157, unused error code
1979 // E0402, // cannot use an outer type parameter in this context
1980 // E0406, merged into 420
1981 // E0410, merged into 408
1982 // E0413, merged into 530
1983 // E0414, merged into 530
1984 // E0417, merged into 532
1985 // E0418, merged into 532
1986 // E0419, merged into 531
1987 // E0420, merged into 532
1988 // E0421, merged into 531
1989 // E0427, merged into 530