Skip to content

Commit 61225ec

Browse files
authored
Enable clippy::never_loop (#9006)
Three changes: two of which are changing `while let` construct to `if let` as they unconditionally broke and one of which was removing a loop in the `start_default_prettier` as it unconditionally broke in the control flow for match installation task: the diff for this is larger than needed as removing the loop changed a lot of indentation for `rustfmt`.
1 parent df27e78 commit 61225ec

File tree

4 files changed

+49
-53
lines changed

4 files changed

+49
-53
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ derive_ord_xor_partial_ord = "allow"
412412
eq_op = "allow"
413413
let_underscore_future = "allow"
414414
map_entry = "allow"
415-
never_loop = "allow"
416415
non_canonical_clone_impl = "allow"
417416
non_canonical_partial_ord_impl = "allow"
418417
reversed_empty_ranges = "allow"

crates/assistant/src/assistant_panel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,7 @@ impl Conversation {
20942094
let buffer = self.buffer.read(cx);
20952095
let mut message_anchors = self.message_anchors.iter().enumerate().peekable();
20962096
iter::from_fn(move || {
2097-
while let Some((start_ix, message_anchor)) = message_anchors.next() {
2097+
if let Some((start_ix, message_anchor)) = message_anchors.next() {
20982098
let metadata = self.messages_metadata.get(&message_anchor.id)?;
20992099
let message_start = message_anchor.start.to_offset(buffer);
21002100
let mut message_end = None;

crates/multi_buffer/src/multi_buffer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ impl MultiBuffer {
13491349
cursor.next(&());
13501350

13511351
// Skip over any subsequent excerpts that are also removed.
1352-
while let Some(&next_excerpt_id) = excerpt_ids.peek() {
1352+
if let Some(&next_excerpt_id) = excerpt_ids.peek() {
13531353
let next_locator = snapshot.excerpt_locator_for_id(next_excerpt_id);
13541354
if let Some(next_excerpt) = cursor.item() {
13551355
if next_excerpt.locator == *next_locator {
@@ -1358,7 +1358,6 @@ impl MultiBuffer {
13581358
continue 'remove_excerpts;
13591359
}
13601360
}
1361-
break;
13621361
}
13631362

13641363
break;

crates/project/src/prettier_support.rs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -230,68 +230,66 @@ fn start_default_prettier(
230230
cx: &mut ModelContext<'_, Project>,
231231
) -> Task<anyhow::Result<PrettierTask>> {
232232
cx.spawn(|project, mut cx| async move {
233-
loop {
234-
let installation_task = project.update(&mut cx, |project, _| {
235-
match &project.default_prettier.prettier {
236-
PrettierInstallation::NotInstalled {
237-
installation_task, ..
238-
} => ControlFlow::Continue(installation_task.clone()),
239-
PrettierInstallation::Installed(default_prettier) => {
240-
ControlFlow::Break(default_prettier.clone())
241-
}
233+
let installation_task = project.update(&mut cx, |project, _| {
234+
match &project.default_prettier.prettier {
235+
PrettierInstallation::NotInstalled {
236+
installation_task, ..
237+
} => ControlFlow::Continue(installation_task.clone()),
238+
PrettierInstallation::Installed(default_prettier) => {
239+
ControlFlow::Break(default_prettier.clone())
242240
}
243-
})?;
244-
match installation_task {
245-
ControlFlow::Continue(None) => {
246-
anyhow::bail!("Default prettier is not installed and cannot be started")
241+
}
242+
})?;
243+
match installation_task {
244+
ControlFlow::Continue(None) => {
245+
anyhow::bail!("Default prettier is not installed and cannot be started")
246+
}
247+
ControlFlow::Continue(Some(installation_task)) => {
248+
log::info!("Waiting for default prettier to install");
249+
if let Err(e) = installation_task.await {
250+
project.update(&mut cx, |project, _| {
251+
if let PrettierInstallation::NotInstalled {
252+
installation_task,
253+
attempts,
254+
..
255+
} = &mut project.default_prettier.prettier
256+
{
257+
*installation_task = None;
258+
*attempts += 1;
259+
}
260+
})?;
261+
anyhow::bail!(
262+
"Cannot start default prettier due to its installation failure: {e:#}"
263+
);
247264
}
248-
ControlFlow::Continue(Some(installation_task)) => {
249-
log::info!("Waiting for default prettier to install");
250-
if let Err(e) = installation_task.await {
251-
project.update(&mut cx, |project, _| {
252-
if let PrettierInstallation::NotInstalled {
253-
installation_task,
254-
attempts,
255-
..
256-
} = &mut project.default_prettier.prettier
257-
{
258-
*installation_task = None;
259-
*attempts += 1;
260-
}
261-
})?;
262-
anyhow::bail!(
263-
"Cannot start default prettier due to its installation failure: {e:#}"
264-
);
265-
}
265+
let new_default_prettier = project.update(&mut cx, |project, cx| {
266+
let new_default_prettier =
267+
start_prettier(node, DEFAULT_PRETTIER_DIR.clone(), worktree_id, cx);
268+
project.default_prettier.prettier =
269+
PrettierInstallation::Installed(PrettierInstance {
270+
attempt: 0,
271+
prettier: Some(new_default_prettier.clone()),
272+
});
273+
new_default_prettier
274+
})?;
275+
return Ok(new_default_prettier);
276+
}
277+
ControlFlow::Break(instance) => match instance.prettier {
278+
Some(instance) => return Ok(instance),
279+
None => {
266280
let new_default_prettier = project.update(&mut cx, |project, cx| {
267281
let new_default_prettier =
268282
start_prettier(node, DEFAULT_PRETTIER_DIR.clone(), worktree_id, cx);
269283
project.default_prettier.prettier =
270284
PrettierInstallation::Installed(PrettierInstance {
271-
attempt: 0,
285+
attempt: instance.attempt + 1,
272286
prettier: Some(new_default_prettier.clone()),
273287
});
274288
new_default_prettier
275289
})?;
276290
return Ok(new_default_prettier);
277291
}
278-
ControlFlow::Break(instance) => match instance.prettier {
279-
Some(instance) => return Ok(instance),
280-
None => {
281-
let new_default_prettier = project.update(&mut cx, |project, cx| {
282-
let new_default_prettier =
283-
start_prettier(node, DEFAULT_PRETTIER_DIR.clone(), worktree_id, cx);
284-
project.default_prettier.prettier =
285-
PrettierInstallation::Installed(PrettierInstance {
286-
attempt: instance.attempt + 1,
287-
prettier: Some(new_default_prettier.clone()),
288-
});
289-
new_default_prettier
290-
})?;
291-
return Ok(new_default_prettier);
292-
}
293-
},
294-
}
292+
},
295293
}
296294
})
297295
}

0 commit comments

Comments
 (0)