Skip to content

Commit 251697b

Browse files
author
Jonathan Turner
authored
Rollup merge of #36141 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
2 parents 78fc44f + 37bf449 commit 251697b

File tree

11 files changed

+196
-2
lines changed

11 files changed

+196
-2
lines changed

src/librustc_resolve/diagnostics.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,42 @@ trait Foo {}
12701270
12711271
impl Foo for i32 {}
12721272
```
1273-
"##
1273+
"##,
1274+
1275+
E0530: r##"
1276+
A binding shadowed something it shouldn't.
1277+
1278+
Erroneous code example:
1279+
1280+
```compile_fail,E0530
1281+
static TEST: i32 = 0;
1282+
1283+
let r: (i32, i32) = (0, 0);
1284+
match r {
1285+
TEST => {} // error: match bindings cannot shadow statics
1286+
}
1287+
```
1288+
1289+
To fix this error, just change the binding's name in order to avoid shadowing
1290+
one of the following:
1291+
1292+
* struct name
1293+
* struct/enum variant
1294+
* static
1295+
* const
1296+
* associated const
1297+
1298+
Fixed example:
1299+
1300+
```
1301+
static TEST: i32 = 0;
1302+
1303+
let r: (i32, i32) = (0, 0);
1304+
match r {
1305+
something => {} // ok!
1306+
}
1307+
```
1308+
"##,
12741309

12751310
}
12761311

@@ -1289,7 +1324,6 @@ register_diagnostics! {
12891324
// E0419, merged into 531
12901325
// E0420, merged into 532
12911326
// E0421, merged into 531
1292-
E0530, // X bindings cannot shadow Ys
12931327
E0531, // unresolved pattern path kind `name`
12941328
E0532, // expected pattern path kind, found another pattern path kind
12951329
// E0427, merged into 530

src/test/compile-fail/E0528.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+
#![feature(slice_patterns)]
12+
13+
fn main() {
14+
let r = &[1, 2];
15+
match r {
16+
&[a, b, c, rest..] => { //~ ERROR E0528
17+
}
18+
}
19+
}

src/test/compile-fail/E0529.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+
#![feature(slice_patterns)]
12+
13+
fn main() {
14+
let r: f32 = 1.0;
15+
match r {
16+
[a, b] => { //~ ERROR E0529
17+
}
18+
}
19+
}

src/test/compile-fail/E0530.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+
fn main() {
12+
static TEST: i32 = 0;
13+
14+
let r: (i32, i32) = (0, 0);
15+
match r {
16+
TEST => {} //~ ERROR E0530
17+
}
18+
}

src/test/compile-fail/E0534.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#[inline()] //~ ERROR E0534
12+
pub fn something() {}
13+
14+
fn main() {}

src/test/compile-fail/E0535.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#[inline(unknown)] //~ ERROR E0535
12+
pub fn something() {}
13+
14+
fn main() {}

src/test/compile-fail/E0536.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#[cfg(not())] //~ ERROR E0536
12+
pub fn something() {}
13+
14+
pub fn main() {}

src/test/compile-fail/E0537.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#[cfg(unknown())] //~ ERROR E0537
12+
pub fn something() {}
13+
14+
pub fn main() {}

src/test/compile-fail/E0558.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#[export_name] //~ ERROR E0558
12+
pub fn something() {}
13+
14+
fn main() {}

src/test/compile-fail/E0559.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+
enum Field {
12+
Fool { x: u32 },
13+
}
14+
15+
fn main() {
16+
let s = Field::Fool { joke: 0 }; //~ ERROR E0559
17+
}

src/test/compile-fail/E560.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+
struct Simba {
12+
mother: u32,
13+
}
14+
15+
fn main() {
16+
let s = Simba { mother: 1, father: 0 }; //~ ERROR E0560
17+
}

0 commit comments

Comments
 (0)