This commit is contained in:
Lukas Wirth 2021-06-07 20:45:17 +02:00
parent b29e8ed994
commit 2987e05f15
5 changed files with 33 additions and 36 deletions

View file

@ -272,9 +272,8 @@ fn test_for_is_prev2() {
check_pattern_is_applicable(r"for i i$0", for_is_prev2);
}
pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
element
.ancestors()
pub(crate) fn is_in_loop_body(node: &SyntaxNode) -> bool {
node.ancestors()
.take_while(|it| it.kind() != FN && it.kind() != CLOSURE_EXPR)
.find_map(|it| {
let loop_body = match_ast! {
@ -285,7 +284,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
_ => None,
}
};
loop_body.filter(|it| it.syntax().text_range().contains_range(element.text_range()))
loop_body.filter(|it| it.syntax().text_range().contains_range(node.text_range()))
})
.is_some()
}