Skip to content

Commit 84f7ce7

Browse files
committed
modernize all errors in check_match
1 parent bf68227 commit 84f7ce7

11 files changed

+44
-69
lines changed

src/librustc_const_eval/diagnostics.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -294,27 +294,6 @@ match x {
294294
```
295295
"##,
296296

297-
E0158: r##"
298-
`const` and `static` mean different things. A `const` is a compile-time
299-
constant, an alias for a literal value. This property means you can match it
300-
directly within a pattern.
301-
302-
The `static` keyword, on the other hand, guarantees a fixed location in memory.
303-
This does not always mean that the value is constant. For example, a global
304-
mutex can be declared `static` as well.
305-
306-
If you want to match against a `static`, consider using a guard instead:
307-
308-
```
309-
static FORTY_TWO: i32 = 42;
310-
311-
match Some(42) {
312-
Some(x) if x == FORTY_TWO => {}
313-
_ => {}
314-
}
315-
```
316-
"##,
317-
318297
E0162: r##"
319298
An if-let pattern attempts to match the pattern, and enters the body if the
320299
match was successful. If the match is irrefutable (when it cannot fail to
@@ -564,6 +543,7 @@ let x = [0i32; 2];
564543

565544
register_diagnostics! {
566545
// E0002, // duplicated from E0001
546+
E0158, // cannot resolve constant in pattern
567547
E0298, // cannot compare constants
568548
// E0299, // mismatched types between arms
569549
// E0471, // constant evaluation error (in pattern)

src/test/compile-fail/E0002.rs

-15
This file was deleted.

src/test/compile-fail/associated-const-type-parameter-arms.rs renamed to src/test/compile-fail/E0158.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ impl Foo for Def {
2828

2929
pub fn test<A: Foo, B: Foo>(arg: EFoo) {
3030
match arg {
31-
A::X => println!("A::X"), //~ error: statics cannot be referenced in patterns [E0158]
32-
B::X => println!("B::X"), //~ error: statics cannot be referenced in patterns [E0158]
31+
A::X => println!("A::X"), //~ ERROR E0158
32+
//~| unresolvable constant here
33+
B::X => println!("B::X"), //~ ERROR E0158
34+
//~| unresolvable constant here
3335
_ => (),
3436
}
3537
}

src/test/compile-fail/E0162.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct Irrefutable(i32);
1313
fn main() {
1414
let irr = Irrefutable(0);
1515
if let Irrefutable(x) = irr { //~ ERROR E0162
16+
//~| this pattern always applies
1617
println!("{}", x);
1718
}
1819
}

src/test/compile-fail/issue-14221.rs renamed to src/test/compile-fail/E0170.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub mod b {
1717
pub fn key(e: ::E) -> &'static str {
1818
match e {
1919
A => "A",
20-
//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
20+
//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E` [E0170]
2121
B => "B", //~ ERROR: unreachable pattern
22-
//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
22+
//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E` [E0170]
2323
}
2424
}
2525
}

src/test/compile-fail/E0297.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let xs : Vec<Option<i32>> = vec!(Some(1), None);
12+
for
13+
&0
14+
//~^ ERROR refutable pattern in `for` loop binding [E0297]
15+
//~| `&_` not covered
16+
in [1].iter()
17+
{
1318

14-
for Some(x) in xs {} //~ ERROR E0297
19+
}
1520
}

src/test/compile-fail/E0301.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
fn mangle(x: &mut Option<u32>) -> bool { *x = None; false }
12+
1113
fn main() {
12-
match Some(()) {
13-
None => { },
14-
option if option.take().is_none() => {}, //~ ERROR E0301
15-
Some(_) => { }
14+
let ref mut x = Some(4);
15+
match x {
16+
&mut None => {}
17+
&mut Some(_) if
18+
mangle(
19+
x //~ ERROR E0301
20+
)
21+
=> {}
22+
&mut Some(_) => {}
1623
}
1724
}

src/test/compile-fail/E0302.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
match Some(()) {
13-
None => { },
14-
option if { option = None; false } => { }, //~ ERROR E0302
15-
Some(_) => { }
12+
let ref mut x = Some(4);
13+
match x {
14+
&mut None => {}
15+
&mut Some(_) if
16+
{
17+
*x = None; //~ ERROR E0302
18+
false
19+
}
20+
=> {}
21+
&mut Some(_) => {}
1622
}
1723
}

src/test/compile-fail/E0303.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
match Some("hi".to_string()) {
13-
ref op_string_ref @ Some(s) => {}, //~ ERROR E0303
14-
//~^ ERROR E0009
15-
None => {},
12+
match 0 {
13+
ref mut x @ y //~ ERROR E0303
14+
=> {}
1615
}
1716
}

src/test/compile-fail/for-loop-refutable-pattern-error-message.rs

-13
This file was deleted.

src/test/compile-fail/pattern-bindings-after-at.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ enum Option<T> {
1515

1616
fn main() {
1717
match &mut Some(1) {
18-
ref mut z @ &mut Some(ref a) => {
19-
//~^ ERROR pattern bindings are not allowed after an `@`
18+
ref mut z
19+
//~^ NOTE within this binding
20+
@ &mut Some(ref a) => {
21+
//~^ ERROR nested pattern bindings are invalid
22+
//~| invalid nested binding here
2023
**z = None;
2124
println!("{}", *a);
2225
}

0 commit comments

Comments
 (0)