When encountering a binding that could be a const or unit variant, suggest the right path

This commit is contained in:
Esteban Kuber 2021-11-17 19:37:46 +00:00
parent 05c07386b4
commit 09f3ea1692
8 changed files with 131 additions and 77 deletions

View file

@ -103,6 +103,22 @@ LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| |
| pattern doesn't bind `c`
error[E0408]: variable `d` is not bound in all patterns
--> $DIR/missing-bindings.rs:45:33
|
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| - ^^^^ pattern doesn't bind `d`
| |
| variable not in all patterns
error[E0408]: variable `e` is not bound in all patterns
--> $DIR/missing-bindings.rs:45:10
|
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| ^^^^^^^^^^^^^^^^^^^^ - variable not in all patterns
| |
| pattern doesn't bind `e`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:45:33
|
@ -127,22 +143,6 @@ LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| |
| variable not in all patterns
error[E0408]: variable `d` is not bound in all patterns
--> $DIR/missing-bindings.rs:45:33
|
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| - ^^^^ pattern doesn't bind `d`
| |
| variable not in all patterns
error[E0408]: variable `e` is not bound in all patterns
--> $DIR/missing-bindings.rs:45:10
|
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
| ^^^^^^^^^^^^^^^^^^^^ - variable not in all patterns
| |
| pattern doesn't bind `e`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:61:29
|

View file

@ -2,9 +2,9 @@
enum E { A, B, c }
mod m {
pub mod m {
const CONST1: usize = 10;
const Const2: usize = 20;
pub const Const2: usize = 20;
}
fn main() {
@ -22,15 +22,14 @@ fn main() {
//~| ERROR variable `B` is bound inconsistently
//~| ERROR mismatched types
//~| ERROR variable `c` is not bound in all patterns
//~| HELP consider making the path in the pattern qualified: `?::A`
//~| HELP if you meant to match on unit variant `E::A`, use the full path in the pattern
}
let z = (10, 20);
match z {
(CONST1, _) | (_, Const2) => ()
//~^ ERROR variable `CONST1` is not bound in all patterns
//~| HELP consider making the path in the pattern qualified: `?::CONST1`
//~| ERROR variable `Const2` is not bound in all patterns
//~| HELP consider making the path in the pattern qualified: `?::Const2`
//~| HELP if you meant to match on constant `m::Const2`, use the full path in the pattern
}
}

View file

@ -23,11 +23,10 @@ LL | (A, B) | (ref B, c) | (c, A) => ()
| | pattern doesn't bind `A`
| variable not in all patterns
|
help: if you meant to match on a variant or a `const` item, consider making the path in the pattern qualified: `?::A`
--> $DIR/resolve-inconsistent-names.rs:19:10
help: if you meant to match on unit variant `E::A`, use the full path in the pattern
|
LL | (A, B) | (ref B, c) | (c, A) => ()
| ^
LL | (E::A, B) | (ref B, c) | (c, A) => ()
| ~~~~
error[E0408]: variable `B` is not bound in all patterns
--> $DIR/resolve-inconsistent-names.rs:19:31
@ -63,11 +62,11 @@ LL | (CONST1, _) | (_, Const2) => ()
| |
| variable not in all patterns
|
help: if you meant to match on a variant or a `const` item, consider making the path in the pattern qualified: `?::CONST1`
--> $DIR/resolve-inconsistent-names.rs:30:10
note: you might have meant to match on constant `m::CONST1`, which exists but is inaccessible
--> $DIR/resolve-inconsistent-names.rs:6:5
|
LL | (CONST1, _) | (_, Const2) => ()
| ^^^^^^
LL | const CONST1: usize = 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible
error[E0408]: variable `Const2` is not bound in all patterns
--> $DIR/resolve-inconsistent-names.rs:30:9
@ -77,11 +76,10 @@ LL | (CONST1, _) | (_, Const2) => ()
| |
| pattern doesn't bind `Const2`
|
help: if you meant to match on a variant or a `const` item, consider making the path in the pattern qualified: `?::Const2`
--> $DIR/resolve-inconsistent-names.rs:30:27
help: if you meant to match on constant `m::Const2`, use the full path in the pattern
|
LL | (CONST1, _) | (_, Const2) => ()
| ^^^^^^
LL | (CONST1, _) | (_, m::Const2) => ()
| ~~~~~~~~~
error[E0308]: mismatched types
--> $DIR/resolve-inconsistent-names.rs:19:19

View file

@ -1,3 +1,13 @@
error[E0408]: variable `d` is not bound in all patterns
--> $DIR/issue-39698.rs:10:37
|
LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| - - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `d`
| | | |
| | | pattern doesn't bind `d`
| | variable not in all patterns
| variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/issue-39698.rs:10:23
|
@ -28,16 +38,6 @@ LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}
| | pattern doesn't bind `c`
| pattern doesn't bind `c`
error[E0408]: variable `d` is not bound in all patterns
--> $DIR/issue-39698.rs:10:37
|
LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| - - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `d`
| | | |
| | | pattern doesn't bind `d`
| | variable not in all patterns
| variable not in all patterns
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0408`.