Suggest using Self in traits #66424
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
A-trait-system
Area: Trait system
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I wrote the following trait:
trait Area : Sized { fn f(a : Area) -> Area; }
. What I meant (I've now discovered) wastrait Area : Sized { fn f(a : Self) -> Self; }
. However, it isn't easy to get "to that point".Reading the pages linked to from the compiler warning, and the rust book, I didn't find anything which discussed what using the name of a trait inside the trait means -- in particular (and this was I believe the source of my confusion), it isn't like C++ where, while defining
template<typename T> vector { ... }
, we usevector
to refer to the type we are currently defining.I'm not suggesting a change of behaviour, but I wonder if this could be a common enough bug to say "did you mean Self?"
The text was updated successfully, but these errors were encountered: