Skip to content

Conversation

@InvalidPathException
Copy link
Contributor

Fixes #148391

Root cause:
async closures are treated like plain Fn closures because we never updated their kind after adding the async coroutine path.

Symptom:
The compiler note tells users closure implements Fn…, which is wrong for async closures and made the error message confusing. Notably FnMut does not suffer from this issue.

Fix:
With this fix we treat coroutine closures as FnOnce when building that note.

Testing:
Updated a UI test stderr file to reflect the correct wording. It also clearly demonstrates what was wrong.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

"closure implements `FnOnce`, so references to captured variables \
can't escape the closure"
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way this can look like

let note = format!("closure implements `{}`, so references to captured variables can't escape the closure", closure_kind.as_str());

Copy link
Contributor Author

@InvalidPathException InvalidPathException Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about this. Correct me if I'm wrong, RegionNameSource stores these as &'static str but format! gives String, so we cannot really get around it (at least in this way). If we do refactor then it might be a lot of diff for something we do not touch for years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics incorrectly states that async closure implements Fn.

4 participants