2019-08-09 04:43:26 -05:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
|
|
|
enum E { A, B, c }
|
|
|
|
|
2021-11-17 13:37:46 -06:00
|
|
|
pub mod m {
|
2019-08-09 04:43:26 -05:00
|
|
|
const CONST1: usize = 10;
|
2021-11-17 13:37:46 -06:00
|
|
|
pub const Const2: usize = 20;
|
2019-08-09 04:43:26 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 09:20:23 -05:00
|
|
|
fn main() {
|
|
|
|
let y = 1;
|
2012-08-06 18:16:08 -05:00
|
|
|
match y {
|
Clean up "pattern doesn't bind x" messages
Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.
Before:
```
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
--> file.rs:10:23
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
--> file.rs:10:32
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `b`
error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
--> file.rs:10:43
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `c`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
--> file.rs:10:48
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error: aborting due to 6 previous errors
```
After:
```
error[E0408]: variable `a` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - ^^^^^^^^^^^ ^^^^^^^^ - variable
t in all patterns
| | | |
| | | pattern doesn't bind `a`
| | pattern doesn't bind `a`
| variable not in all patterns
error[E0408]: variable `d` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `d`
| | | |
| | | pattern doesn't bind `d`
| | variable not in all patterns
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `b`
| | | |
| | | pattern doesn't bind `b`
| | variable not in all patterns
| pattern doesn't bind `b`
error[E0408]: variable `c` is not bound in all patterns
--> file.rs:20:48
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ ^^^^^^^^^^^ - ^^^^^^^^ pattern
esn't bind `c`
| | | |
| | | variable not in all
tterns
| | pattern doesn't bind `c`
| pattern doesn't bind `c`
error: aborting due to 4 previous errors
```
* Have only one presentation for binding consistency errors
* Point to same binding in multiple patterns when possible
* Check inconsistent bindings in all arms
* Simplify wording of diagnostic message
* Sort emition and spans of binding errors for deterministic output
2017-02-09 19:54:56 -06:00
|
|
|
a | b => {} //~ ERROR variable `a` is not bound in all patterns
|
2019-08-09 04:43:26 -05:00
|
|
|
//~| ERROR variable `b` is not bound in all patterns
|
|
|
|
}
|
|
|
|
|
|
|
|
let x = (E::A, E::B);
|
|
|
|
match x {
|
|
|
|
(A, B) | (ref B, c) | (c, A) => ()
|
|
|
|
//~^ ERROR variable `A` is not bound in all patterns
|
|
|
|
//~| ERROR variable `B` is not bound in all patterns
|
2020-03-03 20:58:52 -06:00
|
|
|
//~| ERROR variable `B` is bound inconsistently
|
2019-08-09 04:43:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR variable `c` is not bound in all patterns
|
2021-11-17 13:37:46 -06:00
|
|
|
//~| HELP if you meant to match on unit variant `E::A`, use the full path in the pattern
|
2022-07-27 19:55:12 -05:00
|
|
|
//~| HELP consider removing `ref`
|
2019-08-09 04:43:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let z = (10, 20);
|
|
|
|
match z {
|
|
|
|
(CONST1, _) | (_, Const2) => ()
|
|
|
|
//~^ ERROR variable `CONST1` is not bound in all patterns
|
|
|
|
//~| ERROR variable `Const2` is not bound in all patterns
|
2021-11-17 13:37:46 -06:00
|
|
|
//~| HELP if you meant to match on constant `m::Const2`, use the full path in the pattern
|
2012-08-06 09:20:23 -05:00
|
|
|
}
|
|
|
|
}
|