Skip to content

Check for legal binding name in the ident of Pat::Ident#1627

Merged
dtolnay merged 1 commit intomasterfrom
patident
Apr 18, 2024
Merged

Check for legal binding name in the ident of Pat::Ident#1627
dtolnay merged 1 commit intomasterfrom
patident

Conversation

@dtolnay
Copy link
Copy Markdown
Owner

@dtolnay dtolnay commented Apr 18, 2024

The Ident::parse_any in this code is here to support #517 in syn 0.15. At the time, the function argument in fn f(self: T) was parsed as https://docs.rs/syn/0.15.44/syn/enum.FnArg.html#variant.Captured in the form of a Pat, colon token, and Type. The only other variants of FnArg held a Pat only, a Type only, self, mut self, &self, or &mut self, none of which are suitable for the form self: T. So self needed to be handled as some kind of Pat, and Pat::Ident was selected. (It might alternatively have been Pat::Path.)

These days in syn 2, the function argument in fn f(self: T) is parsed as https://docs.rs/syn/2/syn/struct.Receiver.html but self continues to be considered a legal Pat::Ident. Keywords other than self should not be, however. For example:

if let Some(ref mut extern) = x {}

@dtolnay dtolnay merged commit 1b20403 into master Apr 18, 2024
@dtolnay dtolnay deleted the patident branch April 18, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant