-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
A-resolveProposals relating to name resolution.Proposals relating to name resolution.A-syntaxSyntax related proposals & ideasSyntax related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
Proposal
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.
Search results in the rust-lang/rust repository
For example, consider the following code in library/std/src/sys/pal/sgx/net.rs
:
fn try_into_inner(self) -> Result<FileDesc, Socket> {
let Socket { inner, local_addr } = self;
Arc::try_unwrap(inner).map_err(|inner| Socket { inner, local_addr })
}
If self
were allowed as an identifier in identifier patterns, this could be written more concisely as:
fn try_into_inner(self @ Socket { inner, local_addr }) -> Result<FileDesc, Socket> {
Arc::try_unwrap(inner).map_err(|inner| Socket { inner, local_addr })
}
This is not only more concise but also more natural from a language specification standpoint.
naskya, yonipeleg33, Be3y4uu-K0T and bbb651
Metadata
Metadata
Assignees
Labels
A-resolveProposals relating to name resolution.Proposals relating to name resolution.A-syntaxSyntax related proposals & ideasSyntax related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.