The Ident::parse_any in this code is here to support https://github.com/dtolnay/syn/issues/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:
The
Ident::parse_any
in this code is here to support https://github.com/dtolnay/syn/issues/517 in syn 0.15. At the time, the function argument infn 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 ofFnArg
held a Pat only, a Type only,self
,mut self
,&self
, or&mut self
, none of which are suitable for the formself: T
. Soself
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 butself
continues to be considered a legal Pat::Ident. Keywords other thanself
should not be, however. For example: