mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-28 03:07:24 +03:00
Auto merge of #35431 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
This commit is contained in:
@@ -1399,6 +1399,38 @@ struct Foo<T: 'static> {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0312: r##"
|
||||
A lifetime of reference outlives lifetime of borrowed content.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0312
|
||||
fn make_child<'human, 'elve>(x: &mut &'human isize, y: &mut &'elve isize) {
|
||||
*x = *y;
|
||||
// error: lifetime of reference outlives lifetime of borrowed content
|
||||
}
|
||||
```
|
||||
|
||||
The compiler cannot determine if the `human` lifetime will live long enough
|
||||
to keep up on the elve one. To solve this error, you have to give an
|
||||
explicit lifetime hierarchy:
|
||||
|
||||
```
|
||||
fn make_child<'human, 'elve: 'human>(x: &mut &'human isize,
|
||||
y: &mut &'elve isize) {
|
||||
*x = *y; // ok!
|
||||
}
|
||||
```
|
||||
|
||||
Or use the same lifetime for every variable:
|
||||
|
||||
```
|
||||
fn make_child<'elve>(x: &mut &'elve isize, y: &mut &'elve isize) {
|
||||
*x = *y; // ok!
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
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
|
||||
@@ -1674,7 +1706,6 @@ fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
|
||||
// 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
|
||||
E0314, // closure outlives stack frame
|
||||
E0315, // cannot invoke closure outside of its lifetime
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
when that data may no longer exist. It's most commonly seen when attempting to
|
||||
return a closure:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0373
|
||||
fn foo() -> Box<Fn(u32) -> u32> {
|
||||
let x = 0u32;
|
||||
Box::new(|y| x + y)
|
||||
@@ -31,7 +31,7 @@ fn foo() -> Box<Fn(u32) -> u32> {
|
||||
|
||||
Another situation where this might be encountered is when spawning threads:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0373
|
||||
fn foo() {
|
||||
let x = 0u32;
|
||||
let y = 1u32;
|
||||
@@ -66,7 +66,7 @@ fn foo() -> Box<Fn(u32) -> u32> {
|
||||
E0381: r##"
|
||||
It is not allowed to use or capture an uninitialized variable. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0381
|
||||
fn main() {
|
||||
let x: i32;
|
||||
let y = x; // error, use of possibly uninitialized variable
|
||||
@@ -88,7 +88,7 @@ fn main() {
|
||||
This error occurs when an attempt is made to use a variable after its contents
|
||||
have been moved elsewhere. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0382
|
||||
struct MyStruct { s: u32 }
|
||||
|
||||
fn main() {
|
||||
@@ -180,8 +180,8 @@ struct Foo {
|
||||
This error occurs when an attempt is made to reassign an immutable variable.
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
fn main(){
|
||||
```compile_fail,E0384
|
||||
fn main() {
|
||||
let x = 3;
|
||||
x = 5; // error, reassignment of immutable variable
|
||||
}
|
||||
@@ -191,7 +191,7 @@ fn main(){
|
||||
`mut` after the keyword `let` when declaring the variable. For example:
|
||||
|
||||
```
|
||||
fn main(){
|
||||
fn main() {
|
||||
let mut x = 3;
|
||||
x = 5;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ fn main(){
|
||||
|
||||
For example, this can happen when storing a `&mut` inside an immutable `Box`:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0386
|
||||
let mut x: i64 = 1;
|
||||
let y: Box<_> = Box::new(&mut x);
|
||||
**y = 2; // error, cannot assign to data in an immutable container
|
||||
@@ -234,7 +234,7 @@ fn main(){
|
||||
This error occurs when an attempt is made to mutate or mutably reference data
|
||||
that a closure has captured immutably. Examples of this error are shown below:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0387
|
||||
// Accepts a function or a closure that captures its environment immutably.
|
||||
// Closures passed to foo will not be able to mutate their closed-over state.
|
||||
fn foo<F: Fn()>(f: F) { }
|
||||
@@ -286,6 +286,30 @@ fn mutable() {
|
||||
https://doc.rust-lang.org/std/cell/
|
||||
"##,
|
||||
|
||||
E0388: r##"
|
||||
A mutable borrow was attempted in a static location.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0388
|
||||
static X: i32 = 1;
|
||||
|
||||
static STATIC_REF: &'static mut i32 = &mut X;
|
||||
// error: cannot borrow data mutably in a static location
|
||||
|
||||
const CONST_REF: &'static mut i32 = &mut X;
|
||||
// error: cannot borrow data mutably in a static location
|
||||
```
|
||||
|
||||
To fix this error, you have to use constant borrow:
|
||||
|
||||
```
|
||||
static X: i32 = 1;
|
||||
|
||||
static STATIC_REF: &'static i32 = &X;
|
||||
```
|
||||
"##,
|
||||
|
||||
E0389: r##"
|
||||
An attempt was made to mutate data using a non-mutable reference. This
|
||||
commonly occurs when attempting to assign to a non-mutable reference of a
|
||||
@@ -293,9 +317,9 @@ fn mutable() {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0389
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -315,7 +339,7 @@ fn main() {
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -353,7 +377,7 @@ fn main() {
|
||||
E0499: r##"
|
||||
A variable was borrowed as mutable more than once. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0499
|
||||
let mut i = 0;
|
||||
let mut x = &mut i;
|
||||
let mut a = &mut i;
|
||||
@@ -438,7 +462,7 @@ fn you_know_nothing(jon_snow: &mut i32) {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0501
|
||||
fn inside_closure(x: &mut i32) {
|
||||
// Actions which require unique access
|
||||
}
|
||||
@@ -508,7 +532,7 @@ fn foo(a: &mut i32) {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0502
|
||||
fn bar(x: &mut i32) {}
|
||||
fn foo(a: &mut i32) {
|
||||
let ref y = a; // a is borrowed as immutable.
|
||||
@@ -537,7 +561,7 @@ fn foo(a: &mut i32) {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0503
|
||||
fn main() {
|
||||
let mut value = 3;
|
||||
// Create a mutable borrow of `value`. This borrow
|
||||
@@ -594,9 +618,9 @@ fn main() {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0504
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -622,7 +646,7 @@ fn main() {
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -645,7 +669,7 @@ fn main() {
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -674,7 +698,7 @@ fn main() {
|
||||
use std::thread;
|
||||
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -692,95 +716,12 @@ fn main() {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0506: r##"
|
||||
This error occurs when an attempt is made to assign to a borrowed value.
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
let fancy_ref = &fancy_num;
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
// error: cannot assign to `fancy_num` because it is borrowed
|
||||
|
||||
println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
|
||||
}
|
||||
```
|
||||
|
||||
Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't
|
||||
be assigned to a new value as it would invalidate the reference.
|
||||
|
||||
Alternatively, we can move out of `fancy_num` into a second `fancy_num`:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
let moved_num = fancy_num;
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
|
||||
println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num);
|
||||
}
|
||||
```
|
||||
|
||||
If the value has to be borrowed, try limiting the lifetime of the borrow using
|
||||
a scoped block:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
|
||||
{
|
||||
let fancy_ref = &fancy_num;
|
||||
println!("Ref: {}", fancy_ref.num);
|
||||
}
|
||||
|
||||
// Works because `fancy_ref` is no longer in scope
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
println!("Num: {}", fancy_num.num);
|
||||
}
|
||||
```
|
||||
|
||||
Or by moving the reference into a function:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
|
||||
print_fancy_ref(&fancy_num);
|
||||
|
||||
// Works because function borrow has ended
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
println!("Num: {}", fancy_num.num);
|
||||
}
|
||||
|
||||
fn print_fancy_ref(fancy_ref: &FancyNum){
|
||||
println!("Ref: {}", fancy_ref.num);
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0505: r##"
|
||||
A value was moved out while it was still borrowed.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0505
|
||||
struct Value {}
|
||||
|
||||
fn eat(val: Value) {}
|
||||
@@ -855,10 +796,94 @@ fn main() {
|
||||
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
|
||||
"##,
|
||||
|
||||
E0506: r##"
|
||||
This error occurs when an attempt is made to assign to a borrowed value.
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail,E0506
|
||||
struct FancyNum {
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
let fancy_ref = &fancy_num;
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
// error: cannot assign to `fancy_num` because it is borrowed
|
||||
|
||||
println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
|
||||
}
|
||||
```
|
||||
|
||||
Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't
|
||||
be assigned to a new value as it would invalidate the reference.
|
||||
|
||||
Alternatively, we can move out of `fancy_num` into a second `fancy_num`:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
let moved_num = fancy_num;
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
|
||||
println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num);
|
||||
}
|
||||
```
|
||||
|
||||
If the value has to be borrowed, try limiting the lifetime of the borrow using
|
||||
a scoped block:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
|
||||
{
|
||||
let fancy_ref = &fancy_num;
|
||||
println!("Ref: {}", fancy_ref.num);
|
||||
}
|
||||
|
||||
// Works because `fancy_ref` is no longer in scope
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
println!("Num: {}", fancy_num.num);
|
||||
}
|
||||
```
|
||||
|
||||
Or by moving the reference into a function:
|
||||
|
||||
```
|
||||
struct FancyNum {
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy_num = FancyNum { num: 5 };
|
||||
|
||||
print_fancy_ref(&fancy_num);
|
||||
|
||||
// Works because function borrow has ended
|
||||
fancy_num = FancyNum { num: 6 };
|
||||
println!("Num: {}", fancy_num.num);
|
||||
}
|
||||
|
||||
fn print_fancy_ref(fancy_ref: &FancyNum){
|
||||
println!("Ref: {}", fancy_ref.num);
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0507: r##"
|
||||
You tried to move out of a value which was borrowed. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0507
|
||||
use std::cell::RefCell;
|
||||
|
||||
struct TheDarkKnight;
|
||||
@@ -975,7 +1000,7 @@ fn main() {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0508
|
||||
struct NonCopy;
|
||||
|
||||
fn main() {
|
||||
@@ -1020,7 +1045,7 @@ fn main() {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0509
|
||||
struct FancyNum {
|
||||
num: usize
|
||||
}
|
||||
@@ -1113,6 +1138,5 @@ fn main() {
|
||||
|
||||
register_diagnostics! {
|
||||
E0385, // {} in an aliasable location
|
||||
E0388, // {} in a static location
|
||||
E0524, // two closures require unique access to `..` at the same time
|
||||
}
|
||||
|
||||
+157
-153
@@ -43,7 +43,7 @@ enum Fruit {
|
||||
|
||||
Matching with the wrong number of fields has no sensible interpretation:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0023
|
||||
enum Fruit {
|
||||
Apple(String, String),
|
||||
Pear(u32),
|
||||
@@ -66,7 +66,7 @@ enum Fruit {
|
||||
Each field of a struct can only be bound once in a pattern. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0025
|
||||
struct Foo {
|
||||
a: u8,
|
||||
b: u8,
|
||||
@@ -123,7 +123,7 @@ struct Thing {
|
||||
|
||||
Change this:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0026
|
||||
struct Thing {
|
||||
x: u32,
|
||||
y: u32
|
||||
@@ -159,7 +159,7 @@ struct Thing {
|
||||
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0027
|
||||
struct Dog {
|
||||
name: String,
|
||||
age: u32,
|
||||
@@ -201,7 +201,9 @@ struct Dog {
|
||||
want to capture values of an orderable type between two end-points, you can use
|
||||
a guard.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0029
|
||||
let string = "salutations !";
|
||||
|
||||
// The ordering relation for strings can't be evaluated at compile time,
|
||||
// so this doesn't work:
|
||||
match string {
|
||||
@@ -245,7 +247,7 @@ struct Dog {
|
||||
The compiler doesn't know what method to call because more than one method
|
||||
has the same prototype. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0034
|
||||
struct Test;
|
||||
|
||||
trait Trait1 {
|
||||
@@ -332,7 +334,7 @@ fn main() {
|
||||
You tried to give a type parameter where it wasn't needed. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0035
|
||||
struct Test;
|
||||
|
||||
impl Test {
|
||||
@@ -367,7 +369,7 @@ fn main() {
|
||||
This error occurrs when you pass too many or not enough type parameters to
|
||||
a method. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0036
|
||||
struct Test;
|
||||
|
||||
impl Test {
|
||||
@@ -417,7 +419,7 @@ fn main() {
|
||||
|
||||
Here's an example of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0040
|
||||
struct Foo {
|
||||
x: i32,
|
||||
}
|
||||
@@ -438,7 +440,7 @@ fn main() {
|
||||
E0044: r##"
|
||||
You can't use type parameters on foreign items. Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0044
|
||||
extern { fn some_func<T>(x: T); }
|
||||
```
|
||||
|
||||
@@ -456,7 +458,9 @@ fn main() {
|
||||
FFI. As such, variadic parameters can only be used with functions which are
|
||||
using the C ABI. Examples of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0045
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
extern "rust-call" { fn foo(x: u8, ...); }
|
||||
|
||||
// or
|
||||
@@ -466,12 +470,6 @@ fn foo(x: u8, ...) {}
|
||||
|
||||
To fix such code, put them in an extern "C" block:
|
||||
|
||||
```ignore
|
||||
extern "C" fn foo(x: u8, ...);
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```
|
||||
extern "C" {
|
||||
fn foo (x: u8, ...);
|
||||
@@ -482,7 +480,7 @@ fn foo(x: u8, ...) {}
|
||||
E0046: r##"
|
||||
Items are missing in a trait implementation. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0046
|
||||
trait Foo {
|
||||
fn foo();
|
||||
}
|
||||
@@ -518,7 +516,7 @@ fn foo() {} // ok!
|
||||
For example, the trait below has a method `foo` with a type parameter `T`,
|
||||
but the implementation of `foo` for the type `Bar` is missing this parameter:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0049
|
||||
trait Foo {
|
||||
fn foo<T: Default>(x: T) -> Self;
|
||||
}
|
||||
@@ -541,7 +539,7 @@ fn foo(x: bool) -> Self { Bar }
|
||||
(`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits
|
||||
the `u8` parameter:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0050
|
||||
trait Foo {
|
||||
fn foo(&self, x: u8) -> bool;
|
||||
}
|
||||
@@ -562,7 +560,7 @@ fn foo(&self) -> bool { true }
|
||||
|
||||
Here are a couple examples of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0053
|
||||
trait Foo {
|
||||
fn foo(x: u16);
|
||||
fn bar(&self);
|
||||
@@ -584,7 +582,7 @@ fn bar(&mut self) { }
|
||||
It is not allowed to cast to a bool. If you are trying to cast a numeric type
|
||||
to a bool, you can compare it with zero instead:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0054
|
||||
let x = 5;
|
||||
|
||||
// Not allowed, won't compile
|
||||
@@ -607,7 +605,7 @@ fn bar(&mut self) { }
|
||||
|
||||
For a somewhat artificial example:
|
||||
|
||||
```compile_fail,ignore
|
||||
```compile_fail,E0055
|
||||
#![recursion_limit="2"]
|
||||
|
||||
struct Foo;
|
||||
@@ -637,7 +635,7 @@ fn main() {
|
||||
|
||||
An example using a closure:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0057
|
||||
let f = |x| x * 3;
|
||||
let a = f(); // invalid, too few parameters
|
||||
let b = f(4); // this works!
|
||||
@@ -663,13 +661,17 @@ fn foo<F: Fn()>(f: F) {
|
||||
The most likely source of this error is using angle-bracket notation without
|
||||
wrapping the function argument type into a tuple, for example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0059
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
|
||||
```
|
||||
|
||||
It can be fixed by adjusting the trait bound like this:
|
||||
|
||||
```ignore
|
||||
```
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
|
||||
```
|
||||
|
||||
@@ -726,9 +728,9 @@ fn f(a: u16, b: &str) {}
|
||||
enum variant, one of the fields was specified more than once. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0062
|
||||
struct Foo {
|
||||
x: i32
|
||||
x: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -743,7 +745,7 @@ fn main() {
|
||||
|
||||
```
|
||||
struct Foo {
|
||||
x: i32
|
||||
x: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -756,10 +758,10 @@ fn main() {
|
||||
This error indicates that during an attempt to build a struct or struct-like
|
||||
enum variant, one of the fields was not provided. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0063
|
||||
struct Foo {
|
||||
x: i32,
|
||||
y: i32
|
||||
y: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -772,7 +774,7 @@ fn main() {
|
||||
```
|
||||
struct Foo {
|
||||
x: i32,
|
||||
y: i32
|
||||
y: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -799,7 +801,7 @@ fn main() {
|
||||
|
||||
Let's start with some erroneous code examples:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0067
|
||||
use std::collections::LinkedList;
|
||||
|
||||
// Bad: assignment to non-lvalue expression
|
||||
@@ -831,7 +833,7 @@ fn some_func(i: &mut i32) {
|
||||
The compiler found a function whose body contains a `return;` statement but
|
||||
whose return type is not `()`. An example of this is:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0069
|
||||
// error
|
||||
fn foo() -> u8 {
|
||||
return;
|
||||
@@ -853,7 +855,7 @@ fn foo() -> u8 {
|
||||
|
||||
Now, we can go further. Here are some erroneous code examples:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0070
|
||||
struct SomeStruct {
|
||||
x: i32,
|
||||
y: i32
|
||||
@@ -897,7 +899,7 @@ fn some_func(x: &mut i32) {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0071
|
||||
enum Foo { FirstValue(i32) };
|
||||
|
||||
let u = Foo::FirstValue { value: 0 }; // error: Foo::FirstValue
|
||||
@@ -976,7 +978,7 @@ struct Foo { x: Option<Box<Foo>> }
|
||||
|
||||
This will cause an error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0075
|
||||
#![feature(repr_simd)]
|
||||
|
||||
#[repr(simd)]
|
||||
@@ -1000,7 +1002,7 @@ struct Foo { x: Option<Box<Foo>> }
|
||||
|
||||
This will cause an error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0076
|
||||
#![feature(repr_simd)]
|
||||
|
||||
#[repr(simd)]
|
||||
@@ -1023,7 +1025,7 @@ struct Foo { x: Option<Box<Foo>> }
|
||||
|
||||
This will cause an error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0077
|
||||
#![feature(repr_simd)]
|
||||
|
||||
#[repr(simd)]
|
||||
@@ -1047,9 +1049,9 @@ struct Foo { x: Option<Box<Foo>> }
|
||||
|
||||
For example, in the following code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0079
|
||||
enum Foo {
|
||||
Q = "32"
|
||||
Q = "32",
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1060,7 +1062,7 @@ enum Foo {
|
||||
|
||||
```
|
||||
enum Foo {
|
||||
Q = 32
|
||||
Q = 32,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1084,12 +1086,12 @@ fn get_str(&self) -> &'static str {
|
||||
This error indicates that the same value was used for two or more variants,
|
||||
making them impossible to tell apart.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0081
|
||||
// Bad.
|
||||
enum Enum {
|
||||
P = 3,
|
||||
X = 3,
|
||||
Y = 5
|
||||
Y = 5,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1098,7 +1100,7 @@ enum Enum {
|
||||
enum Enum {
|
||||
P,
|
||||
X = 3,
|
||||
Y = 5
|
||||
Y = 5,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1106,7 +1108,7 @@ enum Enum {
|
||||
top to bottom starting from 0, so clashes can occur with seemingly unrelated
|
||||
variants.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0081
|
||||
enum Bad {
|
||||
X,
|
||||
Y = 0
|
||||
@@ -1128,7 +1130,7 @@ enum Bad {
|
||||
#[repr(u8)]
|
||||
enum Thing {
|
||||
A = 1024,
|
||||
B = 5
|
||||
B = 5,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1137,7 +1139,7 @@ enum Thing {
|
||||
|
||||
```ignore
|
||||
enum DependsOnPointerSize {
|
||||
A = 1 << 32
|
||||
A = 1 << 32,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1153,7 +1155,7 @@ enum DependsOnPointerSize {
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0084
|
||||
#[repr(i32)]
|
||||
enum NightsWatch {} // error: unsupported representation for zero-variant enum
|
||||
```
|
||||
@@ -1181,7 +1183,7 @@ enum NightsWatch {}
|
||||
E0087: r##"
|
||||
Too many type parameters were supplied for a function. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0087
|
||||
fn foo<T>() {}
|
||||
|
||||
fn main() {
|
||||
@@ -1196,7 +1198,7 @@ fn main() {
|
||||
E0088: r##"
|
||||
You gave too many lifetime parameters. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0088
|
||||
fn f() {}
|
||||
|
||||
fn main() {
|
||||
@@ -1241,7 +1243,7 @@ fn main() {
|
||||
E0089: r##"
|
||||
Not enough type parameters were supplied for a function. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0089
|
||||
fn foo<T, U>() {}
|
||||
|
||||
fn main() {
|
||||
@@ -1252,7 +1254,7 @@ fn main() {
|
||||
Note that if a function takes multiple type parameters but you want the compiler
|
||||
to infer some of them, you can use type placeholders:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0089
|
||||
fn foo<T, U>(x: T) {}
|
||||
|
||||
fn main() {
|
||||
@@ -1267,7 +1269,7 @@ fn main() {
|
||||
You gave an unnecessary type parameter in a type alias. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0091
|
||||
type Foo<T> = u32; // error: type parameter `T` is unused
|
||||
// or:
|
||||
type Foo<A,B> = Box<A>; // error: type parameter `B` is unused
|
||||
@@ -1285,7 +1287,7 @@ fn main() {
|
||||
You tried to declare an undefined atomic operation function.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0092
|
||||
#![feature(intrinsics)]
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
@@ -1310,7 +1312,7 @@ fn main() {
|
||||
E0093: r##"
|
||||
You declared an unknown intrinsic function. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0093
|
||||
#![feature(intrinsics)]
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
@@ -1347,7 +1349,7 @@ fn main() {
|
||||
You gave an invalid number of type parameters to an intrinsic function.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0094
|
||||
#![feature(intrinsics)]
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
@@ -1373,10 +1375,8 @@ fn main() {
|
||||
You hit this error because the compiler lacks the information to
|
||||
determine a type for this expression. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
fn main() {
|
||||
let x = |_| {}; // error: cannot determine a type for this expression
|
||||
}
|
||||
```compile_fail,E0101
|
||||
let x = |_| {}; // error: cannot determine a type for this expression
|
||||
```
|
||||
|
||||
You have two possibilities to solve this situation:
|
||||
@@ -1386,12 +1386,10 @@ fn main() {
|
||||
Examples:
|
||||
|
||||
```
|
||||
fn main() {
|
||||
let x = |_ : u32| {}; // ok!
|
||||
// or:
|
||||
let x = |_| {};
|
||||
x(0u32);
|
||||
}
|
||||
let x = |_ : u32| {}; // ok!
|
||||
// or:
|
||||
let x = |_| {};
|
||||
x(0u32);
|
||||
```
|
||||
"##,
|
||||
|
||||
@@ -1399,11 +1397,9 @@ fn main() {
|
||||
You hit this error because the compiler lacks the information to
|
||||
determine the type of this variable. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
fn main() {
|
||||
// could be an array of anything
|
||||
let x = []; // error: cannot determine a type for this local variable
|
||||
}
|
||||
```compile_fail,E0102
|
||||
// could be an array of anything
|
||||
let x = []; // error: cannot determine a type for this local variable
|
||||
```
|
||||
|
||||
To solve this situation, constrain the type of the variable.
|
||||
@@ -1425,7 +1421,7 @@ fn main() {
|
||||
|
||||
Here are some simple examples of where you'll run into this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0106
|
||||
struct Foo { x: &bool } // error
|
||||
struct Foo<'a> { x: &'a bool } // correct
|
||||
|
||||
@@ -1453,7 +1449,7 @@ enum Bar<'a> { A(u8), B(&'a bool), } // correct
|
||||
|
||||
Here are some examples of elision errors:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0106
|
||||
// error, no input lifetimes
|
||||
fn foo() -> &str { }
|
||||
|
||||
@@ -1473,7 +1469,7 @@ fn baz<'a>(x: &'a str, y: &str) -> &str { }
|
||||
|
||||
Some basic examples include:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0107
|
||||
struct Foo<'a>(&'a str);
|
||||
enum Bar { A, B, C }
|
||||
|
||||
@@ -1486,7 +1482,7 @@ struct Baz<'a> {
|
||||
Here's an example that is currently an error, but may work in a future version
|
||||
of Rust:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0107
|
||||
struct Foo<'a>(&'a str);
|
||||
|
||||
trait Quux { }
|
||||
@@ -1504,7 +1500,7 @@ impl Quux for Foo { } // error: expected 1, found 0
|
||||
where the type was defined. For example, an `impl` block as below is not allowed
|
||||
since `Vec` is defined in the standard library:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0116
|
||||
impl Vec<u8> { } // error
|
||||
```
|
||||
|
||||
@@ -1518,7 +1514,7 @@ impl Vec<u8> { } // error
|
||||
Note that using the `type` keyword does not work here because `type` only
|
||||
introduces a type alias:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0116
|
||||
type Bytes = Vec<u8>;
|
||||
|
||||
impl Bytes { } // error, same as above
|
||||
@@ -1536,7 +1532,7 @@ trait defined in another crate) where
|
||||
|
||||
Here's one example of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0117
|
||||
impl Drop for u32 {}
|
||||
```
|
||||
|
||||
@@ -1579,7 +1575,7 @@ fn get(&self) -> usize { 0 }
|
||||
You're trying to write an inherent implementation for something which isn't a
|
||||
struct nor an enum. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0118
|
||||
impl (u8, u8) { // error: no base type found for inherent implementation
|
||||
fn get_state(&self) -> String {
|
||||
// ...
|
||||
@@ -1623,7 +1619,7 @@ fn get_state(&self) -> String {
|
||||
There are conflicting trait implementations for the same type.
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0119
|
||||
trait MyTrait {
|
||||
fn get(&self) -> usize;
|
||||
}
|
||||
@@ -1684,7 +1680,7 @@ fn main() {
|
||||
An attempt was made to implement Drop on a trait, which is not allowed: only
|
||||
structs and enums can implement Drop. An example causing this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0120
|
||||
trait MyTrait {}
|
||||
|
||||
impl Drop for MyTrait {
|
||||
@@ -1725,7 +1721,7 @@ fn drop(&mut self) {}
|
||||
|
||||
Examples of this error include:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0121
|
||||
fn foo() -> _ { 5 } // error, explicitly write out the return type instead
|
||||
|
||||
static BAR: _ = "test"; // error, explicitly write out the type instead
|
||||
@@ -1756,7 +1752,7 @@ fn main() {
|
||||
You declared two fields of a struct with the same name. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0124
|
||||
struct Foo {
|
||||
field1: i32,
|
||||
field1: i32, // error: field is already declared
|
||||
@@ -1777,7 +1773,7 @@ struct Foo {
|
||||
Type parameter defaults can only use parameters that occur before them.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0128
|
||||
struct Foo<T=U, U=()> {
|
||||
field1: T,
|
||||
filed2: U,
|
||||
@@ -1805,7 +1801,7 @@ struct Foo<U=(), T=U> {
|
||||
parameters. When `main` is present, it must take no arguments and return `()`.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0131
|
||||
fn main<T>() { // error: main function is not allowed to have type parameters
|
||||
}
|
||||
```
|
||||
@@ -1816,7 +1812,7 @@ fn main<T>() { // error: main function is not allowed to have type parameters
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0132
|
||||
#![feature(start)]
|
||||
|
||||
#[start]
|
||||
@@ -1847,7 +1843,7 @@ fn my_start(argc: isize, argv: *const *const u8) -> isize {
|
||||
This error means that an attempt was made to match a struct type enum
|
||||
variant as a non-struct type:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0164
|
||||
enum Foo { B { i: u32 } }
|
||||
|
||||
fn bar(foo: Foo) -> u32 {
|
||||
@@ -1875,7 +1871,7 @@ fn bar(foo: Foo) -> u32 {
|
||||
marked as diverging. A function diverges if it has `!` in the place of the
|
||||
return type in its signature. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0166
|
||||
fn foo() -> ! { return; } // error
|
||||
```
|
||||
|
||||
@@ -1888,7 +1884,7 @@ fn bar(foo: Foo) -> u32 {
|
||||
This error means that an attempt was made to specify the type of a variable with
|
||||
a combination of a concrete type and a trait. Consider the following example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0172
|
||||
fn foo(bar: i32+std::fmt::Display) {}
|
||||
```
|
||||
|
||||
@@ -1917,7 +1913,7 @@ fn foo(bar: i32) {}
|
||||
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0178
|
||||
trait Foo {}
|
||||
|
||||
struct Bar<'a> {
|
||||
@@ -1949,7 +1945,7 @@ struct Bar<'a> {
|
||||
|
||||
Here's an example of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0185
|
||||
trait Foo {
|
||||
fn foo();
|
||||
}
|
||||
@@ -1971,7 +1967,7 @@ fn foo(&self) {}
|
||||
|
||||
Here's an example of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0186
|
||||
trait Foo {
|
||||
fn foo(&self);
|
||||
}
|
||||
@@ -1990,7 +1986,7 @@ fn foo() {}
|
||||
Trait objects need to have all associated types specified. Erroneous code
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0191
|
||||
trait Trait {
|
||||
type Bar;
|
||||
}
|
||||
@@ -2066,7 +2062,7 @@ fn bar(&self) { }
|
||||
A type parameter was declared which shadows an existing one. An example of this
|
||||
error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0194
|
||||
trait Foo<T> {
|
||||
fn do_something(&self) -> T;
|
||||
fn do_something_else<T: Clone>(&self, bar: T);
|
||||
@@ -2082,7 +2078,7 @@ trait Foo<T> {
|
||||
Your method's lifetime parameters do not match the trait declaration.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0195
|
||||
trait Trait {
|
||||
fn bar<'a,'b:'a>(x: &'a str, y: &'b str);
|
||||
}
|
||||
@@ -2121,7 +2117,7 @@ fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
|
||||
implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
|
||||
implementation will resolve this error.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0197
|
||||
struct Foo;
|
||||
|
||||
// this will cause this error
|
||||
@@ -2168,7 +2164,7 @@ impl !Enterprise for Foo { }
|
||||
implementation for a safe trait unsafe will cause a compiler error. Removing
|
||||
the unsafe marker on the trait noted in the error will resolve this problem.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0199
|
||||
struct Foo;
|
||||
|
||||
trait Bar { }
|
||||
@@ -2185,7 +2181,7 @@ impl Bar for Foo { }
|
||||
implementation for an unsafe trait isn't marked as unsafe. This may be resolved
|
||||
by marking the unsafe implementation as unsafe.
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0200
|
||||
struct Foo;
|
||||
|
||||
unsafe trait Bar { }
|
||||
@@ -2203,7 +2199,7 @@ unsafe impl Bar for Foo { }
|
||||
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0201
|
||||
struct Foo(u8);
|
||||
|
||||
impl Foo {
|
||||
@@ -2258,7 +2254,7 @@ fn bar(&self) -> bool { self.0 }
|
||||
fields does not implement `Copy`. To fix this, you must implement `Copy` for the
|
||||
mentioned field. Note that this may not be possible, as in the example of
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0204
|
||||
struct Foo {
|
||||
foo : Vec<u32>,
|
||||
}
|
||||
@@ -2270,7 +2266,7 @@ impl Copy for Foo { }
|
||||
|
||||
Here's another example that will fail:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0204
|
||||
#[derive(Copy)]
|
||||
struct Foo<'a> {
|
||||
ty: &'a mut bool,
|
||||
@@ -2286,7 +2282,7 @@ struct Foo<'a> {
|
||||
variants does not implement `Copy`. To fix this, you must implement `Copy` for
|
||||
the mentioned variant. Note that this may not be possible, as in the example of
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0205
|
||||
enum Foo {
|
||||
Bar(Vec<u32>),
|
||||
Baz,
|
||||
@@ -2299,11 +2295,11 @@ impl Copy for Foo { }
|
||||
|
||||
Here's another example that will fail:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0205
|
||||
#[derive(Copy)]
|
||||
enum Foo<'a> {
|
||||
Bar(&'a mut bool),
|
||||
Baz
|
||||
Baz,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2316,7 +2312,7 @@ enum Foo<'a> {
|
||||
examples will fail, because neither `i32` (primitive type) nor `&'static Bar`
|
||||
(reference to `Bar`) is a struct or enum:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0206
|
||||
type Foo = i32;
|
||||
impl Copy for Foo { } // error
|
||||
|
||||
@@ -2339,7 +2335,7 @@ impl Copy for &'static Bar { } // error
|
||||
Suppose we have a struct `Foo` and we would like to define some methods for it.
|
||||
The following definition leads to a compiler error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0207
|
||||
struct Foo;
|
||||
|
||||
impl<T: Default> Foo {
|
||||
@@ -2372,7 +2368,7 @@ fn get<T: Default>(&self) -> T {
|
||||
As another example, suppose we have a `Maker` trait and want to establish a
|
||||
type `FooMaker` that makes `Foo`s:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0207
|
||||
trait Maker {
|
||||
type Item;
|
||||
fn make(&mut self) -> Self::Item;
|
||||
@@ -2468,11 +2464,13 @@ fn make(&mut self) -> Foo<T> {
|
||||
If `ForeignTrait` is a trait defined in some external crate `foo`, then the
|
||||
following trait `impl` is an error:
|
||||
|
||||
```compile_fail
|
||||
extern crate foo;
|
||||
use foo::ForeignTrait;
|
||||
```compile_fail,E0210
|
||||
extern crate collections;
|
||||
use collections::range::RangeArgument;
|
||||
|
||||
impl<T> ForeignTrait for T { } // error
|
||||
impl<T> RangeArgument<T> for T { } // error
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
To work around this, it can be covered with a local type, `MyType`:
|
||||
@@ -2611,7 +2609,7 @@ fn x(self: Box<Foo>) {} // ok!
|
||||
A generic type was described using parentheses rather than angle brackets. For
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0214
|
||||
fn main() {
|
||||
let v: Vec(&str) = vec!["foo"];
|
||||
}
|
||||
@@ -2626,7 +2624,7 @@ fn main() {
|
||||
You used an associated type which isn't defined in the trait.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0220
|
||||
trait T1 {
|
||||
type Bar;
|
||||
}
|
||||
@@ -2670,7 +2668,7 @@ trait T2 {
|
||||
An attempt was made to retrieve an associated type, but the type was ambiguous.
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0221
|
||||
trait T1 {}
|
||||
trait T2 {}
|
||||
|
||||
@@ -2716,7 +2714,7 @@ fn do_something() {
|
||||
An attempt was made to retrieve an associated type, but the type was ambiguous.
|
||||
For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0223
|
||||
trait MyTrait {type X; }
|
||||
|
||||
fn main() {
|
||||
@@ -2751,7 +2749,7 @@ fn main() {
|
||||
You attempted to use multiple types as bounds for a closure or trait object.
|
||||
Rust does not currently support this. A simple example that causes this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0225
|
||||
fn main() {
|
||||
let _: Box<std::io::Read + std::io::Write>;
|
||||
}
|
||||
@@ -2771,7 +2769,7 @@ fn main() {
|
||||
E0232: r##"
|
||||
The attribute must have a value. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0232
|
||||
#![feature(on_unimplemented)]
|
||||
|
||||
#[rustc_on_unimplemented] // error: this attribute must have a value
|
||||
@@ -2795,7 +2793,7 @@ trait Bar {}
|
||||
For example, the `Foo` struct below is defined to be generic in `T`, but the
|
||||
type parameter is missing in the definition of `Bar`:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0243
|
||||
struct Foo<T> { x: T }
|
||||
|
||||
struct Bar { x: Foo }
|
||||
@@ -2809,7 +2807,7 @@ struct Bar { x: Foo }
|
||||
For example, the `Foo` struct below has no type parameters, but is supplied
|
||||
with two in the definition of `Bar`:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0244
|
||||
struct Foo { x: bool }
|
||||
|
||||
struct Bar<S, T> { x: Foo<S, T> }
|
||||
@@ -2820,7 +2818,7 @@ struct Bar<S, T> { x: Foo<S, T> }
|
||||
This error indicates an attempt to use a value where a type is expected. For
|
||||
example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0248
|
||||
enum Foo {
|
||||
Bar(u32)
|
||||
}
|
||||
@@ -2845,14 +2843,14 @@ fn do_something(x: Foo::Bar) { }
|
||||
A cross-crate opt-out trait was implemented on something which wasn't a struct
|
||||
or enum type. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0321
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl !Sync for Foo {}
|
||||
|
||||
unsafe impl Send for &'static Foo {
|
||||
unsafe impl Send for &'static Foo {}
|
||||
// error: cross-crate traits with a default impl, like `core::marker::Send`,
|
||||
// can only be implemented for a struct/enum type, not
|
||||
// `&'static Foo`
|
||||
@@ -2874,7 +2872,7 @@ unsafe impl Send for &'static Foo {
|
||||
An associated const was implemented when another trait item was expected.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0323
|
||||
#![feature(associated_consts)]
|
||||
|
||||
trait Foo {
|
||||
@@ -2926,7 +2924,9 @@ impl Foo for Bar {
|
||||
A method was implemented when another trait item was expected. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0324
|
||||
#![feature(associated_consts)]
|
||||
|
||||
struct Bar;
|
||||
|
||||
trait Foo {
|
||||
@@ -2968,7 +2968,9 @@ fn M() {} // ok!
|
||||
An associated type was implemented when another trait item was expected.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0325
|
||||
#![feature(associated_consts)]
|
||||
|
||||
struct Bar;
|
||||
|
||||
trait Foo {
|
||||
@@ -3020,7 +3022,9 @@ impl Foo for Bar {
|
||||
|
||||
Here's an example of this error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0326
|
||||
#![feature(associated_consts)]
|
||||
|
||||
trait Foo {
|
||||
const BAR: bool;
|
||||
}
|
||||
@@ -3078,7 +3082,7 @@ fn get_bar_good() -> f64 {
|
||||
An attempt was made to implement `Drop` on a concrete specialization of a
|
||||
generic type. An example is shown below:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0366
|
||||
struct Foo<T> {
|
||||
t: T
|
||||
}
|
||||
@@ -3111,7 +3115,7 @@ fn drop(&mut self) {}
|
||||
An attempt was made to implement `Drop` on a specialization of a generic type.
|
||||
An example is shown below:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0367
|
||||
trait Foo{}
|
||||
|
||||
struct MyStruct<T> {
|
||||
@@ -3149,7 +3153,7 @@ fn drop(&mut self) {}
|
||||
This error indicates that a binary assignment operator like `+=` or `^=` was
|
||||
applied to a type that doesn't support it. For example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0368
|
||||
let mut x = 12f32; // error: binary operation `<<` cannot be applied to
|
||||
// type `f32`
|
||||
|
||||
@@ -3172,7 +3176,7 @@ fn drop(&mut self) {}
|
||||
operator for some type `Foo` by implementing the `std::ops::Add` trait for
|
||||
`Foo`, but you find that using `+=` does not work, as in this example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0368
|
||||
use std::ops::Add;
|
||||
|
||||
struct Foo(u32);
|
||||
@@ -3199,7 +3203,7 @@ fn main() {
|
||||
A binary operation was attempted on a type which doesn't support it.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0369
|
||||
let x = 12f32; // error: binary operation `<<` cannot be applied to
|
||||
// type `f32`
|
||||
|
||||
@@ -3262,7 +3266,7 @@ enum Foo {
|
||||
|
||||
Example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0371
|
||||
trait Foo { fn foo(&self) { } }
|
||||
trait Bar: Foo { }
|
||||
trait Baz: Bar { }
|
||||
@@ -3283,7 +3287,7 @@ impl Baz for Bar { } // Note: This is OK
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0374
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
@@ -3342,7 +3346,7 @@ impl `CoerceUnsized` from `T` to `U` which are both types that the struct
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0375
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
@@ -3397,7 +3401,7 @@ fn coerce_foo<T: CoerceUnsized<U>, U>(t: T) -> Foo<U> {
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0376
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
@@ -3448,7 +3452,7 @@ impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
|
||||
E0390: r##"
|
||||
You tried to implement methods for a primitive type. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0390
|
||||
struct Foo {
|
||||
x: i32
|
||||
}
|
||||
@@ -3482,7 +3486,7 @@ fn bar() {} // ok!
|
||||
|
||||
The following example contains a circular dependency between two traits:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0391
|
||||
trait FirstTrait : SecondTrait {
|
||||
|
||||
}
|
||||
@@ -3497,9 +3501,9 @@ trait SecondTrait : FirstTrait {
|
||||
This error indicates that a type or lifetime parameter has been declared
|
||||
but not actually used. Here is an example that demonstrates the error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0392
|
||||
enum Foo<T> {
|
||||
Bar
|
||||
Bar,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3508,7 +3512,7 @@ enum Foo<T> {
|
||||
|
||||
```
|
||||
enum Foo {
|
||||
Bar
|
||||
Bar,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3517,7 +3521,7 @@ enum Foo {
|
||||
|
||||
```
|
||||
enum Foo<T> {
|
||||
Bar(T)
|
||||
Bar(T),
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3526,9 +3530,9 @@ enum Foo<T> {
|
||||
which the pointed-at data is valid. An initial attempt (below) causes this
|
||||
error:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0392
|
||||
struct Foo<'a, T> {
|
||||
x: *const T
|
||||
x: *const T,
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3557,7 +3561,7 @@ struct Foo<'a, T: 'a> {
|
||||
A type parameter which references `Self` in its default value was not specified.
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0393
|
||||
trait A<T=Self> {}
|
||||
|
||||
fn together_we_will_rule_the_galaxy(son: &A) {}
|
||||
@@ -3588,7 +3592,7 @@ fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
|
||||
The length of the platform-intrinsic function `simd_shuffle`
|
||||
wasn't specified. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0439
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
@@ -3613,7 +3617,7 @@ fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
|
||||
A platform-specific intrinsic function has the wrong number of type
|
||||
parameters. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0440
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
@@ -3647,7 +3651,7 @@ fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
|
||||
An unknown platform-specific intrinsic function was used. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0441
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
@@ -3681,7 +3685,7 @@ fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
|
||||
Intrinsic argument(s) and/or return value have the wrong type.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0442
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
@@ -3719,7 +3723,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
|
||||
Intrinsic argument(s) and/or return value have the wrong type.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0443
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
@@ -3754,7 +3758,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
|
||||
A platform-specific intrinsic function has wrong number of arguments.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0444
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
|
||||
@@ -3787,7 +3791,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8,
|
||||
The `typeof` keyword is currently reserved but unimplemented.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0516
|
||||
fn main() {
|
||||
let x: typeof(92) = 92;
|
||||
}
|
||||
@@ -3806,7 +3810,7 @@ fn main() {
|
||||
A non-default implementation was already made on this type so it cannot be
|
||||
specialized further. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0520
|
||||
#![feature(specialization)]
|
||||
|
||||
trait SpaceLlama {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod foo {
|
||||
pub const X: u32 = 1;
|
||||
}
|
||||
|
||||
pub use foo as foo2; //~ ERROR E0365
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[deny(overflowing_literals)]
|
||||
#[repr(i64)]
|
||||
enum Foo {
|
||||
X = 0x7fffffffffffffff,
|
||||
Y, //~ ERROR E0370
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
struct Foo<T: ?Sized> {
|
||||
a: i32,
|
||||
}
|
||||
|
||||
impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> //~ ERROR E0374
|
||||
where T: CoerceUnsized<U> {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
struct Foo<T: ?Sized, U: ?Sized> {
|
||||
a: i32,
|
||||
b: T,
|
||||
c: U,
|
||||
}
|
||||
|
||||
impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {} //~ ERROR E0375
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(coerce_unsized)]
|
||||
use std::ops::CoerceUnsized;
|
||||
|
||||
struct Foo<T: ?Sized> {
|
||||
a: T,
|
||||
}
|
||||
|
||||
impl<T, U> CoerceUnsized<U> for Foo<T> {} //~ ERROR E0376
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static X: i32 = 1;
|
||||
const C: i32 = 2;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
//~| ERROR E0388
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
|
||||
//~| ERROR E0017
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct FancyNum {
|
||||
num: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut fancy = FancyNum{ num: 5 };
|
||||
let fancy_ref = &(&mut fancy);
|
||||
fancy_ref.num = 6; //~ ERROR E0389
|
||||
println!("{}", fancy_ref.num);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
struct Foo {
|
||||
x: i32
|
||||
}
|
||||
|
||||
impl *mut Foo {} //~ ERROR E0390
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
enum Foo<T> { Bar } //~ ERROR E0392
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
trait A<T=Self> {}
|
||||
|
||||
fn together_we_will_rule_the_galaxy(son: &A) {} //~ ERROR E0393
|
||||
|
||||
fn main() {
|
||||
}
|
||||
Reference in New Issue
Block a user