pub fn fix_loop_break<'db>(
db: &'db dyn Database,
node: SyntaxNode<'db>,
) -> Option<InternalFix<'db>>Expand description
Converts a loop with a conditionally-breaking if statement into a while loop.
This function transforms loops that have a conditional if statement
followed by a break into a while loop, which can simplify the logic
and improve readability.
§Arguments
db- Reference to theSyntaxGroupfor syntax tree access.node- TheSyntaxNoderepresenting the loop expression.
§Returns
A String containing the transformed loop as a while loop, preserving
the original formatting and indentation.
§Example
let mut x = 0;
loop {
if x > 5 {
break;
}
x += 1;
}Would be converted to:
let mut x = 0;
while x <= 5 {
x += 1;
}