]> git.lizzy.rs Git - rust.git/commitdiff
fix only_used_in_recursion not to lint when unused_variable
authorJaeyong Sung <jaeyong0201@gmail.com>
Sat, 12 Feb 2022 18:53:23 +0000 (03:53 +0900)
committerJaeyong Sung <jaeyong0201@gmail.com>
Sat, 12 Feb 2022 18:53:23 +0000 (03:53 +0900)
clippy_lints/src/only_used_in_recursion.rs

index ace00333bd1b5573dd199ed653f164dbd2f72211..81c40a6a3793adc28a7ac15cf1d87a985e780773 100644 (file)
@@ -126,8 +126,20 @@ fn check_fn(
                 }
             }
 
+            let mut pre_order = FxHashMap::default();
+
+            visitor.graph.iter().for_each(|(_, next)| {
+                next.iter().for_each(|i| {
+                    *pre_order.entry(*i).or_insert(0) += 1;
+                });
+            });
+
             for (id, span, ident) in param_span {
-                if !visitor.has_side_effect.contains(&id) {
+                // if the variable is not used in recursion, it would be marked as unused
+                if !visitor.has_side_effect.contains(&id)
+                    && *pre_order.get(&id).unwrap_or(&0) > 0
+                    && visitor.graph.contains_key(&id)
+                {
                     span_lint_and_sugg(
                         cx,
                         ONLY_USED_IN_RECURSION,