Auto merge of #35431 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
This commit is contained in:
commit
1deb02ea69
@ -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##"
|
E0398: r##"
|
||||||
In Rust 1.3, the default object lifetime bounds are expected to change, as
|
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
|
described in RFC #1156 [1]. You are getting a warning because the compiler
|
||||||
@ -1674,7 +1706,6 @@ register_diagnostics! {
|
|||||||
// E0304, // expected signed integer constant
|
// E0304, // expected signed integer constant
|
||||||
// E0305, // expected constant
|
// E0305, // expected constant
|
||||||
E0311, // thing may not live long enough
|
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
|
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
|
||||||
E0314, // closure outlives stack frame
|
E0314, // closure outlives stack frame
|
||||||
E0315, // cannot invoke closure outside of its lifetime
|
E0315, // cannot invoke closure outside of its lifetime
|
||||||
|
@ -17,7 +17,7 @@ This error occurs when an attempt is made to use data captured by a closure,
|
|||||||
when that data may no longer exist. It's most commonly seen when attempting to
|
when that data may no longer exist. It's most commonly seen when attempting to
|
||||||
return a closure:
|
return a closure:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0373
|
||||||
fn foo() -> Box<Fn(u32) -> u32> {
|
fn foo() -> Box<Fn(u32) -> u32> {
|
||||||
let x = 0u32;
|
let x = 0u32;
|
||||||
Box::new(|y| x + y)
|
Box::new(|y| x + y)
|
||||||
@ -31,7 +31,7 @@ unsafe.
|
|||||||
|
|
||||||
Another situation where this might be encountered is when spawning threads:
|
Another situation where this might be encountered is when spawning threads:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0373
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let x = 0u32;
|
let x = 0u32;
|
||||||
let y = 1u32;
|
let y = 1u32;
|
||||||
@ -66,7 +66,7 @@ about safety.
|
|||||||
E0381: r##"
|
E0381: r##"
|
||||||
It is not allowed to use or capture an uninitialized variable. For example:
|
It is not allowed to use or capture an uninitialized variable. For example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0381
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: i32;
|
let x: i32;
|
||||||
let y = x; // error, use of possibly uninitialized variable
|
let y = x; // error, use of possibly uninitialized variable
|
||||||
@ -88,7 +88,7 @@ E0382: r##"
|
|||||||
This error occurs when an attempt is made to use a variable after its contents
|
This error occurs when an attempt is made to use a variable after its contents
|
||||||
have been moved elsewhere. For example:
|
have been moved elsewhere. For example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0382
|
||||||
struct MyStruct { s: u32 }
|
struct MyStruct { s: u32 }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -180,8 +180,8 @@ E0384: r##"
|
|||||||
This error occurs when an attempt is made to reassign an immutable variable.
|
This error occurs when an attempt is made to reassign an immutable variable.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0384
|
||||||
fn main(){
|
fn main() {
|
||||||
let x = 3;
|
let x = 3;
|
||||||
x = 5; // error, reassignment of immutable variable
|
x = 5; // error, reassignment of immutable variable
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ By default, variables in Rust are immutable. To fix this error, add the keyword
|
|||||||
`mut` after the keyword `let` when declaring the variable. For example:
|
`mut` after the keyword `let` when declaring the variable. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
fn main(){
|
fn main() {
|
||||||
let mut x = 3;
|
let mut x = 3;
|
||||||
x = 5;
|
x = 5;
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ reference stored inside an immutable container.
|
|||||||
|
|
||||||
For example, this can happen when storing a `&mut` inside an immutable `Box`:
|
For example, this can happen when storing a `&mut` inside an immutable `Box`:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0386
|
||||||
let mut x: i64 = 1;
|
let mut x: i64 = 1;
|
||||||
let y: Box<_> = Box::new(&mut x);
|
let y: Box<_> = Box::new(&mut x);
|
||||||
**y = 2; // error, cannot assign to data in an immutable container
|
**y = 2; // error, cannot assign to data in an immutable container
|
||||||
@ -234,7 +234,7 @@ E0387: r##"
|
|||||||
This error occurs when an attempt is made to mutate or mutably reference data
|
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:
|
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.
|
// 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.
|
// Closures passed to foo will not be able to mutate their closed-over state.
|
||||||
fn foo<F: Fn()>(f: F) { }
|
fn foo<F: Fn()>(f: F) { }
|
||||||
@ -286,6 +286,30 @@ You can read more about cell types in the API documentation:
|
|||||||
https://doc.rust-lang.org/std/cell/
|
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##"
|
E0389: r##"
|
||||||
An attempt was made to mutate data using a non-mutable reference. This
|
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
|
commonly occurs when attempting to assign to a non-mutable reference of a
|
||||||
@ -293,9 +317,9 @@ mutable reference (`&(&mut T)`).
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0389
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -315,7 +339,7 @@ To fix this, either remove the outer reference:
|
|||||||
|
|
||||||
```
|
```
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -353,7 +377,7 @@ fn main() {
|
|||||||
E0499: r##"
|
E0499: r##"
|
||||||
A variable was borrowed as mutable more than once. Erroneous code example:
|
A variable was borrowed as mutable more than once. Erroneous code example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0499
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut x = &mut i;
|
let mut x = &mut i;
|
||||||
let mut a = &mut i;
|
let mut a = &mut i;
|
||||||
@ -438,7 +462,7 @@ capturing.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0501
|
||||||
fn inside_closure(x: &mut i32) {
|
fn inside_closure(x: &mut i32) {
|
||||||
// Actions which require unique access
|
// Actions which require unique access
|
||||||
}
|
}
|
||||||
@ -508,7 +532,7 @@ has already been borrowed as immutable.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0502
|
||||||
fn bar(x: &mut i32) {}
|
fn bar(x: &mut i32) {}
|
||||||
fn foo(a: &mut i32) {
|
fn foo(a: &mut i32) {
|
||||||
let ref y = a; // a is borrowed as immutable.
|
let ref y = a; // a is borrowed as immutable.
|
||||||
@ -537,7 +561,7 @@ A value was used after it was mutably borrowed.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0503
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut value = 3;
|
let mut value = 3;
|
||||||
// Create a mutable borrow of `value`. This borrow
|
// Create a mutable borrow of `value`. This borrow
|
||||||
@ -594,9 +618,9 @@ closure.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0504
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -622,7 +646,7 @@ rather than moving:
|
|||||||
|
|
||||||
```
|
```
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -645,7 +669,7 @@ the borrow using a scoped block:
|
|||||||
|
|
||||||
```
|
```
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -674,7 +698,7 @@ use std::sync::Arc;
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: u8
|
num: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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##"
|
E0505: r##"
|
||||||
A value was moved out while it was still borrowed.
|
A value was moved out while it was still borrowed.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0505
|
||||||
struct Value {}
|
struct Value {}
|
||||||
|
|
||||||
fn eat(val: Value) {}
|
fn eat(val: Value) {}
|
||||||
@ -855,10 +796,94 @@ You can find more information about borrowing in the rust-book:
|
|||||||
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
|
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##"
|
E0507: r##"
|
||||||
You tried to move out of a value which was borrowed. Erroneous code example:
|
You tried to move out of a value which was borrowed. Erroneous code example:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0507
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
struct TheDarkKnight;
|
struct TheDarkKnight;
|
||||||
@ -975,7 +1000,7 @@ A value was moved out of a non-copy fixed-size array.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0508
|
||||||
struct NonCopy;
|
struct NonCopy;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -1020,7 +1045,7 @@ implements the `Drop` trait.
|
|||||||
|
|
||||||
Example of erroneous code:
|
Example of erroneous code:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0509
|
||||||
struct FancyNum {
|
struct FancyNum {
|
||||||
num: usize
|
num: usize
|
||||||
}
|
}
|
||||||
@ -1113,6 +1138,5 @@ fn main() {
|
|||||||
|
|
||||||
register_diagnostics! {
|
register_diagnostics! {
|
||||||
E0385, // {} in an aliasable location
|
E0385, // {} in an aliasable location
|
||||||
E0388, // {} in a static location
|
|
||||||
E0524, // two closures require unique access to `..` at the same time
|
E0524, // two closures require unique access to `..` at the same time
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
17
src/test/compile-fail/E0365.rs
Normal file
17
src/test/compile-fail/E0365.rs
Normal file
@ -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() {}
|
20
src/test/compile-fail/E0370.rs
Normal file
20
src/test/compile-fail/E0370.rs
Normal file
@ -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() {}
|
21
src/test/compile-fail/E0374.rs
Normal file
21
src/test/compile-fail/E0374.rs
Normal file
@ -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() {}
|
22
src/test/compile-fail/E0375.rs
Normal file
22
src/test/compile-fail/E0375.rs
Normal file
@ -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() {}
|
20
src/test/compile-fail/E0376.rs
Normal file
20
src/test/compile-fail/E0376.rs
Normal file
@ -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() {}
|
22
src/test/compile-fail/E0388.rs
Normal file
22
src/test/compile-fail/E0388.rs
Normal file
@ -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() {}
|
20
src/test/compile-fail/E0389.rs
Normal file
20
src/test/compile-fail/E0389.rs
Normal file
@ -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);
|
||||||
|
}
|
18
src/test/compile-fail/E0390.rs
Normal file
18
src/test/compile-fail/E0390.rs
Normal file
@ -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() {
|
||||||
|
}
|
14
src/test/compile-fail/E0392.rs
Normal file
14
src/test/compile-fail/E0392.rs
Normal file
@ -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() {
|
||||||
|
}
|
16
src/test/compile-fail/E0393.rs
Normal file
16
src/test/compile-fail/E0393.rs
Normal file
@ -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() {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user