Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest using Self in traits #66424

Closed
ChrisJefferson opened this issue Nov 14, 2019 · 0 comments · Fixed by #68377
Closed

Suggest using Self in traits #66424

ChrisJefferson opened this issue Nov 14, 2019 · 0 comments · Fixed by #68377
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.

Comments

@ChrisJefferson
Copy link
Contributor

I wrote the following trait: trait Area : Sized { fn f(a : Area) -> Area; }. What I meant (I've now discovered) was trait 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 use vector 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?"

@estebank estebank added 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 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. labels Nov 15, 2019
@Centril Centril added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Nov 15, 2019
@bors bors closed this as completed in 5b0caef Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants