- Start Date: 2015-01-18
- RFC PR: rust-lang/rfcs#593
- Rust Issue: rust-lang/rust#22137
Summary
Make Self
a keyword.
Motivation
Right now, Self
is just a regularSelf
, which can lead to weird situations:
This piece of code definesSelf
and Foo
, and a method foo()
that because of the special meaning of Self
has the signaturefn(&Foo, Foo)
.
So in this case it is not possible to defineFoo
that takesSelf
without renaming it or creating a renamed alias.
It would also be highly unidiomatic to actually name the type Self
for a custom type, precisely
Making the identifierSelf
an keyword would prevent
Detailed design設計(する)
Make the identifierSelf
a keyword that is only legalSelf
type.
Drawbacks
It might be unnecessary churn because people already don't run into this in practice.
Alternatives
Keep the status quo. It isn't a problem in practice, and just means Self
is the special case of a contextual type definition
Unresolved questions
None so far