- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Closed
Copy link
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done