From b4251681c70f86a0ff0613afb3ed2a7ab876a47c Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 8 Jul 2025 16:45:39 -0400 Subject: [PATCH] Fix clippy errors --- crates/editor/benches/editor_render.rs | 2 +- crates/editor/src/display_map/tab_map.rs | 30 +++++++----------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/crates/editor/benches/editor_render.rs b/crates/editor/benches/editor_render.rs index 0e8c896033..367a355d85 100644 --- a/crates/editor/benches/editor_render.rs +++ b/crates/editor/benches/editor_render.rs @@ -62,7 +62,7 @@ pub fn benches() { criterion.bench_with_input( BenchmarkId::new("editor_render", "TestAppContext"), &cx, - |bencher, cx| editor_render(bencher, cx), + editor_render, ); } diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 77d3a12e83..4731e59859 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -1139,16 +1139,13 @@ mod tests { let mut all_tab_stops = Vec::new(); let mut byte_offset = 0; - let mut char_offset = 0; - for ch in buffer.read(cx).snapshot(cx).text().chars() { - // byte_offset += ch.len_utf8(); + for (offset, ch) in buffer.read(cx).snapshot(cx).text().char_indices() { byte_offset += ch.len_utf8() as u32; - char_offset += 1; if ch == '\t' { all_tab_stops.push(TabStop { byte_offset, - char_offset, + char_offset: offset as u32 + 1, }); } } @@ -1177,16 +1174,13 @@ mod tests { let mut expected_tab_stops = Vec::new(); let mut byte_offset = 0; - let mut char_offset = 0; - for ch in buffer.read(cx).snapshot(cx).text().chars() { - // byte_offset += ch.len_utf8(); + for (offset, ch) in buffer.read(cx).snapshot(cx).text().char_indices() { byte_offset += ch.len_utf8() as u32; - char_offset += 1; if ch == '\t' { expected_tab_stops.push(TabStop { byte_offset, - char_offset, + char_offset: offset as u32 + 1, }); } } @@ -1306,15 +1300,13 @@ mod tests { let mut expected_tab_stops = Vec::new(); let mut byte_offset = 0; - let mut char_offset = 0; - for ch in fold_snapshot.chars_at(FoldPoint::new(0, 0)) { + for (i, ch) in fold_snapshot.chars_at(FoldPoint::new(0, 0)).enumerate() { byte_offset += ch.len_utf8() as u32; - char_offset += 1; if ch == '\t' { expected_tab_stops.push(TabStop { byte_offset, - char_offset, + char_offset: i as u32 + 1, }); } } @@ -1346,17 +1338,14 @@ mod tests { // First, collect all expected tab positions let mut all_tab_stops = Vec::new(); let mut byte_offset = 0; - let mut char_offset = 0; - for ch in buffer_snapshot.text().chars() { + for (i, ch) in buffer_snapshot.text().chars().enumerate() { byte_offset += ch.len_utf8() as u32; - char_offset += 1; if ch == '\t' { all_tab_stops.push(TabStop { byte_offset, - char_offset, + char_offset: i as u32 + 1, }); } - // byte_offset += ch.len_utf8(); } // Test with various distances @@ -1451,8 +1440,7 @@ impl<'a> TabStopCursor<'a> { /// distance: length to move forward while searching for the next tab stop fn seek(&mut self, distance: u32) -> Option { - if distance <= 0 { - debug_assert!(distance == 0, "Can't seek backwards: {distance}"); + if distance == 0 { return None; }