You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow the use of self as an identifier in identifier patterns (foo @ Foo { bar, baz }).
Motivation
As seen in the following search results within the rust-lang/rust repository, there are numerous instances where developers want to destructure a struct in a let statement with self on the right-hand side.
But what about &self and &mut self? We can write &self as a shorthand for self: &Self, but it might be confusing if &self @ Foo { bar, baz } was desugared into self @ Foo { bar, baz }: &Self. There are two possible ways:
Allow only self in patterns, and disallow &self and &mut self (so that we have to write as self @ Foo { bar, baz }: &Self)
Let &self @ Foo { bar, baz } and &mut self @ Foo { bar, baz } be shorthands for self @ Foo { bar, baz }: &Self and self @ Foo { bar, baz }: &mut Self, respectively.
Reacted by kennytm, zachs18, chansuke, Lucky_Cat, bbb651 🇮🇱 and Teoh Han Hui
Activity
fiveseven-lambda commentedon Aug 26, 2024
But what about
&selfand&mut self? We can write&selfas a shorthand forself: &Self, but it might be confusing if&self @ Foo { bar, baz }was desugared intoself @ Foo { bar, baz }: &Self. There are two possible ways:selfin patterns, and disallow&selfand&mut self(so that we have to write asself @ Foo { bar, baz }: &Self)&self @ Foo { bar, baz }and&mut self @ Foo { bar, baz }be shorthands forself @ Foo { bar, baz }: &Selfandself @ Foo { bar, baz }: &mut Self, respectively.