will never be reached as for all possible values of the expression being
matched, one of the preceding patterns will match.
-This means that perhaps some of the preceding patterns are too general, this one
-is too specific or the ordering is incorrect.
+This means that perhaps some of the preceding patterns are too general, this
+one is too specific or the ordering is incorrect.
For example, the following `match` block has too many arms:
-```
+```compile_fail
match foo {
Some(bar) => {/* ... */}
None => {/* ... */}
An example of an empty type is `enum Empty { }`. So, the following will work:
```
+enum Empty {}
+
fn foo(x: Empty) {
match x {
// empty
However, this won't:
-```
+```compile_fail
+enum Empty {}
+
fn foo(x: Option<String>) {
match x {
// empty
Not-a-Number (NaN) values cannot be compared for equality and hence can never
match the input to a match expression. So, the following will not compile:
-```
+```compile_fail
const NAN: f32 = 0.0 / 0.0;
+let number = 0.1f32;
+
match number {
NAN => { /* ... */ },
- // ...
+ _ => {}
}
```
guard, like so:
```
+let number = 0.1f32;
+
match number {
- // ...
x if x.is_nan() => { /* ... */ }
- // ...
+ _ => {}
}
```
"##,
This error indicates that the compiler cannot guarantee a matching pattern for
one or more possible inputs to a match expression. Guaranteed matches are
required in order to assign values to match expressions, or alternatively,
-determine the flow of execution.
+determine the flow of execution. Erroneous code example:
+
+```compile_fail
+enum Terminator {
+ HastaLaVistaBaby,
+ TalkToMyHand,
+}
+
+let x = Terminator::HastaLaVistaBaby;
+
+match x { // error: non-exhaustive patterns: `HastaLaVistaBaby` not covered
+ Terminator::TalkToMyHand => {}
+}
+```
If you encounter this error you must alter your patterns so that every possible
value of the input type is matched. For types with a small number of variants
(like enums) you should probably cover all cases explicitly. Alternatively, the
underscore `_` wildcard pattern can be added after all other patterns to match
-"anything else".
+"anything else". Example:
+
+```
+enum Terminator {
+ HastaLaVistaBaby,
+ TalkToMyHand,
+}
+
+let x = Terminator::HastaLaVistaBaby;
+
+match x {
+ Terminator::TalkToMyHand => {}
+ Terminator::HastaLaVistaBaby => {}
+}
+
+// or:
+
+match x {
+ Terminator::TalkToMyHand => {}
+ _ => {}
+}
+```
"##,
E0005: r##"
Patterns used to bind names must be irrefutable, that is, they must guarantee
-that a name will be extracted in all cases. If you encounter this error you
-probably need to use a `match` or `if let` to deal with the possibility of
-failure.
+that a name will be extracted in all cases. Erroneous code example:
+
+```compile_fail
+let x = Some(1);
+let Some(y) = x;
+// error: refutable pattern in local binding: `None` not covered
+```
+
+If you encounter this error you probably need to use a `match` or `if let` to
+deal with the possibility of failure. Example:
+
+```compile_fail
+let x = Some(1);
+
+match x {
+ Some(y) => {
+ // do something
+ },
+ None => {}
+}
+
+// or:
+
+if let Some(y) = x {
+ // do something
+}
+```
"##,
E0007: r##"
This error indicates that the bindings in a match arm would require a value to
-be moved into more than one location, thus violating unique ownership. Code like
-the following is invalid as it requires the entire `Option<String>` to be moved
-into a variable called `op_string` while simultaneously requiring the inner
-String to be moved into a variable called `s`.
+be moved into more than one location, thus violating unique ownership. Code
+like the following is invalid as it requires the entire `Option<String>` to be
+moved into a variable called `op_string` while simultaneously requiring the
+inner `String` to be moved into a variable called `s`.
-```
+```compile_fail
let x = Some("s".to_string());
+
match x {
- op_string @ Some(s) => ...
- None => ...
+ op_string @ Some(s) => {},
+ None => {},
}
```
-See also Error 303.
+See also the error E0303.
"##,
E0008: r##"
referenced in the pattern guard code. Doing so however would prevent the name
from being available in the body of the match arm. Consider the following:
-```
+```compile_fail
match Some("hi".to_string()) {
- Some(s) if s.len() == 0 => // use s.
- ...
+ Some(s) if s.len() == 0 => {}, // use s.
+ _ => {},
}
```
innocuous, the problem is most clear when considering functions that take their
argument by value.
-```
+```compile_fail
match Some("hi".to_string()) {
Some(s) if { drop(s); false } => (),
- Some(s) => // use s.
- ...
+ Some(s) => {}, // use s.
+ _ => {},
}
```
This limitation may be removed in a future version of Rust.
-Wrong example:
+Erroneous code example:
-```
+```compile_fail
struct X { x: (), }
let x = Some((X { x: () }, X { x: () }));
remainder of a zero divisor) in a static or constant expression. Erroneous
code example:
-```
+```compile_fail
const X: i32 = 42 / 0;
// error: attempted to divide by zero in a constant expression
```
}
```
-we cannot create an object of type `Box<Foo>` or `&Foo` since in this case
+We cannot create an object of type `Box<Foo>` or `&Foo` since in this case
`Self` would not be `Sized`.
Generally, `Self : Sized` is used to indicate that the trait should not be used
This happens when a trait has a method like the following:
-```
+```compile_fail
trait Trait {
fn foo(&self) -> Self;
}
```
(Note that `&self` and `&mut self` are okay, it's additional `Self` types which
-cause this problem)
+cause this problem.)
In such a case, the compiler cannot predict the return type of `foo()` in a
situation like the following:
-```
+```compile_fail
+trait Trait {
+ fn foo(&self) -> Self;
+}
+
fn call_foo(x: Box<Trait>) {
let y = x.foo(); // What type is y?
// ...
trait Trait {
fn foo(&self);
}
+
impl Trait for String {
fn foo(&self) {
// implementation 1
}
}
+
impl Trait for u8 {
fn foo(&self) {
// implementation 2
}
```
-the machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any
+The machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any
other type substitution is different. Hence the compiler generates the
implementation on-demand. If you call `foo()` with a `bool` parameter, the
compiler will only generate code for `foo::<bool>()`. When we have additional
fn foo<T>(&self, on: T);
// more methods
}
+
impl Trait for String {
fn foo<T>(&self, on: T) {
// implementation 1
}
}
+
impl Trait for u8 {
fn foo<T>(&self, on: T) {
// implementation 2
}
}
+
// 8 more implementations
```
Now, if we have the following code:
-```
+```ignore
fn call_foo(thing: Box<Trait>) {
thing.foo(true); // this could be any one of the 8 types above
thing.foo(1);
}
```
-we don't just need to create a table of all implementations of all methods of
+We don't just need to create a table of all implementations of all methods of
`Trait`, we need to create such a table, for each different type fed to
`foo()`. In this case this turns out to be (10 types implementing `Trait`)*(3
types being fed to `foo()`) = 30 implementations!
### Method has no receiver
Methods that do not take a `self` parameter can't be called since there won't be
-a way to get a pointer to the method table for them
+a way to get a pointer to the method table for them.
```
trait Foo {
This is similar to the second sub-error, but subtler. It happens in situations
like the following:
-```
+```compile_fail
trait Super<A> {}
trait Trait: Super<Self> {
Consider the following erroneous definition of a type for a list of bytes:
-```
+```compile_fail
// error, invalid recursive struct type
struct ListNode {
head: u8,
You tried to give a type parameter to a type which doesn't need it. Erroneous
code example:
-```
+```compile_fail
type X = u32<i32>; // error: type parameters are not allowed on this type
```
You tried to give a lifetime parameter to a type which doesn't need it.
Erroneous code example:
-```
+```compile_fail
type X = u32<'static>; // error: lifetime parameters are not allowed on
// this type
```
"##,
E0133: r##"
-Using unsafe functionality, is potentially dangerous and disallowed
-by safety checks. Examples:
+Using unsafe functionality is potentially dangerous and disallowed by safety
+checks. Examples:
-- Dereferencing raw pointers
-- Calling functions via FFI
-- Calling functions marked unsafe
+* Dereferencing raw pointers
+* Calling functions via FFI
+* Calling functions marked unsafe
-These safety checks can be relaxed for a section of the code
-by wrapping the unsafe instructions with an `unsafe` block. For instance:
+These safety checks can be relaxed for a section of the code by wrapping the
+unsafe instructions with an `unsafe` block. For instance:
```
unsafe fn f() { return; }
So, for example, the following is not allowed:
-```
-struct Foo<T>(Vec<T>)
+```compile_fail
+struct Foo<T>(Vec<T>);
fn foo<T>(x: Vec<T>) {
// we are transmuting between Vec<T> and Foo<T> here
possible type substitution. It's possible to use traits to do this cleanly,
for example:
-```
+```ignore
+struct Foo<T>(Vec<T>);
+
trait MyTransmutableType {
- fn transmute(Vec<Self>) -> Foo<Self>
+ fn transmute(Vec<Self>) -> Foo<Self>;
}
impl MyTransmutableType for u8 {
transmute(x)
}
}
+
impl MyTransmutableType for String {
fn transmute(x: Foo<String>) -> Vec<String> {
transmute(x)
}
}
+
// ... more impls for the types you intend to transmute
fn foo<T: MyTransmutableType>(x: Vec<T>) {
It is also possible to manually transmute:
-```
+```ignore
ptr::read(&v as *const _ as *const SomeType) // `v` transmuted to `SomeType`
```
```
static FORTY_TWO: i32 = 42;
+
match Some(42) {
- Some(x) if x == FORTY_TWO => ...
- ...
+ Some(x) if x == FORTY_TWO => {}
+ _ => {}
}
```
"##,
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding instead. For instance:
-```
+```compile_fail
struct Irrefutable(i32);
let irr = Irrefutable(0);
// This body will always be executed.
foo(x);
}
+```
+
+Try this instead:
+
+```ignore
+struct Irrefutable(i32);
+let irr = Irrefutable(0);
-// Try this instead:
let Irrefutable(x) = irr;
foo(x);
```
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding inside a `loop` instead. For instance:
-```
+```compile_fail
struct Irrefutable(i32);
let irr = Irrefutable(0);
...
}
-// Try this instead:
+Try this instead:
+
+```
+struct Irrefutable(i32);
+let irr = Irrefutable(0);
+
loop {
let Irrefutable(x) = irr;
...
```
enum Method {
GET,
- POST
+ POST,
}
```
-you would match it using:
+You would match it using:
```
+enum Method {
+ GET,
+ POST,
+}
+
+let m = Method::GET;
+
match m {
- Method::GET => ...
- Method::POST => ...
+ Method::GET => {},
+ Method::POST => {},
}
```
Qualified names are good practice, and most code works well with them. But if
you prefer them unqualified, you can import the variants into scope:
-```
+```ignore
use Method::*;
enum Method { GET, POST }
```
If you want others to be able to import variants from your module directly, use
`pub use`:
-```
+```ignore
pub use Method::*;
enum Method { GET, POST }
```
An associated type binding was done outside of the type parameter declaration
and `where` clause. Erroneous code example:
-```
+```compile_fail
pub trait Foo {
type A;
fn boo(&self) -> <Self as Foo>::A;
To solve this error, please move the type bindings in the type parameter
declaration:
-```
+```ignore
fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok!
```
-or in the `where` clause:
+Or in the `where` clause:
-```
+```ignore
fn baz<I>(x: &<I as Foo>::A) where I: Foo<A=Bar> {}
```
"##,
These two examples illustrate the problem:
-```
+```compile_fail
// error, use of undeclared lifetime name `'a`
fn foo(x: &'a str) { }
These can be fixed by declaring lifetime parameters:
```
-fn foo<'a>(x: &'a str) { }
+fn foo<'a>(x: &'a str) {}
struct Foo<'a> {
x: &'a str,
because the `'static` lifetime is a special built-in lifetime name denoting
the lifetime of the entire program, this is an error:
-```
+```compile_fail
// error, invalid lifetime parameter name `'static`
fn foo<'static>(x: &'static str) { }
```
A lifetime name cannot be declared more than once in the same scope. For
example:
-```
+```compile_fail
// error, lifetime name `'a` declared twice in the same scope
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
```
E0264: r##"
An unknown external lang item was used. Erroneous code example:
-```
+```compile_fail
#![feature(lang_items)]
extern "C" {
E0269: r##"
Functions must eventually return a value of their return type. For example, in
-the following function
+the following function:
-```
+```compile_fail
fn foo(x: u8) -> u8 {
if x > 0 {
x // alternatively, `return x`
}
```
-if the condition is true, the value `x` is returned, but if the condition is
+If the condition is true, the value `x` is returned, but if the condition is
false, control exits the `if` block and reaches a place where nothing is being
returned. All possible control paths must eventually return a `u8`, which is not
happening here.
An easy fix for this in a complicated function is to specify a default return
value, if possible:
-```
+```ignore
fn foo(x: u8) -> u8 {
if x > 0 {
x // alternatively, `return x`
For example, the following functions never return:
-```
+```no_run
fn foo() -> ! {
loop {}
}
fn baz() -> ! {
panic!(); // this macro internally expands to a call to a diverging function
}
-
```
Such functions can be used in a place where a value is expected without
-returning a value of that type, for instance:
+returning a value of that type, for instance:
+
+```no_run
+fn foo() -> ! {
+ loop {}
+}
+
+let x = 3;
-```
let y = match x {
1 => 1,
2 => 4,
_ => foo() // diverging function called here
};
+
println!("{}", y)
```
integer was expected. The `match` block will never finish executing, and any
point where `y` (like the print statement) is needed will not be reached.
-However, if we had a diverging function that actually does finish execution
+However, if we had a diverging function that actually does finish execution:
-```
-fn foo() -> {
+```ignore
+fn foo() -> ! {
loop {break;}
}
```
-then we would have an unknown value for `y` in the following code:
+Then we would have an unknown value for `y` in the following code:
+
+```no_run
+fn foo() -> ! {
+ loop {}
+}
+
+let x = 3;
-```
let y = match x {
1 => 1,
2 => 4,
_ => foo()
};
+
println!("{}", y);
```
-In the previous example, the print statement was never reached when the wildcard
-match arm was hit, so we were okay with `foo()` not returning an integer that we
-could set to `y`. But in this example, `foo()` actually does return control, so
-the print statement will be executed with an uninitialized value.
+In the previous example, the print statement was never reached when the
+wildcard match arm was hit, so we were okay with `foo()` not returning an
+integer that we could set to `y`. But in this example, `foo()` actually does
+return control, so the print statement will be executed with an uninitialized
+value.
Obviously we cannot have functions which are allowed to be used in such
positions and yet can return control. So, if you are defining a function that
-returns `!`, make sure that there is no way for it to actually finish executing.
+returns `!`, make sure that there is no way for it to actually finish
+executing.
"##,
E0271: r##"
Here is a basic example:
-```
+```compile_fail
trait Trait { type AssociatedType; }
+
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
println!("in foo");
}
+
impl Trait for i8 { type AssociatedType = &'static str; }
+
foo(3_i8);
```
Here is that same example again, with some explanatory comments:
-```
+```ignore
trait Trait { type AssociatedType; }
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
Here is a more subtle instance of the same problem, that can
arise with for-loops in Rust:
-```
+```compile_fail
let vs: Vec<i32> = vec![1, 2, 3, 4];
for v in &vs {
match v {
- 1 => {}
- _ => {}
+ 1 => {},
+ _ => {},
}
}
```
though may be harder to see. Again, here are some
explanatory comments for the same example:
-```
+```ignore
{
let vs = vec![1, 2, 3, 4];
```
// Basic Example:
trait Trait { type AssociatedType; }
+
fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
println!("in foo");
}
+
impl Trait for i8 { type AssociatedType = &'static str; }
+
foo(3_i8);
// For-Loop Example:
position that needs that trait. For example, when the following code is
compiled:
-```
+```compile_fail
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
-trait Index<Idx> { ... }
+trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
```
-there will be an error about `bool` not implementing `Index<u8>`, followed by a
+There will be an error about `bool` not implementing `Index<u8>`, followed by a
note saying "the type `bool` cannot be indexed by `u8`".
-As you can see, you can specify type parameters in curly braces for substitution
-with the actual types (using the regular format string syntax) in a given
-situation. Furthermore, `{Self}` will substitute to the type (in this case,
-`bool`) that we tried to use.
+As you can see, you can specify type parameters in curly braces for
+substitution with the actual types (using the regular format string syntax) in
+a given situation. Furthermore, `{Self}` will substitute to the type (in this
+case, `bool`) that we tried to use.
This error appears when the curly braces contain an identifier which doesn't
-match with any of the type parameters or the string `Self`. This might happen if
-you misspelled a type parameter, or if you intended to use literal curly braces.
-If it is the latter, escape the curly braces with a second curly brace of the
-same type; e.g. a literal `{` is `{{`
+match with any of the type parameters or the string `Self`. This might happen
+if you misspelled a type parameter, or if you intended to use literal curly
+braces. If it is the latter, escape the curly braces with a second curly brace
+of the same type; e.g. a literal `{` is `{{`.
"##,
E0273: r##"
position that needs that trait. For example, when the following code is
compiled:
-```
+```compile_fail
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
-trait Index<Idx> { ... }
+trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
```
there will be an error about `bool` not implementing `Index<u8>`, followed by a
note saying "the type `bool` cannot be indexed by `u8`".
-As you can see, you can specify type parameters in curly braces for substitution
-with the actual types (using the regular format string syntax) in a given
-situation. Furthermore, `{Self}` will substitute to the type (in this case,
-`bool`) that we tried to use.
+As you can see, you can specify type parameters in curly braces for
+substitution with the actual types (using the regular format string syntax) in
+a given situation. Furthermore, `{Self}` will substitute to the type (in this
+case, `bool`) that we tried to use.
This error appears when the curly braces do not contain an identifier. Please
add one of the same name as a type parameter. If you intended to use literal
position that needs that trait. For example, when the following code is
compiled:
-```
+```compile_fail
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
-trait Index<Idx> { ... }
+trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
```
E0275: r##"
This error occurs when there was a recursive trait requirement that overflowed
-before it could be evaluated. Often this means that there is unbounded recursion
-in resolving some type bounds.
+before it could be evaluated. Often this means that there is unbounded
+recursion in resolving some type bounds.
-For example, in the following code
+For example, in the following code:
-```
+```compile_fail
trait Foo {}
struct Bar<T>(T);
impl<T> Foo for T where Bar<T>: Foo {}
```
-to determine if a `T` is `Foo`, we need to check if `Bar<T>` is `Foo`. However,
-to do this check, we need to determine that `Bar<Bar<T>>` is `Foo`. To determine
-this, we check if `Bar<Bar<Bar<T>>>` is `Foo`, and so on. This is clearly a
-recursive requirement that can't be resolved directly.
+To determine if a `T` is `Foo`, we need to check if `Bar<T>` is `Foo`. However,
+to do this check, we need to determine that `Bar<Bar<T>>` is `Foo`. To
+determine this, we check if `Bar<Bar<Bar<T>>>` is `Foo`, and so on. This is
+clearly a recursive requirement that can't be resolved directly.
Consider changing your trait bounds so that they're less self-referential.
"##,
This error occurs when a bound in an implementation of a trait does not match
the bounds specified in the original trait. For example:
-```
+```compile_fail
trait Foo {
- fn foo<T>(x: T);
+ fn foo<T>(x: T);
}
impl Foo for bool {
- fn foo<T>(x: T) where T: Copy {}
+ fn foo<T>(x: T) where T: Copy {}
}
```
You tried to use a type which doesn't implement some trait in a place which
expected that trait. Erroneous code example:
-```
+```compile_fail
// here we declare the Foo trait with a bar method
trait Foo {
fn bar(&self);
// we now call the method with the i32 type, which doesn't implement
// the Foo trait
some_func(5i32); // error: the trait `Foo` is not implemented for the
- // type `i32`
+ // type `i32`
}
```
which expected that trait. This error typically occurs when working with
`Fn`-based types. Erroneous code example:
-```
+```compile_fail
fn foo<F: Fn()>(x: F) { }
fn main() {
implemented by `Vec` and `String` among others. Consider the following snippet
that reverses the characters of a string:
-```
+```compile_fail
let x = "hello".chars().rev().collect();
```
case it is not always possible to use a type annotation, because all candidates
have the same return type. For instance:
-```
+```compile_fail
struct Foo<T> {
- // Some fields omitted.
+ num: T,
}
impl<T> Foo<T> {
For example:
-```
+```compile_fail
trait Generator {
fn create() -> u32;
}
struct Impl;
+
impl Generator for Impl {
fn create() -> u32 { 1 }
}
struct AnotherImpl;
+
impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
}
To resolve this error use the concrete type:
```
+trait Generator {
+ fn create() -> u32;
+}
+
+struct AnotherImpl;
+
+impl Generator for AnotherImpl {
+ fn create() -> u32 { 2 }
+}
+
fn main() {
let gen1 = AnotherImpl::create();
loop variable, consider using a `match` or `if let` inside the loop body. For
instance:
-```
+```compile_fail
+let xs : Vec<Option<i32>> = vec!(Some(1), None);
+
// This fails because `None` is not covered.
for Some(x) in xs {
- ...
+ // ...
}
+```
+
+Match inside the loop instead:
+
+```
+let xs : Vec<Option<i32>> = vec!(Some(1), None);
-// Match inside the loop instead:
for item in xs {
match item {
- Some(x) => ...
- None => ...
+ Some(x) => {},
+ None => {},
}
}
+```
+
+Or use `if let`:
+
+```
+let xs : Vec<Option<i32>> = vec!(Some(1), None);
-// Or use `if let`:
for item in xs {
if let Some(x) = item {
- ...
+ // ...
}
}
```
exhaustive. For instance, the following would not match any arm if mutable
borrows were allowed:
-```
+```compile_fail
match Some(()) {
None => { },
- option if option.take().is_none() => { /* impossible, option is `Some` */ },
+ option if option.take().is_none() => {
+ /* impossible, option is `Some` */
+ },
Some(_) => { } // When the previous match failed, the option became `None`.
}
```
exhaustive. For instance, the following would not match any arm if assignments
were allowed:
-```
+```compile_fail
match Some(()) {
None => { },
option if { option = None; false } { },
Updates to the borrow checker in a future version of Rust may remove this
restriction, but for now patterns must be rewritten without sub-bindings.
-```
+```ignore
// Before.
match Some("hi".to_string()) {
- ref op_string_ref @ Some(ref s) => ...
- None => ...
+ ref op_string_ref @ Some(s) => {},
+ None => {},
}
// After.
match Some("hi".to_string()) {
Some(ref s) => {
let op_string_ref = &Some(s);
- ...
- }
- None => ...
+ // ...
+ },
+ None => {},
}
```
E0306: r##"
In an array literal `[x; N]`, `N` is the number of elements in the array. This
-number cannot be negative.
+must be an unsigned integer. Erroneous code example:
+
+```compile_fail
+let x = [0i32; true]; // error: expected positive integer for repeat count,
+ // found boolean
+```
+
+Working example:
+
+```
+let x = [0i32; 2];
+```
"##,
E0307: r##"
-The length of an array is part of its type. For this reason, this length must be
-a compile-time constant.
+The length of an array is part of its type. For this reason, this length must
+be a compile-time constant. Erroneous code example:
+
+```compile_fail
+ let len = 10;
+ let x = [0i32; len]; // error: expected constant integer for repeat count,
+ // found variable
+```
"##,
E0308: r##"
For example:
-```
+```compile_fail
let x: i32 = "I am not a number!";
// ~~~ ~~~~~~~~~~~~~~~~~~~~
// | |
Another situation in which this occurs is when you attempt to use the `try!`
macro inside a function that does not return a `Result<T, E>`:
-```
+```compile_fail
use std::fs::File;
fn main() {
must be as long as the data needs to be alive, and missing the constraint that
denotes this will cause this error.
-```
+```compile_fail
// This won't compile because T is not constrained, meaning the data
// stored in it is not guaranteed to last as long as the reference
struct Foo<'a, T> {
foo: &'a T
}
+```
-// This will compile, because it has the constraint on the type parameter
+This will compile, because it has the constraint on the type parameter:
+
+```
struct Foo<'a, T: 'a> {
foo: &'a T
}
must be as long as the data needs to be alive, and missing the constraint that
denotes this will cause this error.
-```
+```compile_fail
// This won't compile because T is not constrained to the static lifetime
// the reference needs
struct Foo<T> {
foo: &'static T
}
-// This will compile, because it has the constraint on the type parameter
+This will compile, because it has the constraint on the type parameter:
+
+```
struct Foo<T: 'static> {
foo: &'static T
}
"##,
E0398: r##"
-In Rust 1.3, the default object lifetime bounds are expected to
-change, as described in RFC #1156 [1]. You are getting a warning
-because the compiler thinks it is possible that this change will cause
-a compilation error in your code. It is possible, though unlikely,
-that this is a false alarm.
-
-The heart of the change is that where `&'a Box<SomeTrait>` used to
-default to `&'a Box<SomeTrait+'a>`, it now defaults to `&'a
-Box<SomeTrait+'static>` (here, `SomeTrait` is the name of some trait
-type). Note that the only types which are affected are references to
-boxes, like `&Box<SomeTrait>` or `&[Box<SomeTrait>]`. More common
-types like `&SomeTrait` or `Box<SomeTrait>` are unaffected.
-
-To silence this warning, edit your code to use an explicit bound.
-Most of the time, this means that you will want to change the
-signature of a function that you are calling. For example, if
-the error is reported on a call like `foo(x)`, and `foo` is
-defined as follows:
-
-```
+In Rust 1.3, the default object lifetime bounds are expected to change, as
+described in RFC #1156 [1]. You are getting a warning because the compiler
+thinks it is possible that this change will cause a compilation error in your
+code. It is possible, though unlikely, that this is a false alarm.
+
+The heart of the change is that where `&'a Box<SomeTrait>` used to default to
+`&'a Box<SomeTrait+'a>`, it now defaults to `&'a Box<SomeTrait+'static>` (here,
+`SomeTrait` is the name of some trait type). Note that the only types which are
+affected are references to boxes, like `&Box<SomeTrait>` or
+`&[Box<SomeTrait>]`. More common types like `&SomeTrait` or `Box<SomeTrait>`
+are unaffected.
+
+To silence this warning, edit your code to use an explicit bound. Most of the
+time, this means that you will want to change the signature of a function that
+you are calling. For example, if the error is reported on a call like `foo(x)`,
+and `foo` is defined as follows:
+
+```ignore
fn foo(arg: &Box<SomeTrait>) { ... }
```
-you might change it to:
+You might change it to:
-```
+```ignore
fn foo<'a>(arg: &Box<SomeTrait+'a>) { ... }
```
-This explicitly states that you expect the trait object `SomeTrait` to
-contain references (with a maximum lifetime of `'a`).
+This explicitly states that you expect the trait object `SomeTrait` to contain
+references (with a maximum lifetime of `'a`).
[1]: https://github.com/rust-lang/rfcs/pull/1156
"##,
E0452: r##"
An invalid lint attribute has been given. Erroneous code example:
-```
+```compile_fail
#![allow(foo = "")] // error: malformed lint attribute
```
E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:
-```
+```compile_fail
struct Foo<'a> {
a: &'a i32,
}
A stability attribute was used outside of the standard library. Erroneous code
example:
-```
+```compile_fail
#[stable] // error: stability attributes may not be used outside of the
// standard library
fn foo() {}
"##,
E0517: r##"
-This error indicates that a `#[repr(..)]` attribute was placed on an unsupported
-item.
+This error indicates that a `#[repr(..)]` attribute was placed on an
+unsupported item.
Examples of erroneous code:
-```
+```compile_fail
#[repr(C)]
type Foo = u8;
#[repr(C)]
impl Foo {
- ...
+ // ...
}
```
- - The `#[repr(C)]` attribute can only be placed on structs and enums
- - The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs
- - The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums
+* The `#[repr(C)]` attribute can only be placed on structs and enums.
+* The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs.
+* The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums.
These attributes do not work on typedefs, since typedefs are just aliases.
Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
-discriminant size for C-like enums (when there is no associated data, e.g. `enum
-Color {Red, Blue, Green}`), effectively setting the size of the enum to the size
-of the provided type. Such an enum can be cast to a value of the same type as
-well. In short, `#[repr(u8)]` makes the enum behave like an integer with a
-constrained set of allowed values.
+discriminant size for C-like enums (when there is no associated data, e.g.
+`enum Color {Red, Blue, Green}`), effectively setting the size of the enum to
+the size of the provided type. Such an enum can be cast to a value of the same
+type as well. In short, `#[repr(u8)]` makes the enum behave like an integer
+with a constrained set of allowed values.
Only C-like enums can be cast to numerical primitives, so this attribute will
not apply to structs.
`#[repr(packed)]` reduces padding to make the struct size smaller. The
-representation of enums isn't strictly defined in Rust, and this attribute won't
-work on enums.
+representation of enums isn't strictly defined in Rust, and this attribute
+won't work on enums.
`#[repr(simd)]` will give a struct consisting of a homogenous series of machine
types (i.e. `u8`, `i32`, etc) a representation that permits vectorization via
"##,
E0518: r##"
-This error indicates that an `#[inline(..)]` attribute was incorrectly placed on
-something other than a function or method.
+This error indicates that an `#[inline(..)]` attribute was incorrectly placed
+on something other than a function or method.
Examples of erroneous code:
-```
+```compile_fail
#[inline(always)]
struct Foo;
#[inline(never)]
impl Foo {
- ...
+ // ...
}
```
attribute.
"##,
+E0522: r##"
+The lang attribute is intended for marking special items that are built-in to
+Rust itself. This includes special traits (like `Copy` and `Sized`) that affect
+how the compiler behaves, as well as special functions that may be automatically
+invoked (such as the handler for out-of-bounds accesses when indexing a slice).
+Erroneous code example:
+
+```compile_fail
+#![feature(lang_items)]
+
+#[lang = "cookie"]
+fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
+ loop {}
+}
+```
+"##,
+
}
// E0285, // overflow evaluation builtin bounds
E0298, // mismatched types between arms
E0299, // mismatched types between arms
- // E0300, // unexpanded macro
- // E0304, // expected signed integer constant
- // E0305, // expected constant
+// E0300, // unexpanded macro
+// E0304, // expected signed integer constant
+// E0305, // expected constant
E0311, // thing may not live long enough
E0312, // lifetime of reference outlives lifetime of borrowed content
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable