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

Diagnostic for dyn Self could be more specific #58531

Open
wchargin opened this issue Feb 17, 2019 · 2 comments
Open

Diagnostic for dyn Self could be more specific #58531

wchargin opened this issue Feb 17, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wchargin
Copy link
Contributor

Code (play):

trait S {
    fn f() -> dyn Self;
}

Current diagnostic (1.34.0-nightly 2019-02-15 eac0908):

error[E0411]: expected trait, found self type `Self`
 --> src/lib.rs:2:19
  |
2 |     fn f() -> dyn Self;
  |                   ^^^^ `Self` is only available in impls, traits, and type definitions

@Moongoodboy-K on IRC points out that it might be more helpful for the
diagnostic to say something like,

expected trait, found concrete type Self

(help: Self refers to the concrete type implementing this trait)

(For context: while I’ve since learned that this code is pretty far from
valid, the intent was to find a way to use Self-types while preserving
object-safety. My intuition was that it should suffice to return the
receiver’s vtable from the function, which suggested to me the syntax
dyn Self. Using simply fn f() -> dyn S is object-safe but loses the
self-typing, which might matter if given something like dyn S + Send.)

@theastrallyforged
Copy link

TFW you only read the annotation next to the highlight, and entirely miss the error heading. xD

The heading is spot-on; it's just that Self is only available in impls, traits, and type definitions bit that doesn't make sense (what? this is a trait definition!)

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system labels Feb 17, 2019
@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2019
@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@estebank
Copy link
Contributor

estebank commented May 2, 2024

Similar case: #50871

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-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants