about summary refs log tree commit diff
diff options
context:
space:
mode:
authork-nasa <htilcs1115@gmail.com>2021-10-13 22:06:53 +0900
committerk-nasa <htilcs1115@gmail.com>2021-10-13 22:06:53 +0900
commitbc29b75b927cf42ee91f0cb17c6697bb1aff2166 (patch)
tree738eb85fd57cafc769712db0f119f51ab3397e2b
parentb3930599a791682e5ae8268f0c779d74e1e3dfda (diff)
downloadrust-bc29b75b927cf42ee91f0cb17c6697bb1aff2166.tar.gz
rust-bc29b75b927cf42ee91f0cb17c6697bb1aff2166.zip
update calc_depth
-rw-r--r--crates/ide_assists/src/utils.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs
index 64adddb1de6..22221afe74f 100644
--- a/crates/ide_assists/src/utils.rs
+++ b/crates/ide_assists/src/utils.rs
@@ -294,7 +294,7 @@ pub(crate) fn does_nested_pattern(pat: &ast::Pat) -> bool {
     false
 }
 
-fn calc_depth(pat: &ast::Pat, mut depth: usize) -> usize {
+fn calc_depth(pat: &ast::Pat, depth: usize) -> usize {
     match pat {
         ast::Pat::IdentPat(_)
         | ast::Pat::BoxPat(_)
@@ -312,12 +312,16 @@ fn calc_depth(pat: &ast::Pat, mut depth: usize) -> usize {
         | ast::Pat::TuplePat(_)
         | ast::Pat::ConstBlockPat(_) => 1,
 
-        // TODO implement
+        // TODO: Other patterns may also be nested. Currently it simply supports only `TupleStructPat`
         ast::Pat::TupleStructPat(pat) => {
+            let mut max_depth = depth;
             for p in pat.fields() {
-                depth += calc_depth(&p, depth + 1);
+                let d = calc_depth(&p, depth + 1);
+                if d > max_depth {
+                    max_depth = d
+                }
             }
-            depth
+            max_depth
         }
     }
 }