Skip to content

Commit 8faa938

Browse files
committed
fix only_used_in_recursion not to lint when unused_variable
1 parent 3a090c9 commit 8faa938

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clippy_lints/src/only_used_in_recursion.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,20 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
126126
}
127127
}
128128

129+
let mut pre_order = FxHashMap::default();
130+
131+
visitor.graph.iter().for_each(|(_, next)| {
132+
next.iter().for_each(|i| {
133+
*pre_order.entry(*i).or_insert(0) += 1;
134+
});
135+
});
136+
129137
for (id, span, ident) in param_span {
130-
if !visitor.has_side_effect.contains(&id) {
138+
// if the variable is not used in recursion, it would be marked as unused
139+
if !visitor.has_side_effect.contains(&id)
140+
&& *pre_order.get(&id).unwrap_or(&0) > 0
141+
&& visitor.graph.contains_key(&id)
142+
{
131143
span_lint_and_sugg(
132144
cx,
133145
ONLY_USED_IN_RECURSION,

0 commit comments

Comments
 (0)