Skip to content

Commit ddf92ff

Browse files
authored
Auto merge of rust-lang#35393 - GuillaumeGomez:err_codes2, r=jonathandturner
Err codes r? @jonathandturner
2 parents 444ff9f + 4e2dd8d commit ddf92ff

File tree

13 files changed

+243
-22
lines changed

13 files changed

+243
-22
lines changed

src/librustc_const_eval/diagnostics.rs

+26-22
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ one is too specific or the ordering is incorrect.
2525
2626
For example, the following `match` block has too many arms:
2727
28-
```compile_fail
29-
match foo {
28+
```compile_fail,E0001
29+
match Some(0) {
3030
Some(bar) => {/* ... */}
3131
None => {/* ... */}
3232
_ => {/* ... */} // All possible cases have already been handled
@@ -108,7 +108,7 @@ one or more possible inputs to a match expression. Guaranteed matches are
108108
required in order to assign values to match expressions, or alternatively,
109109
determine the flow of execution. Erroneous code example:
110110
111-
```compile_fail
111+
```compile_fail,E0004
112112
enum Terminator {
113113
HastaLaVistaBaby,
114114
TalkToMyHand,
@@ -153,7 +153,7 @@ E0005: r##"
153153
Patterns used to bind names must be irrefutable, that is, they must guarantee
154154
that a name will be extracted in all cases. Erroneous code example:
155155
156-
```compile_fail
156+
```compile_fail,E0005
157157
let x = Some(1);
158158
let Some(y) = x;
159159
// error: refutable pattern in local binding: `None` not covered
@@ -187,7 +187,7 @@ like the following is invalid as it requires the entire `Option<String>` to be
187187
moved into a variable called `op_string` while simultaneously requiring the
188188
inner `String` to be moved into a variable called `s`.
189189
190-
```compile_fail
190+
```compile_fail,E0007
191191
let x = Some("s".to_string());
192192
193193
match x {
@@ -205,7 +205,7 @@ name is bound by move in a pattern, it should also be moved to wherever it is
205205
referenced in the pattern guard code. Doing so however would prevent the name
206206
from being available in the body of the match arm. Consider the following:
207207
208-
```compile_fail
208+
```compile_fail,E0008
209209
match Some("hi".to_string()) {
210210
Some(s) if s.len() == 0 => {}, // use s.
211211
_ => {},
@@ -229,7 +229,7 @@ match Some("hi".to_string()) {
229229
Though this example seems innocuous and easy to solve, the problem becomes clear
230230
when it encounters functions which consume the value:
231231
232-
```compile_fail
232+
```compile_fail,E0008
233233
struct A{}
234234
235235
impl A {
@@ -283,7 +283,7 @@ This limitation may be removed in a future version of Rust.
283283
284284
Erroneous code example:
285285
286-
```compile_fail
286+
```compile_fail,E0009
287287
struct X { x: (), }
288288
289289
let x = Some((X { x: () }, X { x: () }));
@@ -351,25 +351,25 @@ An if-let pattern attempts to match the pattern, and enters the body if the
351351
match was successful. If the match is irrefutable (when it cannot fail to
352352
match), use a regular `let`-binding instead. For instance:
353353
354-
```compile_fail
354+
```compile_fail,E0162
355355
struct Irrefutable(i32);
356356
let irr = Irrefutable(0);
357357
358358
// This fails to compile because the match is irrefutable.
359359
if let Irrefutable(x) = irr {
360360
// This body will always be executed.
361-
foo(x);
361+
// ...
362362
}
363363
```
364364
365365
Try this instead:
366366
367-
```ignore
367+
```
368368
struct Irrefutable(i32);
369369
let irr = Irrefutable(0);
370370
371371
let Irrefutable(x) = irr;
372-
foo(x);
372+
println!("{}", x);
373373
```
374374
"##,
375375

@@ -378,7 +378,7 @@ A while-let pattern attempts to match the pattern, and enters the body if the
378378
match was successful. If the match is irrefutable (when it cannot fail to
379379
match), use a regular `let`-binding inside a `loop` instead. For instance:
380380
381-
```compile_fail
381+
```compile_fail,E0165
382382
struct Irrefutable(i32);
383383
let irr = Irrefutable(0);
384384
@@ -455,7 +455,7 @@ that a name will be extracted in all cases. Instead of pattern matching the
455455
loop variable, consider using a `match` or `if let` inside the loop body. For
456456
instance:
457457
458-
```compile_fail
458+
```compile_fail,E0297
459459
let xs : Vec<Option<i32>> = vec!(Some(1), None);
460460
461461
// This fails because `None` is not covered.
@@ -497,7 +497,7 @@ on which the match depends in such a way, that the match would not be
497497
exhaustive. For instance, the following would not match any arm if mutable
498498
borrows were allowed:
499499
500-
```compile_fail
500+
```compile_fail,E0301
501501
match Some(()) {
502502
None => { },
503503
option if option.take().is_none() => {
@@ -515,10 +515,10 @@ on which the match depends in such a way, that the match would not be
515515
exhaustive. For instance, the following would not match any arm if assignments
516516
were allowed:
517517
518-
```compile_fail
518+
```compile_fail,E0302
519519
match Some(()) {
520520
None => { },
521-
option if { option = None; false } { },
521+
option if { option = None; false } => { },
522522
Some(_) => { } // When the previous match failed, the option became `None`.
523523
}
524524
```
@@ -529,14 +529,18 @@ In certain cases it is possible for sub-bindings to violate memory safety.
529529
Updates to the borrow checker in a future version of Rust may remove this
530530
restriction, but for now patterns must be rewritten without sub-bindings.
531531
532-
```ignore
533-
// Before.
532+
Before:
533+
534+
```compile_fail,E0303
534535
match Some("hi".to_string()) {
535536
ref op_string_ref @ Some(s) => {},
536537
None => {},
537538
}
539+
```
540+
541+
After:
538542
539-
// After.
543+
```
540544
match Some("hi".to_string()) {
541545
Some(ref s) => {
542546
let op_string_ref = &Some(s);
@@ -556,7 +560,7 @@ This error indicates that the compiler was unable to sensibly evaluate an
556560
constant expression that had to be evaluated. Attempting to divide by 0
557561
or causing integer overflow are two ways to induce this error. For example:
558562
559-
```compile_fail
563+
```compile_fail,E0080
560564
enum Enum {
561565
X = (1 << 500),
562566
Y = (1 / 0)
@@ -575,7 +579,7 @@ E0306: r##"
575579
In an array literal `[x; N]`, `N` is the number of elements in the array. This
576580
must be an unsigned integer. Erroneous code example:
577581
578-
```compile_fail
582+
```compile_fail,E0306
579583
let x = [0i32; true]; // error: expected positive integer for repeat count,
580584
// found boolean
581585
```

src/test/compile-fail/E0271.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+
trait Trait { type AssociatedType; }
12+
13+
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
14+
println!("in foo");
15+
}
16+
17+
impl Trait for i8 { type AssociatedType = &'static str; }
18+
19+
fn main() {
20+
foo(3_i8); //~ ERROR E0271
21+
}

src/test/compile-fail/E0275.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 Foo {}
12+
13+
struct Bar<T>(T);
14+
15+
impl<T> Foo for T where Bar<T>: Foo {} //~ ERROR E0275
16+
17+
fn main() {
18+
}

src/test/compile-fail/E0276.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 Foo {
12+
fn foo<T>(x: T);
13+
}
14+
15+
impl Foo for bool {
16+
fn foo<T>(x: T) where T: Copy {} //~ ERROR E0276
17+
}
18+
19+
fn main() {
20+
}

src/test/compile-fail/E0277.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+
trait Foo {
12+
fn bar(&self);
13+
}
14+
15+
fn some_func<T: Foo>(foo: T) {
16+
foo.bar();
17+
}
18+
19+
fn main() {
20+
some_func(5i32); //~ ERROR E0277
21+
}

src/test/compile-fail/E0281.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 foo<F: Fn()>(x: F) { }
12+
13+
fn main() {
14+
foo(|y| { }); //~ ERROR E0281
15+
//~^ ERROR E0281
16+
}

src/test/compile-fail/E0282.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 x = "hello".chars().rev().collect(); //~ ERROR E0282
13+
}

src/test/compile-fail/E0283.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 Generator {
12+
fn create() -> u32;
13+
}
14+
15+
struct Impl;
16+
17+
impl Generator for Impl {
18+
fn create() -> u32 { 1 }
19+
}
20+
21+
struct AnotherImpl;
22+
23+
impl Generator for AnotherImpl {
24+
fn create() -> u32 { 2 }
25+
}
26+
27+
fn main() {
28+
let cont: u32 = Generator::create(); //~ ERROR E0283
29+
}

src/test/compile-fail/E0296.rs

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

src/test/compile-fail/E0297.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 xs : Vec<Option<i32>> = vec!(Some(1), None);
13+
14+
for Some(x) in xs {} //~ ERROR E0297
15+
}

src/test/compile-fail/E0301.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+
fn main() {
12+
match Some(()) {
13+
None => { },
14+
option if option.take().is_none() => {}, //~ ERROR E0301
15+
Some(_) => { }
16+
}
17+
}

src/test/compile-fail/E0302.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+
fn main() {
12+
match Some(()) {
13+
None => { },
14+
option if { option = None; false } => { }, //~ ERROR E0302
15+
Some(_) => { }
16+
}
17+
}

0 commit comments

Comments
 (0)