From daaeacb39bfe82990757b656e63800c2e27f89f5 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 31 May 2024 16:31:13 -0400 Subject: [PATCH] Use find in indent detection --- crates/ruff_python_codegen/src/stylist.rs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/crates/ruff_python_codegen/src/stylist.rs b/crates/ruff_python_codegen/src/stylist.rs index 37115690a140fa..7387de8e3035fb 100644 --- a/crates/ruff_python_codegen/src/stylist.rs +++ b/crates/ruff_python_codegen/src/stylist.rs @@ -106,13 +106,7 @@ fn detect_indention(tokens: &[LexResult], locator: &Locator) -> Indentation { } TokenKind::NonLogicalNewline => { let line = locator.line(range.end()); - let indent_index = line.char_indices().find_map(|(i, c)| { - if c.is_whitespace() { - None - } else { - Some(i) - } - }); + let indent_index = line.find(|c: char| !c.is_whitespace()); if let Some(indent_index) = indent_index { if indent_index > 0 { let whitespace = &line[..indent_index]; @@ -229,20 +223,6 @@ x = ( &Indentation(" ".to_string()) ); - let contents = r" -x = ( - 1, - 2, - 3, -) -"; - let locator = Locator::new(contents); - let tokens: Vec<_> = lex(contents, Mode::Module).collect(); - assert_eq!( - Stylist::from_tokens(&tokens, &locator).indentation(), - &Indentation(" ".to_string()) - ); - // formfeed indent, see `detect_indention` comment. let contents = r" class FormFeedIndent: