Normalize return's 'after'

This commit is contained in:
Joshua Warner 2024-12-12 19:29:41 -08:00
parent 17849ca556
commit 2857833c35
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 73 additions and 1 deletions

View file

@ -1116,7 +1116,7 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
after: body_lifted.after,
}
}
Expr::If { .. } | Expr::When(_, _) | Expr::Return(_, _) => {
Expr::If { .. } | Expr::When(_, _) => {
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
Spaces {
before: &[],
@ -1131,6 +1131,34 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
}
}
}
Expr::Return(val, opt_after) => {
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
Spaces {
before: &[],
item: Expr::ParensAround(arena.alloc(*expr)),
after: &[],
}
} else if let Some(after) = opt_after {
let after_lifted = expr_lift_spaces_after(Parens::NotNeeded, arena, &after.value);
Spaces {
before: &[],
item: Expr::Return(
val,
Some(arena.alloc(Loc::at(after.region, after_lifted.item))),
),
after: after_lifted.after,
}
} else {
let val_lifted = expr_lift_spaces_after(Parens::NotNeeded, arena, &val.value);
Spaces {
before: &[],
item: Expr::Return(arena.alloc(Loc::at(val.region, val_lifted.item)), None),
after: val_lifted.after,
}
}
}
Expr::Backpassing(pats, call, continuation) => {
let pats = arena.alloc_slice_copy(pats);
let before = if let Some(first) = pats.first_mut() {