1
Fork 0

Rollup merge of #139871 - GuillaumeGomez:async-gen-move, r=compiler-errors

Fix wrong "move keyword" suggestion for async gen block

Fixes #139839.

It was just missing a string comparison with `async gen`.
This commit is contained in:
Matthias Krüger 2025-04-16 13:45:29 +02:00 committed by GitHub
commit a1de2a2d05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 126 additions and 4 deletions

View file

@ -3376,10 +3376,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
Ok(string) => {
let coro_prefix = if string.starts_with("async") {
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize`
// to `u32`.
Some(5)
let coro_prefix = if let Some(sub) = string.strip_prefix("async") {
let trimmed_sub = sub.trim_end();
if trimmed_sub.ends_with("gen") {
// `async` is 5 chars long.
Some((trimmed_sub.len() + 5) as _)
} else {
// `async` is 5 chars long.
Some(5)
}
} else if string.starts_with("gen") {
// `gen` is 3 chars long
Some(3)