1
Fork 0

Fix wrong suggestion for async gen block and add regression ui test for #139839

This commit is contained in:
Guillaume Gomez 2025-04-15 16:59:16 +02:00
parent 40dacd50b7
commit 2020adba86
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)