Change:
I tried this code: I expected to see this happen: A suggestion to change to Instead, this happened: A suggestion to change to (note the extra comma!) With the comma at the end, I get a parser error and a suggestion to remove the comma. Nightly on playground: 1.49.0-nightly (2020-10-27 )
modify labels: +A-diagnostics

Discussion:
/// Returns a diagnostic reporting a struct pattern which does not mention some fields. /// /// ```text <del> /// error[E0027]: pattern does not mention field `you_cant_use_this_field` </del> <ins> /// error[E0027]: pattern does not mention field `bar` </ins> ///   --> src/main.rs:15:9 ///    | /// LL |     let foo::Foo {} = foo::Foo::new(); <del> ///    |         ^^^^^^^^^^^ missing field `you_cant_use_this_field` </del> <ins> ///    |         ^^^^^^^^^^^ missing field `bar` </ins> /// ``` fn error_unmentioned_fields( &self,

} _ => return err, }, <del> [.., field] => ( match pat.kind { PatKind::Struct(_, [_, ..], _) => ", ", _ => "", }, "", field.span.shrink_to_hi(), ), </del> <ins> [.., field] => { // if last field has a trailing comma, use the comma // as the span to avoid trailing comma in ultimate // suggestion (Issue #78511) let tail = field.span.shrink_to_hi().until(pat.span.shrink_to_hi()); let tail_through_comma = self.tcx.sess.source_map().span_through_char(tail, ','); let sp = if tail_through_comma == tail { field.span.shrink_to_hi() } else { tail_through_comma }; ( match pat.kind { PatKind::Struct(_, [_, ..], _) => ", ", _ => "", }, "", sp, ) } </ins> }; err.span_suggestion( sp,

| help: include the missing field in the pattern | <del> LL |     Struct { a, b, _ } = Struct { a: 1, b: 2 }; </del> <ins> LL |     Struct { a, b _ } = Struct { a: 1, b: 2 }; </ins> |               ^^^ help: if you don't care about this missing field, you can explicitly ignore it | <del> LL |     Struct { a, .., _ } = Struct { a: 1, b: 2 }; </del> <ins> LL |     Struct { a, .. _ } = Struct { a: 1, b: 2 }; </ins> |               ^^^^ error: aborting due to 5 previous errors

age: u32, } fn main() { let d = Dog { name: "Rusty".to_string(), age: 8 };

Dog { age: x } => {} //~ ERROR pattern does not mention field `name` } match d { <ins> // trailing comma Dog { name: x, } => {} //~ ERROR pattern does not mention field `age` } match d { // trailing comma with weird whitespace Dog { name: x  , } => {} //~ ERROR pattern does not mention field `age` } match d { </ins> Dog {} => {} //~ ERROR pattern does not mention fields `name`, `age` } }

error[E0027]: pattern does not mention field `name` <del> --> $DIR/E0027.rs:10:9 </del> <ins> --> $DIR/E0027.rs:11:9 </ins> | LL |         Dog { age: x } => {} |         ^^^^^^^^^^^^^^ missing field `name`

LL |         Dog { age: x, .. } => {} |                     ^^^^ <ins> error[E0027]: pattern does not mention field `age` --> $DIR/E0027.rs:15:9 | LL |         Dog { name: x, } => {} |         ^^^^^^^^^^^^^^^^ missing field `age` | help: include the missing field in the pattern | LL |         Dog { name: x, age } => {} |                      ^^^^^ help: if you don't care about this missing field, you can explicitly ignore it | LL |         Dog { name: x, .. } => {} |                      ^^^^ error[E0027]: pattern does not mention field `age` --> $DIR/E0027.rs:19:9 | LL |         Dog { name: x  , } => {} |         ^^^^^^^^^^^^^^^^^^ missing field `age` | help: include the missing field in the pattern | LL |         Dog { name: x, age } => {} |                      ^^^^^ help: if you don't care about this missing field, you can explicitly ignore it | LL |         Dog { name: x, .. } => {} |                      ^^^^ </ins> error[E0027]: pattern does not mention fields `name`, `age` <del> --> $DIR/E0027.rs:13:9 </del> <ins> --> $DIR/E0027.rs:22:9 </ins> | LL |         Dog {} => {} |         ^^^^^^ missing fields `name`, `age`

LL |         Dog { .. } => {} |             ^^^^^^ <del> error: aborting due to 2 previous errors </del> <ins> error: aborting due to 4 previous errors </ins> For more information about this error, try `rustc --explain E0027`.