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

Improve error message for "return type cannot contain a projection or Self..." #78600

Closed
gliderkite opened this issue Oct 31, 2020 · 1 comment · Fixed by #82021
Closed

Improve error message for "return type cannot contain a projection or Self..." #78600

gliderkite opened this issue Oct 31, 2020 · 1 comment · Fixed by #82021
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: suggestions generated by the compiler applied by cargo fix AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gliderkite
Copy link

Following the improvement for the diagnostic of the error reported in this issue #69276, it would be nice (depending on how #61949 is prioritized) to have the same error message when instead of returning Self the function returns Result<Self, Error>.

When Self is returned I get a nice error message (on rustc 1.47):

struct S<'a>(&'a i32);

impl<'a> S<'a> {
    async fn new(i: &'a i32) -> Self {
        S(&22)
    }
}
error[E0760]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
 --> src/lib.rs:4:33
  |
4 |     async fn new(i: &'a i32) -> Self {
  |                                 ^^^^ help: consider spelling out the type instead: `S<'a>`

But if Result<Self, Error> is used I get:

struct S<'a>(&'a i32);

impl<'a> S<'a> {
    async fn new(i: &'a i32) -> Result<Self, ()> {
        Ok(S(&22))
    }
}
error[E0760]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
 --> src/lib.rs:4:33
  |
4 |     async fn new(i: &'a i32) -> Result<Self, ()> {
  |                                 ^^^^^^^^^^^^^^^^

with no suggestion to spell the type.

Link to Playground

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: suggestions generated by the compiler applied by cargo fix C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 31, 2020
@csmoe csmoe self-assigned this Nov 2, 2020
@tmandry tmandry added this to On deck in wg-async work via automation Dec 11, 2020
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Dec 11, 2020
@tmandry tmandry moved this from On deck to Claimed in wg-async work Dec 11, 2020
@tmandry
Copy link
Contributor

tmandry commented Jan 28, 2021

@rustbot remove-assignment

@csmoe feel free to re-claim if you are working on this.

@tmandry tmandry moved this from Claimed to On deck in wg-async work Jan 28, 2021
@bors bors closed this as completed in f7501b6 Feb 18, 2021
wg-async work automation moved this from On deck to Done Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: suggestions generated by the compiler applied by cargo fix AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants