Repository navigation
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-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-bugCategory: This is a bug.Category: This is a bug.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.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Description
struct Struct { }
impl Struct {
async fn async_fn(self: &Struct, f: &u32) -> &u32 {
f
}
fn sync_fn(self: &Struct, f: &u32) -> &u32 {
f
}
}Output (playground)
Compiling playground v0.0.1 (/playground)
error[E0623]: lifetime mismatch
--> src/main.rs:5:9
|
4 | async fn async_fn(self: &Struct, f: &u32) -> &u32 {
| ------- ----
| |
| this parameter and the return type are declared with different lifetimes...
5 | f
| ^ ...but data from `f` is returned here
error[E0623]: lifetime mismatch
--> src/main.rs:9:9
|
8 | fn sync_fn(self: &Struct, f: &u32) -> &u32 {
| ---- ----
| |
| this parameter and the return type are declared with different lifetimes...
9 | f
| ^ ...but data from `f` is returned here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0623`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
The error in sync_fn is correct, but the one for async_fn incorrectly claims the return type lifetime is different from self's lifetime, when they are in fact the same per the elision rules.
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-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-bugCategory: This is a bug.Category: This is a bug.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.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Type
Projects
- StatusShow more project fieldsDone
Activity
ayazhafiz commentedon Jul 12, 2020
related: #63499
tmandry commentedon Jul 14, 2020
Seems related to #74072. Triaging as On Deck since this is an incorrect diagnostic which can cause confusion.
SNCPlay42 commentedon Jul 22, 2020
Another case:
Output (playground)
The error message for
async_fnrefers to returning when no returning is involved!SNCPlay42 commentedon Jul 22, 2020
Output for the async functions in both cases with
#![feature(nll)]: (playground)Looks like this can be tagged as fixed by NLL.
eholk commentedon Sep 8, 2021
@SNCPlay42 - since this is tagged as fixed by NLL, do you think we can go ahead and close the whole issue?
tmandry commentedon Sep 9, 2021
This still reproduces for me. Adding
#![feature(nll)]does fix the issue, I'm not sure what we're using that feature for nowadays.eholk commentedon Sep 16, 2021
@rustbot claim
6 remaining items
eholk commentedon Oct 18, 2021
@rustbot label +AsyncAwait-Polish
Rollup merge of rust-lang#92183 - tmandry:issue-74256, r=estebank
Rollup merge of rust-lang#92183 - tmandry:issue-74256, r=estebank
tmandry commentedon Apr 14, 2022
There is a remaining issue not fixed by #92183 which I'll attempt to elucidate here.
In
try_report_anon_anon_conflict, we are reporting an error with two anonymous lifetimes. We rely on the fact that anonymous lifetimes can only be introduced in parameters, and the only other place they can appear is the return type. To check if the conflict occurs in the return type, we check to see if either lifetime appears in the return type. If it does, we highlight the return type and the parameter corresponding to the other lifetime.This is a little broken. Just because a lifetime appears in the return type does not necessarily mean the return type had anything to do with the current error. We want to know what types the failing lifetime obligation came from, and the span of those types. For example, for each lifetime it could be
impl Future<Output = &'a i32>)estebank commentedon Aug 3, 2023
Current output:
compiler-errors commentedon Dec 31, 2024
this works now.