Summary

Make Self a keyword.

Motivation

Right now, Self is just a regular

普通の、正規の
identifier
識別子
that happens to get a special meaning inside trait definitions
定義
and impls. Specifically,
特に
users are not forbidden from defining
定義する
a type called
呼び出し
Self, which can lead to weird situations:

#![allow(unused)] fn main() { struct Self; struct Foo; impl Foo { fn foo(&self, _: Self) {} } }

This piece of code defines

定義する
types called
呼び出し
Self and Foo, and a method foo() that because of the special meaning of Self has the signature
シグネチャ
fn(&Foo, Foo).

So in this case it is not possible to define

定義する
a method on Foo that takes
とる
the actual
実際の
type Self 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

正確に
because of this ambiguity,
曖昧さ
so preventing
防ぐ
it outright seems like the right thing to do.

Making the identifier

識別子
Self an keyword would prevent
防ぐ
this situation because the user could not use it freely for custom definitions.
定義

Detailed design
設計(する)

Make the identifier

識別子
Self a keyword that is only legal
(文法的に)適格
to use inside a trait definition
定義
or impl to refer
参照する
to the Self 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

定義
in the language.
言語

Unresolved questions

None so far