Skip to content

Commit 441a61c

Browse files
ZhiXiao-Linclaude
andcommitted
fix: resolve clippy warnings — needless_range_loop and mut_range_bound
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f0c1bba commit 441a61c

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

core/src/tools/builtin/grep.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ impl Tool for GrepTool {
149149
let start = match_idx.saturating_sub(context_lines);
150150
let end = (match_idx + context_lines + 1).min(lines.len());
151151

152-
for i in start..end {
153-
let prefix = if i == match_idx { ">" } else { " " };
154-
let line_str = format!("{}{}:{}: {}\n", prefix, rel_path, i + 1, lines[i]);
152+
for (i, line) in lines[start..end].iter().enumerate() {
153+
let abs_i = start + i;
154+
let prefix = if abs_i == match_idx { ">" } else { " " };
155+
let line_str = format!("{}{}:{}: {}\n", prefix, rel_path, abs_i + 1, line);
155156
total_size += line_str.len();
156157
output.push_str(&line_str);
157158
}

core/src/tools/builtin/patch.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,22 @@ fn apply_hunks(content: &str, hunks: &[Hunk]) -> Result<String, String> {
149149

150150
for removal in &hunk.removals {
151151
// Find the line to remove starting from search_idx
152-
let mut found = false;
153-
for idx in search_idx..file_lines.len() {
154-
if file_lines[idx].trim() == removal.trim() {
152+
let found_idx = file_lines[search_idx..]
153+
.iter()
154+
.position(|line| line.trim() == removal.trim())
155+
.map(|pos| search_idx + pos);
156+
match found_idx {
157+
Some(idx) => {
155158
lines_to_remove.push(idx);
156159
search_idx = idx + 1;
157-
found = true;
158-
break;
159160
}
160-
}
161-
if !found {
162-
return Err(format!(
163-
"Could not find line to remove: {:?} near line {}",
164-
removal,
165-
start_idx + 1
166-
));
161+
None => {
162+
return Err(format!(
163+
"Could not find line to remove: {:?} near line {}",
164+
removal,
165+
start_idx + 1
166+
));
167+
}
167168
}
168169
}
169170

0 commit comments

Comments
 (0)