Adjust spans

* Highlight the whole pattern if it has no fields
* Highlight the whole definition if it has no fields
* Only highlight the pattern name if the pattern is multi-line
* Determine whether a pattern is multi-line based on distance from name
  to last field, rather than first field
This commit is contained in:
Noah Lev 2021-08-25 14:40:06 -07:00
parent 19f45101e7
commit 8a6501d288
13 changed files with 211 additions and 85 deletions

View file

@ -992,7 +992,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let fields_ending = pluralize!(fields.len());
let subpat_spans = if subpats.is_empty() {
vec![pat_span.trim_start(qpath.span()).unwrap_or(pat_span)]
vec![pat_span]
} else {
subpats.iter().map(|p| p.span).collect()
};
@ -1000,7 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let res_span = self.tcx.def_span(res.def_id());
let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span);
let field_def_spans = if fields.is_empty() {
vec![res_span.trim_start(def_ident_span).unwrap_or(res_span)]
vec![res_span]
} else {
fields.iter().map(|f| f.ident.span).collect()
};
@ -1021,8 +1021,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
last_subpat_span,
&format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()),
);
err.span_label(qpath.span(), "");
if self.tcx.sess.source_map().is_multiline(def_ident_span.between(field_def_spans[0])) {
if self.tcx.sess.source_map().is_multiline(qpath.span().between(last_subpat_span)) {
err.span_label(qpath.span(), "");
}
if self.tcx.sess.source_map().is_multiline(def_ident_span.between(last_field_def_span)) {
err.span_label(def_ident_span, format!("{} defined here", res.descr()));
}
for span in &field_def_spans[..field_def_spans.len() - 1] {

View file

@ -21,7 +21,7 @@ LL | struct TupleStruct<S, T>(S, T);
| - - tuple struct has 2 fields
...
LL | TupleStruct(a, a, b) = TupleStruct(1, 2);
| ----------- ^ ^ ^ expected 2 fields, found 3
| ^ ^ ^ expected 2 fields, found 3
error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields
--> $DIR/tuple_struct_destructure_fail.rs:32:17
@ -30,7 +30,7 @@ LL | struct TupleStruct<S, T>(S, T);
| - - tuple struct has 2 fields
...
LL | TupleStruct(_) = TupleStruct(1, 2);
| ----------- ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -48,7 +48,7 @@ LL | SingleVariant(S, T)
| - - tuple variant has 2 fields
...
LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2);
| ------------------- ^ ^ ^ expected 2 fields, found 3
| ^ ^ ^ expected 2 fields, found 3
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> $DIR/tuple_struct_destructure_fail.rs:36:25
@ -57,7 +57,7 @@ LL | SingleVariant(S, T)
| - - tuple variant has 2 fields
...
LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2);
| ------------------- ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|

View file

@ -5,7 +5,7 @@ LL | Apple(String, String),
| ------ ------ tuple variant has 2 fields
...
LL | Fruit::Apple(a) => {},
| ------------ ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -19,7 +19,7 @@ LL | Apple(String, String),
| ------ ------ tuple variant has 2 fields
...
LL | Fruit::Apple(a, b, c) => {},
| ------------ ^ ^ ^ expected 2 fields, found 3
| ^ ^ ^ expected 2 fields, found 3
error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
--> $DIR/E0023.rs:13:21
@ -28,7 +28,7 @@ LL | Pear(u32),
| --- tuple variant has 1 field
...
LL | Fruit::Pear(1, 2) => {},
| ----------- ^ ^ expected 1 field, found 2
| ^ ^ expected 1 field, found 2
error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
--> $DIR/E0023.rs:14:23
@ -37,7 +37,7 @@ LL | Orange((String, String)),
| ---------------- tuple variant has 1 field
...
LL | Fruit::Orange(a, b) => {},
| ------------- ^ ^ expected 1 field, found 2
| ^ ^ expected 1 field, found 2
|
help: missing parentheses
|
@ -45,13 +45,13 @@ LL | Fruit::Orange((a, b)) => {},
| + +
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field
--> $DIR/E0023.rs:15:22
--> $DIR/E0023.rs:15:9
|
LL | Banana(()),
| -- tuple variant has 1 field
...
LL | Fruit::Banana() => {},
| -------------^^ expected 1 field, found 0
| ^^^^^^^^^^^^^^^ expected 1 field, found 0
|
help: missing parentheses
|

View file

@ -25,7 +25,7 @@ LL | struct Binder(i32, i32, i32);
| --- --- --- tuple struct has 3 fields
...
LL | Binder(_a, _x @ ..) => {}
| ------ ^^ ^^^^^^^ expected 3 fields, found 2
| ^^ ^^^^^^^ expected 3 fields, found 2
|
help: use `_` to explicitly ignore each field
|

View file

@ -5,7 +5,7 @@ LL | Rgb(usize, usize, usize),
| ----- ----- ----- tuple variant has 3 fields
...
LL | Color::Rgb(_, _) => { }
| ---------- ^ ^ expected 3 fields, found 2
| ^ ^ expected 3 fields, found 2
|
help: use `_` to explicitly ignore each field
|

View file

@ -10,13 +10,13 @@ LL | let P() = U {};
found struct `P<_>`
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field
--> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10
--> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9
|
LL | struct P<T>(T); // 1 type parameter wanted
| - tuple struct has 1 field
...
LL | let P() = U {};
| -^^ expected 1 field, found 0
| ^^^ expected 1 field, found 0
|
help: use `_` to explicitly ignore each field
|

View file

@ -25,7 +25,7 @@ LL | A(u8, u8),
| -- -- tuple variant has 2 fields
...
LL | E::A(x @ ..) => {
| ---- ^^^^^^ expected 2 fields, found 1
| ^^^^^^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|

View file

@ -121,7 +121,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0
--> $DIR/pat-tuple-field-count-cross.rs:14:12
|
LL | Z1(x) => {}
| -- ^ expected 0 fields, found 1
| ^ expected 0 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:2:1
|
@ -129,10 +129,10 @@ LL | pub struct Z1();
| ---------------- tuple struct has 0 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:18:10
--> $DIR/pat-tuple-field-count-cross.rs:18:9
|
LL | S() => {}
| -^^ expected 3 fields, found 0
| ^^^ expected 3 fields, found 0
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14
|
@ -152,7 +152,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3
--> $DIR/pat-tuple-field-count-cross.rs:19:11
|
LL | S(1) => {}
| - ^ expected 3 fields, found 1
| ^ expected 3 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14
|
@ -172,7 +172,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has
--> $DIR/pat-tuple-field-count-cross.rs:20:11
|
LL | S(xyz, abc) => {}
| - ^^^ ^^^ expected 3 fields, found 2
| ^^^ ^^^ expected 3 fields, found 2
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14
|
@ -188,7 +188,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has
--> $DIR/pat-tuple-field-count-cross.rs:21:11
|
LL | S(1, 2, 3, 4) => {}
| - ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14
|
@ -196,10 +196,10 @@ LL | pub struct S(pub u8, pub u8, pub u8);
| ------ ------ ------ tuple struct has 3 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:24:10
--> $DIR/pat-tuple-field-count-cross.rs:24:9
|
LL | M() => {}
| -^^ expected 3 fields, found 0
| ^^^ expected 3 fields, found 0
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1
|
@ -226,7 +226,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3
--> $DIR/pat-tuple-field-count-cross.rs:25:11
|
LL | M(1) => {}
| - ^ expected 3 fields, found 1
| ^ expected 3 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1
|
@ -253,7 +253,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has
--> $DIR/pat-tuple-field-count-cross.rs:26:11
|
LL | M(xyz, abc) => {}
| - ^^^ ^^^ expected 3 fields, found 2
| ^^^ ^^^ expected 3 fields, found 2
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1
|
@ -276,7 +276,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has
--> $DIR/pat-tuple-field-count-cross.rs:27:11
|
LL | M(1, 2, 3, 4) => {}
| - ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1
|
@ -294,7 +294,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:36:16
|
LL | E1::Z1(x) => {}
| ------ ^ expected 0 fields, found 1
| ^ expected 0 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19
|
@ -302,10 +302,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| ---- tuple variant has 0 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:39:14
--> $DIR/pat-tuple-field-count-cross.rs:39:9
|
LL | E1::S() => {}
| -----^^ expected 3 fields, found 0
| ^^^^^^^ expected 3 fields, found 0
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27
|
@ -325,7 +325,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:40:15
|
LL | E1::S(1) => {}
| ----- ^ expected 3 fields, found 1
| ^ expected 3 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27
|
@ -345,7 +345,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:41:15
|
LL | E1::S(xyz, abc) => {}
| ----- ^^^ ^^^ expected 3 fields, found 2
| ^^^ ^^^ expected 3 fields, found 2
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27
|
@ -361,7 +361,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:42:15
|
LL | E1::S(1, 2, 3, 4) => {}
| ----- ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27
|
@ -369,10 +369,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| -- -- -- tuple variant has 3 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:46:14
--> $DIR/pat-tuple-field-count-cross.rs:46:9
|
LL | E2::S() => {}
| -----^^ expected 3 fields, found 0
| ^^^^^^^ expected 3 fields, found 0
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7
|
@ -392,7 +392,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:47:15
|
LL | E2::S(1) => {}
| ----- ^ expected 3 fields, found 1
| ^ expected 3 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7
|
@ -412,7 +412,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:48:15
|
LL | E2::S(xyz, abc) => {}
| ----- ^^^ ^^^ expected 3 fields, found 2
| ^^^ ^^^ expected 3 fields, found 2
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7
|
@ -428,7 +428,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:49:15
|
LL | E2::S(1, 2, 3, 4) => {}
| ----- ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7
|
@ -436,10 +436,10 @@ LL | S(u8, u8, u8),
| -- -- -- tuple variant has 3 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:52:14
--> $DIR/pat-tuple-field-count-cross.rs:52:9
|
LL | E2::M() => {}
| -----^^ expected 3 fields, found 0
| ^^^^^^^ expected 3 fields, found 0
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5
|
@ -466,7 +466,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:53:15
|
LL | E2::M(1) => {}
| ----- ^ expected 3 fields, found 1
| ^ expected 3 fields, found 1
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5
|
@ -493,7 +493,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:54:15
|
LL | E2::M(xyz, abc) => {}
| ----- ^^^ ^^^ expected 3 fields, found 2
| ^^^ ^^^ expected 3 fields, found 2
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5
|
@ -516,7 +516,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-field-count-cross.rs:55:15
|
LL | E2::M(1, 2, 3, 4) => {}
| ----- ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
|
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5
|

View file

@ -30,6 +30,22 @@ fn main() {
match M(1, 2, 3, 4, 5) {
M(1, 2, 3, 4, 5, 6) => {}
//~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields
M(1,
2,
3,
4,
5,
6) => {}
//~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields
M(
1,
2,
3,
4,
5,
6,
) => {}
//~^^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields
}
match Z0 {
Z0 => {}

View file

@ -1,5 +1,5 @@
error[E0530]: match bindings cannot shadow tuple structs
--> $DIR/pat-tuple-overfield.rs:41:9
--> $DIR/pat-tuple-overfield.rs:57:9
|
LL | struct Z1();
| ------------ the tuple struct `Z1` is defined here
@ -8,7 +8,7 @@ LL | Z1 => {}
| ^^ cannot be named the same as a tuple struct
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:36:9
--> $DIR/pat-tuple-overfield.rs:52:9
|
LL | struct Z0;
| ---------- `Z0` defined here
@ -28,7 +28,7 @@ LL | Z1() => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:37:9
--> $DIR/pat-tuple-overfield.rs:53:9
|
LL | struct Z0;
| ---------- `Z0` defined here
@ -48,7 +48,7 @@ LL | Z1(_) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:38:9
--> $DIR/pat-tuple-overfield.rs:54:9
|
LL | struct Z0;
| ---------- `Z0` defined here
@ -68,7 +68,7 @@ LL | Z1(_, _) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:48:9
--> $DIR/pat-tuple-overfield.rs:64:9
|
LL | Z0,
| -- `E1::Z0` defined here
@ -88,7 +88,7 @@ LL | E1::Z1() => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:49:9
--> $DIR/pat-tuple-overfield.rs:65:9
|
LL | Z0,
| -- `E1::Z0` defined here
@ -108,7 +108,7 @@ LL | E1::Z1(_) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:50:9
--> $DIR/pat-tuple-overfield.rs:66:9
|
LL | Z0,
| -- `E1::Z0` defined here
@ -128,7 +128,7 @@ LL | E1::Z1(_, _) => {}
| ~~
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
--> $DIR/pat-tuple-overfield.rs:53:9
--> $DIR/pat-tuple-overfield.rs:69:9
|
LL | Z0,
| -- similarly named unit variant `Z0` defined here
@ -177,7 +177,7 @@ LL | struct S(u8, u8, u8);
| -- -- -- tuple struct has 3 fields
...
LL | S(1, 2, 3, 4) => {}
| - ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields
--> $DIR/pat-tuple-overfield.rs:26:11
@ -186,7 +186,7 @@ LL | struct S(u8, u8, u8);
| -- -- -- tuple struct has 3 fields
...
LL | S(1, 2, .., 3, 4) => {}
| - ^ ^ ^ ^ expected 3 fields, found 4
| ^ ^ ^ ^ expected 3 fields, found 4
error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields
--> $DIR/pat-tuple-overfield.rs:31:11
@ -205,45 +205,105 @@ LL | u8,
| -- tuple struct has 5 fields
...
LL | M(1, 2, 3, 4, 5, 6) => {}
| - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6
| ^ ^ ^ ^ ^ ^ expected 5 fields, found 6
error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields
--> $DIR/pat-tuple-overfield.rs:33:11
|
LL | struct M(
| - tuple struct defined here
LL | u8,
| --
LL | u8,
| --
LL | u8,
| --
LL | u8,
| --
LL | u8,
| -- tuple struct has 5 fields
...
LL | M(1,
| - ^
LL | 2,
| ^
LL | 3,
| ^
LL | 4,
| ^
LL | 5,
| ^
LL | 6) => {}
| ^ expected 5 fields, found 6
error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields
--> $DIR/pat-tuple-overfield.rs:41:13
|
LL | struct M(
| - tuple struct defined here
LL | u8,
| --
LL | u8,
| --
LL | u8,
| --
LL | u8,
| --
LL | u8,
| -- tuple struct has 5 fields
...
LL | M(
| -
LL | 1,
| ^
LL | 2,
| ^
LL | 3,
| ^
LL | 4,
| ^
LL | 5,
| ^
LL | 6,
| ^ expected 5 fields, found 6
error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields
--> $DIR/pat-tuple-overfield.rs:43:12
--> $DIR/pat-tuple-overfield.rs:59:12
|
LL | struct Z1();
| --- tuple struct has 0 fields
| ------------ tuple struct has 0 fields
...
LL | Z1(_) => {}
| -- ^ expected 0 fields, found 1
| ^ expected 0 fields, found 1
error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields
--> $DIR/pat-tuple-overfield.rs:44:12
--> $DIR/pat-tuple-overfield.rs:60:12
|
LL | struct Z1();
| --- tuple struct has 0 fields
| ------------ tuple struct has 0 fields
...
LL | Z1(_, _) => {}
| -- ^ ^ expected 0 fields, found 2
| ^ ^ expected 0 fields, found 2
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields
--> $DIR/pat-tuple-overfield.rs:55:16
--> $DIR/pat-tuple-overfield.rs:71:16
|
LL | Z1(),
| -- tuple variant has 0 fields
| ---- tuple variant has 0 fields
...
LL | E1::Z1(_) => {}
| ------ ^ expected 0 fields, found 1
| ^ expected 0 fields, found 1
error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields
--> $DIR/pat-tuple-overfield.rs:56:16
--> $DIR/pat-tuple-overfield.rs:72:16
|
LL | Z1(),
| -- tuple variant has 0 fields
| ---- tuple variant has 0 fields
...
LL | E1::Z1(_, _) => {}
| ------ ^ ^ expected 0 fields, found 2
| ^ ^ expected 0 fields, found 2
error: aborting due to 17 previous errors
error: aborting due to 19 previous errors
Some errors have detailed explanations: E0023, E0308, E0530, E0532.
For more information about an error, try `rustc --explain E0023`.

View file

@ -21,6 +21,12 @@ fn main() {
//~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
// Test non-standard formatting
S () => {}
//~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
}
match E::S(0, 1.0) {
@ -39,6 +45,12 @@ fn main() {
//~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
// Test non-standard formatting
E::S () => {}
//~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
}
match E::S(0, 1.0) {
E::S => {}

View file

@ -1,5 +1,5 @@
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E::S`
--> $DIR/pat-tuple-underfield.rs:44:9
--> $DIR/pat-tuple-underfield.rs:56:9
|
LL | S(i32, f32),
| ----------- `E::S` defined here
@ -14,7 +14,7 @@ LL | struct S(i32, f32);
| --- --- tuple struct has 2 fields
...
LL | S(x) => {}
| - ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -28,7 +28,7 @@ LL | struct S(i32, f32);
| --- --- tuple struct has 2 fields
...
LL | S(_) => {}
| - ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -40,13 +40,13 @@ LL | S(..) => {}
| ~~
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
--> $DIR/pat-tuple-underfield.rs:20:10
--> $DIR/pat-tuple-underfield.rs:20:9
|
LL | struct S(i32, f32);
| --- --- tuple struct has 2 fields
...
LL | S() => {}
| -^^ expected 2 fields, found 0
| ^^^ expected 2 fields, found 0
|
help: use `_` to explicitly ignore each field
|
@ -57,14 +57,32 @@ help: use `..` to ignore all fields
LL | S(..) => {}
| ++
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
--> $DIR/pat-tuple-underfield.rs:26:9
|
LL | struct S(i32, f32);
| --- --- tuple struct has 2 fields
...
LL | S () => {}
| ^^^^ expected 2 fields, found 0
|
help: use `_` to explicitly ignore each field
|
LL | S (_, _) => {}
| ++++
help: use `..` to ignore all fields
|
LL | S (..) => {}
| ++
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:27:14
--> $DIR/pat-tuple-underfield.rs:33:14
|
LL | S(i32, f32),
| --- --- tuple variant has 2 fields
...
LL | E::S(x) => {}
| ---- ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -72,13 +90,13 @@ LL | E::S(x, _) => {}
| +++
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:32:14
--> $DIR/pat-tuple-underfield.rs:38:14
|
LL | S(i32, f32),
| --- --- tuple variant has 2 fields
...
LL | E::S(_) => {}
| ---- ^ expected 2 fields, found 1
| ^ expected 2 fields, found 1
|
help: use `_` to explicitly ignore each field
|
@ -90,13 +108,13 @@ LL | E::S(..) => {}
| ~~
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:38:13
--> $DIR/pat-tuple-underfield.rs:44:9
|
LL | S(i32, f32),
| --- --- tuple variant has 2 fields
...
LL | E::S() => {}
| ----^^ expected 2 fields, found 0
| ^^^^^^ expected 2 fields, found 0
|
help: use `_` to explicitly ignore each field
|
@ -107,14 +125,32 @@ help: use `..` to ignore all fields
LL | E::S(..) => {}
| ++
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:50:9
|
LL | S(i32, f32),
| --- --- tuple variant has 2 fields
...
LL | E::S () => {}
| ^^^^^^^ expected 2 fields, found 0
|
help: use `_` to explicitly ignore each field
|
LL | E::S (_, _) => {}
| ++++
help: use `..` to ignore all fields
|
LL | E::S (..) => {}
| ++
error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields
--> $DIR/pat-tuple-underfield.rs:50:19
--> $DIR/pat-tuple-underfield.rs:62:19
|
LL | struct Point4(i32, i32, i32, i32);
| --- --- --- --- tuple struct has 4 fields
...
LL | Point4( a , _ ) => {}
| ------ ^ ^ expected 4 fields, found 2
| ^ ^ expected 4 fields, found 2
|
help: use `_` to explicitly ignore each field
|
@ -125,7 +161,7 @@ help: use `..` to ignore the rest of the fields
LL | Point4( a, ..) => {}
| ~~~~
error: aborting due to 8 previous errors
error: aborting due to 10 previous errors
Some errors have detailed explanations: E0023, E0532.
For more information about an error, try `rustc --explain E0023`.

View file

@ -32,7 +32,7 @@ LL | B(isize, isize),
| ----- ----- tuple variant has 2 fields
...
LL | A::B(_, _, _) => (),
| ---- ^ ^ ^ expected 2 fields, found 3
| ^ ^ ^ expected 2 fields, found 3
error[E0308]: mismatched types
--> $DIR/pattern-error-continue.rs:22:9