Rollup merge of #49160 - estebank:issue-47457-missing-fields, r=oli-obk

Reduce the diagnostic spam when multiple fields are missing in pattern

Fix #47457.
This commit is contained in:
Alex Crichton 2018-03-23 09:27:22 -05:00
commit 401a93096d
9 changed files with 104 additions and 42 deletions

View file

@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
--> $DIR/E0026-teach.rs:21:23
|
LL | Thing { x, y, z } => {}
| ^ struct `Thing` does not have field `z`
| ^ struct `Thing` does not have this field
|
= note: This error indicates that a struct pattern attempted to extract a non-existent field from a struct. Struct fields are identified by the name used before the colon : so struct patterns should resemble the declaration of the struct type being matched.

View file

@ -2,7 +2,7 @@ error[E0026]: struct `Thing` does not have a field named `z`
--> $DIR/E0026.rs:19:23
|
LL | Thing { x, y, z } => {}
| ^ struct `Thing` does not have field `z`
| ^ struct `Thing` does not have this field
error: aborting due to previous error

View file

@ -0,0 +1,19 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S(usize, usize, usize, usize);
fn main() {
if let S { a, b, c, d } = S(1, 2, 3, 4) {
//~^ ERROR struct `S` does not have fields named `a`, `b`, `c`, `d` [E0026]
//~| ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
println!("hi");
}
}

View file

@ -0,0 +1,18 @@
error[E0026]: struct `S` does not have fields named `a`, `b`, `c`, `d`
--> $DIR/missing-fields-in-struct-pattern.rs:14:16
|
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
| ^ ^ ^ ^ struct `S` does not have these fields
error[E0027]: pattern does not mention fields `0`, `1`, `2`, `3`
--> $DIR/missing-fields-in-struct-pattern.rs:14:12
|
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
| ^^^^^^^^^^^^^^^^ missing fields `0`, `1`, `2`, `3`
|
= note: trying to match a tuple variant with a struct variant pattern
error: aborting due to 2 previous errors
Some errors occurred: E0026, E0027.
For more information about an error, try `rustc --explain E0026`.

View file

@ -10,7 +10,7 @@ error[E0026]: struct `S` does not have a field named `0x1`
--> $DIR/numeric-fields.rs:17:17
|
LL | S{0: a, 0x1: b, ..} => {}
| ^^^^^^ struct `S` does not have field `0x1`
| ^^^^^^ struct `S` does not have this field
error: aborting due to 2 previous errors

View file

@ -2,7 +2,7 @@ error[E0026]: variant `X::Y` does not have a field named `number`
--> $DIR/issue-41314.rs:17:16
|
LL | X::Y { number } => {} //~ ERROR does not have a field named `number`
| ^^^^^^ variant `X::Y` does not have field `number`
| ^^^^^^ variant `X::Y` does not have this field
error[E0027]: pattern does not mention field `0`
--> $DIR/issue-41314.rs:17:9

View file

@ -52,7 +52,7 @@ error[E0026]: union `U` does not have a field named `c`
--> $DIR/union-fields-2.rs:28:19
|
LL | let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
| ^ union `U` does not have field `c`
| ^ union `U` does not have this field
error: union patterns should have exactly one field
--> $DIR/union-fields-2.rs:28:9