Skip to content

Commit 336841c

Browse files
author
Jonathan Turner
authored
Rollup merge of #35920 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
2 parents 95c661a + 5c5f483 commit 336841c

File tree

9 files changed

+180
-14
lines changed

9 files changed

+180
-14
lines changed

src/librustc/diagnostics.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,37 @@ fn main() {
15271527
```
15281528
"##,
15291529

1530+
E0478: r##"
1531+
A lifetime bound was not satisfied.
1532+
1533+
Erroneous code example:
1534+
1535+
```compile_fail,E0478
1536+
// Check that the explicit lifetime bound (`'SnowWhite`, in this example) must
1537+
// outlive all the superbounds from the trait (`'kiss`, in this example).
1538+
1539+
trait Wedding<'t>: 't { }
1540+
1541+
struct Prince<'kiss, 'SnowWhite> {
1542+
child: Box<Wedding<'kiss> + 'SnowWhite>,
1543+
// error: lifetime bound not satisfied
1544+
}
1545+
```
1546+
1547+
In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
1548+
lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
1549+
this issue, you need to specify it:
1550+
1551+
```
1552+
trait Wedding<'t>: 't { }
1553+
1554+
struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
1555+
// longer than 'SnowWhite.
1556+
child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
1557+
}
1558+
```
1559+
"##,
1560+
15301561
E0496: r##"
15311562
A lifetime name is shadowing another lifetime name. Erroneous code example:
15321563
@@ -1715,7 +1746,6 @@ register_diagnostics! {
17151746
E0475, // index of slice outside its lifetime
17161747
E0476, // lifetime of the source pointer does not outlive lifetime bound...
17171748
E0477, // the type `..` does not fulfill the required lifetime...
1718-
E0478, // lifetime bound not satisfied
17191749
E0479, // the type `..` (provided as the value of a type parameter) is...
17201750
E0480, // lifetime of method receiver does not outlive the method call
17211751
E0481, // lifetime of function argument does not outlive the function call

src/librustc_mir/diagnostics.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
1818
the heap at runtime, and therefore cannot be done at compile time. Erroneous
1919
code example:
2020
21-
```compile_fail
21+
```compile_fail,E0010
2222
#![feature(box_syntax)]
2323
2424
const CON : Box<i32> = box 0;
@@ -30,7 +30,7 @@ Static and const variables can refer to other const variables. But a const
3030
variable cannot refer to a static variable. For example, `Y` cannot refer to
3131
`X` here:
3232
33-
```compile_fail
33+
```compile_fail,E0013
3434
static X: i32 = 42;
3535
const Y: i32 = X;
3636
```
@@ -66,7 +66,7 @@ E0016: r##"
6666
Blocks in constants may only contain items (such as constant, function
6767
definition, etc...) and a tail expression. Erroneous code example:
6868
69-
```compile_fail
69+
```compile_fail,E0016
7070
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
7171
```
7272
@@ -81,7 +81,7 @@ E0017: r##"
8181
References in statics and constants may only refer to immutable values.
8282
Erroneous code example:
8383
84-
```compile_fail
84+
```compile_fail,E0017
8585
static X: i32 = 1;
8686
const C: i32 = 2;
8787
@@ -107,7 +107,7 @@ vary.
107107
108108
For example, if you write:
109109
110-
```compile_fail
110+
```compile_fail,E0018
111111
static MY_STATIC: u32 = 42;
112112
static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
113113
static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
@@ -152,7 +152,7 @@ impl Test {
152152
fn main() {
153153
const FOO: Test = Test::V1;
154154
155-
const A: i32 = FOO.test(); // You can't call Test::func() here !
155+
const A: i32 = FOO.test(); // You can't call Test::func() here!
156156
}
157157
```
158158
@@ -214,14 +214,13 @@ static B: &'static u32 = &A; // ok!
214214
```
215215
"##,
216216

217-
218217
E0395: r##"
219218
The value assigned to a constant scalar must be known at compile time,
220219
which is not the case when comparing raw pointers.
221220
222221
Erroneous code example:
223222
224-
```compile_fail
223+
```compile_fail,E0395
225224
static FOO: i32 = 42;
226225
static BAR: i32 = 42;
227226
@@ -250,7 +249,7 @@ The value behind a raw pointer can't be determined at compile-time
250249
(or even link-time), which means it can't be used in a constant
251250
expression. Erroneous code example:
252251
253-
```compile_fail
252+
```compile_fail,E0396
254253
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
255254
256255
const VALUE: u8 = unsafe { *REG_ADDR };
@@ -272,7 +271,7 @@ E0492: r##"
272271
A borrow of a constant containing interior mutability was attempted. Erroneous
273272
code example:
274273
275-
```compile_fail
274+
```compile_fail,E0492
276275
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
277276
278277
const A: AtomicUsize = ATOMIC_USIZE_INIT;
@@ -299,7 +298,7 @@ static B: &'static AtomicUsize = &A; // ok!
299298
300299
You can also have this error while using a cell type:
301300
302-
```compile_fail
301+
```compile_fail,E0492
303302
#![feature(const_fn)]
304303
305304
use std::cell::Cell;
@@ -351,7 +350,7 @@ E0493: r##"
351350
A type with a destructor was assigned to an invalid type of variable. Erroneous
352351
code example:
353352
354-
```compile_fail
353+
```compile_fail,E0493
355354
struct Foo {
356355
a: u32
357356
}
@@ -374,7 +373,7 @@ E0494: r##"
374373
A reference of an interior static was assigned to another const/static.
375374
Erroneous code example:
376375
377-
```compile_fail
376+
```compile_fail,E0494
378377
struct Foo {
379378
a: u32
380379
}

src/test/compile-fail/E0478.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Wedding<'t>: 't { }
12+
13+
struct Prince<'kiss, 'SnowWhite> {
14+
child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
15+
}
16+
17+
fn main() {
18+
}

src/test/compile-fail/E0492.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
12+
13+
const A: AtomicUsize = ATOMIC_USIZE_INIT;
14+
static B: &'static AtomicUsize = &A; //~ ERROR E0492
15+
16+
fn main() {
17+
}

src/test/compile-fail/E0493.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
a: u32
13+
}
14+
15+
impl Drop for Foo {
16+
fn drop(&mut self) {}
17+
}
18+
19+
const F : Foo = Foo { a : 0 }; //~ ERROR E0493
20+
21+
fn main() {
22+
}

src/test/compile-fail/E0494.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
a: u32
13+
}
14+
15+
static S : Foo = Foo { a : 0 };
16+
static A : &'static u32 = &S.a; //~ ERROR E0494
17+
18+
fn main() {
19+
}

src/test/compile-fail/E0496.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo<'a> {
12+
a: &'a i32,
13+
}
14+
15+
impl<'a> Foo<'a> {
16+
fn f<'a>(x: &'a i32) { //~ ERROR E0496
17+
}
18+
}
19+
20+
fn main() {
21+
}

src/test/compile-fail/E0499.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let mut i = 0;
13+
let mut x = &mut i;
14+
let mut a = &mut i; //~ ERROR E0499
15+
}

src/test/compile-fail/E0501.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn inside_closure(x: &mut i32) {
12+
}
13+
14+
fn outside_closure(x: &mut i32) {
15+
}
16+
17+
fn foo(a: &mut i32) {
18+
let bar = || {
19+
inside_closure(a)
20+
};
21+
outside_closure(a); //~ ERROR E0501
22+
}
23+
24+
fn main() {
25+
}

0 commit comments

Comments
 (0)