Rollup merge of #35920 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
This commit is contained in:
commit
336841ccf9
@ -1527,6 +1527,37 @@ fn main() {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0478: r##"
|
||||
A lifetime bound was not satisfied.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0478
|
||||
// Check that the explicit lifetime bound (`'SnowWhite`, in this example) must
|
||||
// outlive all the superbounds from the trait (`'kiss`, in this example).
|
||||
|
||||
trait Wedding<'t>: 't { }
|
||||
|
||||
struct Prince<'kiss, 'SnowWhite> {
|
||||
child: Box<Wedding<'kiss> + 'SnowWhite>,
|
||||
// error: lifetime bound not satisfied
|
||||
}
|
||||
```
|
||||
|
||||
In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
|
||||
lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
|
||||
this issue, you need to specify it:
|
||||
|
||||
```
|
||||
trait Wedding<'t>: 't { }
|
||||
|
||||
struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
|
||||
// longer than 'SnowWhite.
|
||||
child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0496: r##"
|
||||
A lifetime name is shadowing another lifetime name. Erroneous code example:
|
||||
|
||||
@ -1715,7 +1746,6 @@ register_diagnostics! {
|
||||
E0475, // index of slice outside its lifetime
|
||||
E0476, // lifetime of the source pointer does not outlive lifetime bound...
|
||||
E0477, // the type `..` does not fulfill the required lifetime...
|
||||
E0478, // lifetime bound not satisfied
|
||||
E0479, // the type `..` (provided as the value of a type parameter) is...
|
||||
E0480, // lifetime of method receiver does not outlive the method call
|
||||
E0481, // lifetime of function argument does not outlive the function call
|
||||
|
@ -18,7 +18,7 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
|
||||
the heap at runtime, and therefore cannot be done at compile time. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0010
|
||||
#![feature(box_syntax)]
|
||||
|
||||
const CON : Box<i32> = box 0;
|
||||
@ -30,7 +30,7 @@ Static and const variables can refer to other const variables. But a const
|
||||
variable cannot refer to a static variable. For example, `Y` cannot refer to
|
||||
`X` here:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0013
|
||||
static X: i32 = 42;
|
||||
const Y: i32 = X;
|
||||
```
|
||||
@ -66,7 +66,7 @@ E0016: r##"
|
||||
Blocks in constants may only contain items (such as constant, function
|
||||
definition, etc...) and a tail expression. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0016
|
||||
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
|
||||
```
|
||||
|
||||
@ -81,7 +81,7 @@ E0017: r##"
|
||||
References in statics and constants may only refer to immutable values.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0017
|
||||
static X: i32 = 1;
|
||||
const C: i32 = 2;
|
||||
|
||||
@ -107,7 +107,7 @@ vary.
|
||||
|
||||
For example, if you write:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0018
|
||||
static MY_STATIC: u32 = 42;
|
||||
static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
|
||||
static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
|
||||
@ -152,7 +152,7 @@ impl Test {
|
||||
fn main() {
|
||||
const FOO: Test = Test::V1;
|
||||
|
||||
const A: i32 = FOO.test(); // You can't call Test::func() here !
|
||||
const A: i32 = FOO.test(); // You can't call Test::func() here!
|
||||
}
|
||||
```
|
||||
|
||||
@ -214,14 +214,13 @@ static B: &'static u32 = &A; // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
|
||||
E0395: r##"
|
||||
The value assigned to a constant scalar must be known at compile time,
|
||||
which is not the case when comparing raw pointers.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0395
|
||||
static FOO: i32 = 42;
|
||||
static BAR: i32 = 42;
|
||||
|
||||
@ -250,7 +249,7 @@ The value behind a raw pointer can't be determined at compile-time
|
||||
(or even link-time), which means it can't be used in a constant
|
||||
expression. Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0396
|
||||
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
|
||||
|
||||
const VALUE: u8 = unsafe { *REG_ADDR };
|
||||
@ -272,7 +271,7 @@ E0492: r##"
|
||||
A borrow of a constant containing interior mutability was attempted. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0492
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
|
||||
|
||||
const A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
@ -299,7 +298,7 @@ static B: &'static AtomicUsize = &A; // ok!
|
||||
|
||||
You can also have this error while using a cell type:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0492
|
||||
#![feature(const_fn)]
|
||||
|
||||
use std::cell::Cell;
|
||||
@ -351,7 +350,7 @@ E0493: r##"
|
||||
A type with a destructor was assigned to an invalid type of variable. Erroneous
|
||||
code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0493
|
||||
struct Foo {
|
||||
a: u32
|
||||
}
|
||||
@ -374,7 +373,7 @@ E0494: r##"
|
||||
A reference of an interior static was assigned to another const/static.
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail
|
||||
```compile_fail,E0494
|
||||
struct Foo {
|
||||
a: u32
|
||||
}
|
||||
|
18
src/test/compile-fail/E0478.rs
Normal file
18
src/test/compile-fail/E0478.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.
|
||||
|
||||
trait Wedding<'t>: 't { }
|
||||
|
||||
struct Prince<'kiss, 'SnowWhite> {
|
||||
child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
17
src/test/compile-fail/E0492.rs
Normal file
17
src/test/compile-fail/E0492.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.
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
|
||||
|
||||
const A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
static B: &'static AtomicUsize = &A; //~ ERROR E0492
|
||||
|
||||
fn main() {
|
||||
}
|
22
src/test/compile-fail/E0493.rs
Normal file
22
src/test/compile-fail/E0493.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.
|
||||
|
||||
struct Foo {
|
||||
a: u32
|
||||
}
|
||||
|
||||
impl Drop for Foo {
|
||||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
const F : Foo = Foo { a : 0 }; //~ ERROR E0493
|
||||
|
||||
fn main() {
|
||||
}
|
19
src/test/compile-fail/E0494.rs
Normal file
19
src/test/compile-fail/E0494.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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 {
|
||||
a: u32
|
||||
}
|
||||
|
||||
static S : Foo = Foo { a : 0 };
|
||||
static A : &'static u32 = &S.a; //~ ERROR E0494
|
||||
|
||||
fn main() {
|
||||
}
|
21
src/test/compile-fail/E0496.rs
Normal file
21
src/test/compile-fail/E0496.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.
|
||||
|
||||
struct Foo<'a> {
|
||||
a: &'a i32,
|
||||
}
|
||||
|
||||
impl<'a> Foo<'a> {
|
||||
fn f<'a>(x: &'a i32) { //~ ERROR E0496
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
15
src/test/compile-fail/E0499.rs
Normal file
15
src/test/compile-fail/E0499.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
fn main() {
|
||||
let mut i = 0;
|
||||
let mut x = &mut i;
|
||||
let mut a = &mut i; //~ ERROR E0499
|
||||
}
|
25
src/test/compile-fail/E0501.rs
Normal file
25
src/test/compile-fail/E0501.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
fn inside_closure(x: &mut i32) {
|
||||
}
|
||||
|
||||
fn outside_closure(x: &mut i32) {
|
||||
}
|
||||
|
||||
fn foo(a: &mut i32) {
|
||||
let bar = || {
|
||||
inside_closure(a)
|
||||
};
|
||||
outside_closure(a); //~ ERROR E0501
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue
Block a user