tcx.sess.span_err(span, "`..` cannot be used in union patterns");
}
} else if !etc {
- for field in variant.fields
+ let unmentioned_fields = variant.fields
.iter()
- .filter(|field| !used_fields.contains_key(&field.name)) {
+ .map(|field| field.name)
+ .filter(|field| !used_fields.contains_key(&field))
+ .collect::<Vec<_>>();
+ if unmentioned_fields.len() > 0 {
+ let field_names = if unmentioned_fields.len() == 1 {
+ format!("field `{}`", unmentioned_fields[0])
+ } else {
+ format!("fields {}",
+ unmentioned_fields.iter()
+ .map(|name| format!("`{}`", name))
+ .collect::<Vec<String>>()
+ .join(", "))
+ };
let mut diag = struct_span_err!(tcx.sess, span, E0027,
- "pattern does not mention field `{}`",
- field.name);
- diag.span_label(span, format!("missing field `{}`", field.name));
+ "pattern does not mention {}",
+ field_names);
+ diag.span_label(span, format!("missing {}", field_names));
if variant.ctor_kind == CtorKind::Fn {
diag.note("trying to match a tuple variant with a struct variant pattern");
}
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");
}
}
--- /dev/null
+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 field `d`
+ | | | |
+ | | | struct `S` does not have field `c`
+ | | struct `S` does not have field `b`
+ | struct `S` does not have field `a`
+
+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`.