Consider the following erroneous definition of a type for a list of bytes:
-```compile_fail
+```compile_fail,E0072
// 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
+```compile_fail,E0109
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
+```compile_fail,E0110
type X = u32<'static>; // error: lifetime parameters are not allowed on
// this type
```
Erroneous code example:
-```compile_fail
+```compile_fail,E0133
unsafe fn f() { return; } // This is the unsafe code
fn main() {
Erroneous code example:
-```compile_fail
+```compile_fail,E0137
#![feature(main)]
#[main]
Erroneous code example:
-```compile_fail
+```compile_fail,E0138
#![feature(start)]
#[start]
```
"##,
-// FIXME link this to the relevant turpl chapters for instilling fear of the
-// transmute gods in the user
+// isn't thrown anymore
E0139: r##"
There are various restrictions on transmuting between types in Rust; for example
types being transmuted must have the same size. To apply all these restrictions,
So, for example, the following is not allowed:
-```compile_fail
+```
+use std::mem::transmute;
+
struct Foo<T>(Vec<T>);
fn foo<T>(x: Vec<T>) {
- // we are transmuting between Vec<T> and Foo<T> here
+ // we are transmuting between Vec<T> and Foo<F> here
let y: Foo<T> = unsafe { transmute(x) };
// do something with y
}
Erroneous code example:
-```compile_fail
+```compile_fail,E0152
#![feature(lang_items)]
#[lang = "panic_fmt"]
An associated type binding was done outside of the type parameter declaration
and `where` clause. Erroneous code example:
-```compile_fail
+```compile_fail,E0229
pub trait Foo {
type A;
fn boo(&self) -> <Self as Foo>::A;
These two examples illustrate the problem:
-```compile_fail
+```compile_fail,E0261
// error, use of undeclared lifetime name `'a`
fn foo(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
+```compile_fail,E0262
// 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
+```compile_fail,E0263
// 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
+```compile_fail,E0264
#![feature(lang_items)]
extern "C" {
Functions must eventually return a value of their return type. For example, in
the following function:
-```compile_fail
-fn foo(x: u8) -> u8 {
- if x > 0 {
- x // alternatively, `return x`
- }
- // nothing here
+```compile_fail,E0269
+fn abracada_FAIL() -> String {
+ "this won't work".to_string();
}
```
Here is a basic example:
-```compile_fail
+```compile_fail,E0271
trait Trait { type AssociatedType; }
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
compiled:
```compile_fail
+#![feature(on_unimplemented)]
+
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
compiled:
```compile_fail
+#![feature(on_unimplemented)]
+
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
compiled:
```compile_fail
+#![feature(on_unimplemented)]
+
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
For example, in the following code:
-```compile_fail
+```compile_fail,E0275
trait Foo {}
struct Bar<T>(T);
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
+```compile_fail,E0276
trait Foo {
fn foo<T>(x: T);
}
You tried to use a type which doesn't implement some trait in a place which
expected that trait. Erroneous code example:
-```compile_fail
+```compile_fail,E0277
// here we declare the Foo trait with a bar method
trait Foo {
fn bar(&self);
Or in a generic context, an erroneous code example would look like:
-```compile_fail
+```compile_fail,E0277
fn some_func<T>(foo: T) {
println!("{:?}", foo); // error: the trait `core::fmt::Debug` is not
// implemented for the type `T`
which expected that trait. This error typically occurs when working with
`Fn`-based types. Erroneous code example:
-```compile_fail
+```compile_fail,E0281
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
+```compile_fail,E0282
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
+```compile_fail,E0282
struct Foo<T> {
num: T,
}
For example:
-```compile_fail
+```compile_fail,E0283
trait Generator {
fn create() -> u32;
}
E0296: r##"
This error indicates that the given recursion limit could not be parsed. Ensure
-that the value provided is a positive integer between quotes, like so:
+that the value provided is a positive integer between quotes.
+
+Erroneous code example:
+
+```compile_fail,E0296
+#![recursion_limit]
+
+fn main() {}
+```
+
+And a working example:
```
#![recursion_limit="1000"]
+
+fn main() {}
```
"##,
For example:
-```compile_fail
+```compile_fail,E0308
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
+```compile_fail,E0308
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
+```compile_fail,E0309
// 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> {
must be as long as the data needs to be alive, and missing the constraint that
denotes this will cause this error.
-```compile_fail
+```compile_fail,E0310
// This won't compile because T is not constrained to the static lifetime
// the reference needs
struct Foo<T> {
E0452: r##"
An invalid lint attribute has been given. Erroneous code example:
-```compile_fail
+```compile_fail,E0452
#![allow(foo = "")] // error: malformed lint attribute
```
Example of erroneous code:
-```compile_fail
+```compile_fail,E0453
#![forbid(non_snake_case)]
#[allow(non_snake_case)]
E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:
-```compile_fail
+```compile_fail,E0496
struct Foo<'a> {
a: &'a i32,
}
Transmute with two differently sized types was attempted. Erroneous code
example:
-```compile_fail
+```compile_fail,E0512
fn takes_u8(_: u8) {}
fn main() {
Examples of erroneous code:
-```compile_fail
+```compile_fail,E0517
#[repr(C)]
type Foo = u8;
Examples of erroneous code:
-```compile_fail
+```compile_fail,E0518
#[inline(always)]
struct Foo;
invoked (such as the handler for out-of-bounds accesses when indexing a slice).
Erroneous code example:
-```compile_fail
+```compile_fail,E0522
#![feature(lang_items)]
#[lang = "cookie"]