Destructuring arguments in trait methods with bodies fails with a syntax error · Issue #55036 · rust-lang/rust (original) (raw)

You can't destructure an argument in a trait method which has code in the body.

This should work fine. Destructuring an argument in a trait method seems totally reasonable.

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `{`
 --> test.rs:8:25
  |
8 |     fn foo_in_trait(Foo { bar }: Foo) {
  |                         ^ expected one of 7 possible tokens here

error: expected one of `!`, `(`, `)`, `+`, `-`, `::`, `<`, `_`, `box`, `false`, `mut`, `ref`, or `true`, found `{`
 --> test.rs:8:25
  |
8 |     fn foo_in_trait(Foo { bar }: Foo) {
  |                         ^ expected one of 13 possible tokens here

error: expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found `:`
 --> test.rs:8:32
  |
8 |     fn foo_in_trait(Foo { bar }: Foo) {
  |                                ^ expected one of 7 possible tokens here

This might be related to #53051, maybe? In particular, I would expect to see the error message from that pull request in this case, if this were validly invalid code.