Fix clippy::println_empty_string, clippy::while_let_on_iterator, clippy::while_let_on_iterator lint style violations (#36613)

Related: #36577

Release Notes:

- N/A
This commit is contained in:
Umesh Yadav 2025-08-20 23:44:30 +05:30 committed by GitHub
parent 41e28a7185
commit ec8106d1db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 35 additions and 32 deletions

View file

@ -904,6 +904,7 @@ ok_expect = "warn"
owned_cow = "warn"
print_literal = "warn"
print_with_newline = "warn"
println_empty_string = "warn"
ptr_eq = "warn"
question_mark = "warn"
redundant_closure = "warn"
@ -924,7 +925,9 @@ unneeded_struct_pattern = "warn"
unsafe_removed_from_name = "warn"
unused_unit = "warn"
unusual_byte_groupings = "warn"
while_let_on_iterator = "warn"
write_literal = "warn"
write_with_newline = "warn"
writeln_empty_string = "warn"
wrong_self_convention = "warn"
zero_ptr = "warn"

View file

@ -362,7 +362,7 @@ impl Display for DirectoryContext {
let mut is_first = true;
for descendant in &self.descendants {
if !is_first {
write!(f, "\n")?;
writeln!(f)?;
} else {
is_first = false;
}
@ -650,7 +650,7 @@ impl TextThreadContextHandle {
impl Display for TextThreadContext {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
// TODO: escape title?
write!(f, "<text_thread title=\"{}\">\n", self.title)?;
writeln!(f, "<text_thread title=\"{}\">", self.title)?;
write!(f, "{}", self.text.trim())?;
write!(f, "\n</text_thread>")
}
@ -716,7 +716,7 @@ impl RulesContextHandle {
impl Display for RulesContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(title) = &self.title {
write!(f, "Rules title: {}\n", title)?;
writeln!(f, "Rules title: {}", title)?;
}
let code_block = MarkdownCodeBlock {
tag: "",

View file

@ -163,7 +163,7 @@ impl UserMessage {
if !content.is_empty() {
let _ = write!(&mut markdown, "{}\n\n{}\n", uri.as_link(), content);
} else {
let _ = write!(&mut markdown, "{}\n", uri.as_link());
let _ = writeln!(&mut markdown, "{}", uri.as_link());
}
}
}

View file

@ -2024,8 +2024,8 @@ mod tests {
fn gen_working_copy(rng: &mut StdRng, head: &str) -> String {
let mut old_lines = {
let mut old_lines = Vec::new();
let mut old_lines_iter = head.lines();
while let Some(line) = old_lines_iter.next() {
let old_lines_iter = head.lines();
for line in old_lines_iter {
assert!(!line.ends_with("\n"));
old_lines.push(line.to_owned());
}

View file

@ -3183,9 +3183,9 @@ mod tests {
// so we special case row 0 to assume a leading '\n'.
//
// Linehood is the birthright of strings.
let mut input_text_lines = input_text.split('\n').enumerate().peekable();
let input_text_lines = input_text.split('\n').enumerate().peekable();
let mut block_row = 0;
while let Some((wrap_row, input_line)) = input_text_lines.next() {
for (wrap_row, input_line) in input_text_lines {
let wrap_row = wrap_row as u32;
let multibuffer_row = wraps_snapshot
.to_point(WrapPoint::new(wrap_row, 0), Bias::Left)

View file

@ -11021,7 +11021,7 @@ impl Editor {
let mut col = 0;
let mut changed = false;
while let Some(ch) = chars.next() {
for ch in chars.by_ref() {
match ch {
' ' => {
reindented_line.push(' ');
@ -11077,7 +11077,7 @@ impl Editor {
let mut first_non_indent_char = None;
let mut changed = false;
while let Some(ch) = chars.next() {
for ch in chars.by_ref() {
match ch {
' ' => {
// Keep track of spaces. Append \t when we reach tab_size

View file

@ -164,8 +164,8 @@ pub fn indent_guides_in_range(
let end_anchor = snapshot.buffer_snapshot.anchor_after(end_offset);
let mut fold_ranges = Vec::<Range<Point>>::new();
let mut folds = snapshot.folds_in_range(start_offset..end_offset).peekable();
while let Some(fold) = folds.next() {
let folds = snapshot.folds_in_range(start_offset..end_offset).peekable();
for fold in folds {
let start = fold.range.start.to_point(&snapshot.buffer_snapshot);
let end = fold.range.end.to_point(&snapshot.buffer_snapshot);
if let Some(last_range) = fold_ranges.last_mut()

View file

@ -103,9 +103,9 @@ impl FollowableItem for Editor {
multibuffer = MultiBuffer::new(project.read(cx).capability());
let mut sorted_excerpts = state.excerpts.clone();
sorted_excerpts.sort_by_key(|e| e.id);
let mut sorted_excerpts = sorted_excerpts.into_iter().peekable();
let sorted_excerpts = sorted_excerpts.into_iter().peekable();
while let Some(excerpt) = sorted_excerpts.next() {
for excerpt in sorted_excerpts {
let Ok(buffer_id) = BufferId::new(excerpt.buffer_id) else {
continue;
};

View file

@ -706,7 +706,7 @@ fn print_report(
println!("Average thread score: {average_thread_score}%");
}
println!("");
println!();
print_h2("CUMULATIVE TOOL METRICS");
println!("{}", cumulative_tool_metrics);

View file

@ -913,9 +913,9 @@ impl RequestMarkdown {
for tool in &request.tools {
write!(&mut tools, "# {}\n\n", tool.name).unwrap();
write!(&mut tools, "{}\n\n", tool.description).unwrap();
write!(
writeln!(
&mut tools,
"{}\n",
"{}",
MarkdownCodeBlock {
tag: "json",
text: &format!("{:#}", tool.input_schema)

View file

@ -916,7 +916,7 @@ impl GitRepository for RealGitRepository {
.context("no stdin for git cat-file subprocess")?;
let mut stdin = BufWriter::new(stdin);
for rev in &revs {
write!(&mut stdin, "{rev}\n")?;
writeln!(&mut stdin, "{rev}")?;
}
stdin.flush()?;
drop(stdin);

View file

@ -186,7 +186,7 @@ fn tokenize(text: &str, language_scope: Option<LanguageScope>) -> impl Iterator<
let mut prev = None;
let mut start_ix = 0;
iter::from_fn(move || {
while let Some((ix, c)) = chars.next() {
for (ix, c) in chars.by_ref() {
let mut token = None;
let kind = classifier.kind(c);
if let Some((prev_char, prev_kind)) = prev

View file

@ -2250,11 +2250,11 @@ impl ReferenceMultibuffer {
let base_buffer = diff.base_text();
let mut offset = buffer_range.start;
let mut hunks = diff
let hunks = diff
.hunks_intersecting_range(excerpt.range.clone(), buffer, cx)
.peekable();
while let Some(hunk) = hunks.next() {
for hunk in hunks {
// Ignore hunks that are outside the excerpt range.
let mut hunk_range = hunk.buffer_range.to_offset(buffer);

View file

@ -42,8 +42,8 @@ impl<'a> GitTraversal<'a> {
// other_repo/
// .git/
// our_query.txt
let mut query = path.ancestors();
while let Some(query) = query.next() {
let query = path.ancestors();
for query in query {
let (_, snapshot) = self
.repo_root_to_snapshot
.range(Path::new("")..=query)

View file

@ -13149,10 +13149,10 @@ fn ensure_uniform_list_compatible_label(label: &mut CodeLabel) {
let mut offset_map = vec![0; label.text.len() + 1];
let mut last_char_was_space = false;
let mut new_idx = 0;
let mut chars = label.text.char_indices().fuse();
let chars = label.text.char_indices().fuse();
let mut newlines_removed = false;
while let Some((idx, c)) = chars.next() {
for (idx, c) in chars {
offset_map[idx] = new_idx;
match c {

View file

@ -209,7 +209,7 @@ fn replace_value_in_json_text(
if ch == ',' {
removal_end = existing_value_range.end + offset + 1;
// Also consume whitespace after the comma
while let Some((_, next_ch)) = chars.next() {
for (_, next_ch) in chars.by_ref() {
if next_ch.is_whitespace() {
removal_end += next_ch.len_utf8();
} else {

View file

@ -307,7 +307,7 @@ impl TabSwitcherDelegate {
(Reverse(history.get(&item.item.item_id())), item.item_index)
)
}
eprintln!("");
eprintln!();
all_items
.sort_by_key(|tab| (Reverse(history.get(&tab.item.item_id())), tab.item_index));
all_items

View file

@ -1397,8 +1397,8 @@ fn possible_open_target(
let found_entry = worktree
.update(cx, |worktree, _| {
let worktree_root = worktree.abs_path();
let mut traversal = worktree.traverse_from_path(true, true, false, "".as_ref());
while let Some(entry) = traversal.next() {
let traversal = worktree.traverse_from_path(true, true, false, "".as_ref());
for entry in traversal {
if let Some(path_in_worktree) = worktree_paths_to_check
.iter()
.find(|path_to_check| entry.path.ends_with(&path_to_check.path))

View file

@ -1492,7 +1492,7 @@ impl OnMatchingLines {
let mut search = String::new();
let mut escaped = false;
while let Some(c) = chars.next() {
for c in chars.by_ref() {
if escaped {
escaped = false;
// unescape escaped parens

View file

@ -274,9 +274,9 @@ fn find_boolean(snapshot: &MultiBufferSnapshot, start: Point) -> Option<(Range<P
let mut end = None;
let mut word = String::new();
let mut chars = snapshot.chars_at(offset);
let chars = snapshot.chars_at(offset);
while let Some(ch) = chars.next() {
for ch in chars {
if ch.is_ascii_alphabetic() {
if begin.is_none() {
begin = Some(offset);