Skip to content

Commit bc29b75

Browse files
committed
update calc_depth
1 parent b393059 commit bc29b75

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/ide_assists/src/utils.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub(crate) fn does_nested_pattern(pat: &ast::Pat) -> bool {
294294
false
295295
}
296296

297-
fn calc_depth(pat: &ast::Pat, mut depth: usize) -> usize {
297+
fn calc_depth(pat: &ast::Pat, depth: usize) -> usize {
298298
match pat {
299299
ast::Pat::IdentPat(_)
300300
| ast::Pat::BoxPat(_)
@@ -312,12 +312,16 @@ fn calc_depth(pat: &ast::Pat, mut depth: usize) -> usize {
312312
| ast::Pat::TuplePat(_)
313313
| ast::Pat::ConstBlockPat(_) => 1,
314314

315-
// TODO implement
315+
// TODO: Other patterns may also be nested. Currently it simply supports only `TupleStructPat`
316316
ast::Pat::TupleStructPat(pat) => {
317+
let mut max_depth = depth;
317318
for p in pat.fields() {
318-
depth += calc_depth(&p, depth + 1);
319+
let d = calc_depth(&p, depth + 1);
320+
if d > max_depth {
321+
max_depth = d
322+
}
319323
}
320-
depth
324+
max_depth
321325
}
322326
}
323327
}

0 commit comments

Comments
 (0)