Here is an example that demonstrates the error:
-```
+```compile_fail
fn f() {
// Variable declaration before import
let x = 0;
use std::io::Read;
- ...
+ // ...
}
```
fn f() {
use std::io::Read;
let x = 0;
- ...
+ // ...
}
```
An example of this error:
-```
+```compile_fail
use foo::baz;
use bar::*; // error, do `use foo::baz as quux` instead on the previous line
An example of this error:
-```
+```compile_fail
use foo::baz;
use bar::baz; // error, do `use bar::baz as quux` instead
Attempt was made to import an unimportable value. This can happen when
trying to import a method from a trait. An example of this error:
-```
+```compile_fail
mod foo {
pub trait MyTrait {
fn do_something();
}
}
+
use foo::MyTrait::do_something;
```
An example of this error:
-```
+```compile_fail
use bar::foo; // error, do `use bar::foo as baz` instead
fn foo() {}
An example of this error:
-```
+```compile_fail
use foo::Bar; // error
type Bar = u32;
Wrong example:
-```
+```compile_fail
extern crate a;
extern crate crate_a as a;
```
Correct example:
-```
+```ignore
extern crate a;
extern crate crate_a as other_name;
```
E0260: r##"
The name for an item declaration conflicts with an external crate's name.
-For instance,
+For instance:
-```
+```ignore
extern crate abc;
struct abc;
Solution #1: Rename the item.
-```
+```ignore
extern crate abc;
struct xyz;
Solution #2: Import the crate with a different name.
-```
+```ignore
extern crate abc as xyz;
struct abc;
This error indicates you tried to define a type, struct or enum with the same
name as an existing primitive type:
-```
+```compile_fail
struct u8 {
// ...
}
Such an error may also occur if you define a type parameter which shadows a
primitive type. An example would be something like:
-```
+```compile_fail
impl<u8> MyTrait for Option<u8> {
// ...
}
In such a case, if you meant for `u8` to be a generic type parameter (i.e. any
type can be used in its place), use something like `T` instead:
-```
+```ignore
impl<T> MyTrait for Option<T> {
// ...
}
On the other hand, if you wished to refer to the specific type `u8`, remove it
from the type parameter list:
-```
+```ignore
impl MyTrait for Option<u8> {
// ...
}
Here is an example that demonstrates the error:
-```
+```compile_fail
mod foo {
const X: u32 = 1;
}
+
pub use foo::X;
```
The solution to this problem is to ensure that the items that you are
re-exporting are themselves marked with `pub`:
-```
+```ignore
mod foo {
pub const X: u32 = 1;
}
+
pub use foo::X;
```
Here is an example that demonstrates the error:
-```
+```compile_fail
mod foo {
pub const X: u32 = 1;
}
-pub use foo as foo2;
+pub use foo as foo2;
```
+
The solution to this problem is to ensure that the module that you are
re-exporting is itself marked with `pub`:
-```
+```ignore
pub mod foo {
pub const X: u32 = 1;
}
+
pub use foo as foo2;
```
Inner items do not inherit type parameters from the functions they are
embedded in. For example, this will not compile:
-```
+```compile_fail
fn foo<T>(x: T) {
fn bar(y: T) { // T is defined in the "outer" function
// ..
}
```
-nor will this:
+Nor will this:
-```
+```compile_fail
fn foo<T>(x: T) {
type MaybeT = Option<T>;
// ...
}
```
-or this:
+Or this:
-```
+```compile_fail
fn foo<T>(x: T) {
struct Foo {
x: T,
fn foo<T>(x: T) {
let bar = |y: T| { // explicit type annotation may not be necessary
// ..
- }
+ };
bar(x);
}
```
In case the item is a function inside an `impl`, defining a private helper
function might be easier:
-```
+```ignore
impl<T> Foo<T> {
pub fn foo(&self, x: T) {
self.bar(x);
}
+
fn bar(&self, y: T) {
// ..
}
E0403: r##"
Some type parameters have the same name. Example of erroneous code:
-```
+```compile_fail
fn foo<T, T>(s: T, u: T) {} // error: the name `T` is already used for a type
// parameter in this type parameter list
```
You tried to implement something which was not a trait on an object. Example of
erroneous code:
-```
+```compile_fail
struct Foo;
struct Bar;
E0405: r##"
An unknown trait was implemented. Example of erroneous code:
-```
+```compile_fail
struct Foo;
impl SomeTrait for Foo {} // error: use of undeclared trait name `SomeTrait`
Please verify that the name of the trait wasn't misspelled and ensure that it
was imported. Example:
-```
+```ignore
// solution 1:
use some_file::SomeTrait;
A definition of a method not in the implemented trait was given in a trait
implementation. Example of erroneous code:
-```
+```compile_fail
trait Foo {
fn a();
}
The `Self` keyword was used outside an impl or a trait. Erroneous
code example:
-```
+```compile_fail
<Self>::foo; // error: use of `Self` outside of an impl or trait
```
However, be careful when two types has a common associated type:
-```
+```compile_fail
trait Foo {
type Bar;
}
to use the `Bar` type:
```
+trait Foo {
+ type Bar;
+}
+
+trait Foo2 {
+ type Bar;
+}
+
trait Baz : Foo + Foo2 {
fn bar() -> <Self as Foo>::Bar; // ok!
}
E0412: r##"
An undeclared type name was used. Example of erroneous codes:
-```
+```compile_fail
impl Something {} // error: use of undeclared type name `Something`
// or:
trait Foo {
struct Something;
impl Something {} // ok!
+
// or:
+
trait Foo {
type N;
fn bar(Self::N); // ok!
}
-//or:
+
+// or:
+
fn foo<T>(x: T) {} // ok!
```
"##,
A declaration shadows an enum variant or unit-like struct in scope.
Example of erroneous code:
-```
+```compile_fail
struct Foo;
let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
// unit-like struct in scope
```
-
To fix this error, rename the variable such that it doesn't shadow any enum
variable or structure in scope. Example:
More than one function parameter have the same name. Example of erroneous
code:
-```
+```compile_fail
fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
// once in this parameter list
```
An identifier is bound more than once in a pattern. Example of erroneous
code:
-```
+```compile_fail
match (1, 2) {
(x, x) => {} // error: identifier `x` is bound more than once in the
// same pattern
Or maybe did you mean to unify? Consider using a guard:
-```
+```ignore
match (A, B, C) {
(x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
(y, z, see) => { /* A and B unequal; do another thing */ }
E0417: r##"
A static variable was referenced in a pattern. Example of erroneous code:
-```
+```compile_fail
static FOO : i32 = 0;
match 0 {
An unknown enum variant, struct or const was used. Example of
erroneous code:
-```
+```compile_fail
match 0 {
Something::Foo => {} // error: unresolved enum variant, struct
// or const `Foo`
E0422: r##"
You are trying to use an identifier that is either undefined or not a
struct. For instance:
-```
+
+``` compile_fail
fn main () {
let x = Foo { x: 1, y: 2 };
}
In this case, `Foo` is undefined, so it inherently isn't anything, and
definitely not a struct.
-```
+```compile_fail
fn main () {
let foo = 1;
let x = foo { x: 1, y: 2 };
A `struct` variant name was used like a function name. Example of
erroneous code:
-```
+```compile_fail
struct Foo { a: bool};
let f = Foo();
E0424: r##"
The `self` keyword was used in a static method. Example of erroneous code:
-```
+```compile_fail
struct Foo;
impl Foo {
E0425: r##"
An unresolved name was used. Example of erroneous codes:
-```
+```compile_fail
something_that_doesnt_exist::foo;
// error: unresolved name `something_that_doesnt_exist::foo`
```
enum something_that_does_exist {
- foo
+ Foo,
}
+```
-// or:
+Or:
+
+```
mod something_that_does_exist {
pub static foo : i32 = 0i32;
}
something_that_does_exist::foo; // ok!
+```
-// or:
+Or:
+
+```
let unknown_variable = 12u32;
let x = unknown_variable; // ok!
```
E0426: r##"
An undeclared label was used. Example of erroneous code:
-```
+```compile_fail
loop {
break 'a; // error: use of undeclared label `'a`
}
A type or module has been defined more than once. Example of erroneous
code:
-```
+```compile_fail
struct Bar;
struct Bar; // error: duplicate definition of value `Bar`
```
E0430: r##"
The `self` import appears more than once in the list. Erroneous code example:
-```
+```compile_fail
use something::{self, self}; // error: `self` import can only appear once in
// the list
```
Please verify you didn't misspell the import name or remove the duplicated
`self` import. Example:
-```
+```ignore
use something::self; // ok!
```
"##,
E0431: r##"
`self` import was made. Erroneous code example:
-```
+```compile_fail
use {self}; // error: `self` import can only appear in an import list with a
// non-empty prefix
```
E0432: r##"
An import was unresolved. Erroneous code example:
-```
+```compile_fail
use something::Foo; // error: unresolved import `something::Foo`.
```
Please verify you didn't misspell the import name or the import does exist
in the module from where you tried to import it. Example:
-```
+```ignore
use something::Foo; // ok!
mod something {
Or, if you tried to use a module from an external crate, you may have missed
the `extern crate` declaration:
-```
+```ignore
extern crate homura; // Required to use the `homura` crate
use homura::Madoka;
E0433: r##"
Invalid import. Example of erroneous code:
-```
+```compile_fail
use something_which_doesnt_exist;
// error: unresolved import `something_which_doesnt_exist`
```
A non-constant value was used to initialise a constant. Example of erroneous
code:
-```
+```compile_fail
let foo = 42u32;
const FOO : u32 = foo; // error: attempt to use a non-constant value in a
// constant
```
const FOO : u32 = 42u32; // ok!
+```
-// or:
+Or:
+
+```
const OTHER_FOO : u32 = 42u32;
const FOO : u32 = OTHER_FOO; // ok!
```
Here is an example that demonstrates the error:
-```
+```compile_fail
trait Foo {}
impl Foo for i32 {
Here is an example that demonstrates the error:
-```
+```compile_fail
#![feature(associated_consts)]
trait Foo {}