Fix clippy::len_zero lint style violations (#36589)

Related: #36577

Release Notes:

- N/A

---------

Signed-off-by: Umesh Yadav <git@umesh.dev>
This commit is contained in:
Umesh Yadav 2025-08-20 20:05:59 +05:30 committed by GitHub
parent 92352f97ad
commit 1e6cefaa56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 46 additions and 46 deletions

View file

@ -864,6 +864,7 @@ iter_nth = "warn"
iter_nth_zero = "warn"
iter_skip_next = "warn"
just_underscores_and_digits = "warn"
len_zero = "warn"
let_and_return = "warn"
main_recursion = "warn"
manual_bits = "warn"

View file

@ -116,7 +116,7 @@ impl AgentTool for FindPathTool {
..cmp::min(input.offset + RESULTS_PER_PAGE, matches.len())];
event_stream.update_fields(acp::ToolCallUpdateFields {
title: Some(if paginated_matches.len() == 0 {
title: Some(if paginated_matches.is_empty() {
"No matches".into()
} else if paginated_matches.len() == 1 {
"1 match".into()

View file

@ -1117,7 +1117,7 @@ pub(crate) mod tests {
thread.read_with(cx, |thread, _| {
entries_len = thread.plan().entries.len();
assert!(thread.plan().entries.len() > 0, "Empty plan");
assert!(!thread.plan().entries.is_empty(), "Empty plan");
});
thread

View file

@ -1682,7 +1682,7 @@ impl Render for MessageEditor {
let has_history = self
.history_store
.as_ref()
.and_then(|hs| hs.update(cx, |hs, cx| hs.entries(cx).len() > 0).ok())
.and_then(|hs| hs.update(cx, |hs, cx| !hs.entries(cx).is_empty()).ok())
.unwrap_or(false)
|| self
.thread
@ -1695,7 +1695,7 @@ impl Render for MessageEditor {
!has_history && is_signed_out && has_configured_providers,
|this| this.child(cx.new(ApiKeysWithProviders::new)),
)
.when(changed_buffers.len() > 0, |parent| {
.when(!changed_buffers.is_empty(), |parent| {
parent.child(self.render_edits_bar(&changed_buffers, window, cx))
})
.child(self.render_editor(window, cx))

View file

@ -74,7 +74,7 @@ impl Render for AgentPanelOnboarding {
}),
)
.map(|this| {
if enrolled_in_trial || is_pro_user || self.configured_providers.len() >= 1 {
if enrolled_in_trial || is_pro_user || !self.configured_providers.is_empty() {
this
} else {
this.child(ApiKeysWithoutProviders::new())

View file

@ -234,7 +234,7 @@ impl ToolCard for FindPathToolCard {
workspace: WeakEntity<Workspace>,
cx: &mut Context<Self>,
) -> impl IntoElement {
let matches_label: SharedString = if self.paths.len() == 0 {
let matches_label: SharedString = if self.paths.is_empty() {
"No matches".into()
} else if self.paths.len() == 1 {
"1 match".into()

View file

@ -2129,7 +2129,7 @@ mod tests {
diff.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &working_copy, cx)
.collect::<Vec<_>>()
});
if hunks.len() == 0 {
if hunks.is_empty() {
return;
}

View file

@ -2908,7 +2908,7 @@ async fn test_lsp_pull_diagnostics(
{
assert!(
diagnostics_pulls_result_ids.lock().await.len() > 0,
!diagnostics_pulls_result_ids.lock().await.is_empty(),
"Initial diagnostics pulls should report None at least"
);
assert_eq!(

View file

@ -1113,9 +1113,8 @@ impl RunningState {
};
let session = self.session.read(cx);
let cwd = Some(&request.cwd)
.filter(|cwd| cwd.len() > 0)
.map(PathBuf::from)
let cwd = (!request.cwd.is_empty())
.then(|| PathBuf::from(&request.cwd))
.or_else(|| session.binary().unwrap().cwd.clone());
let mut envs: HashMap<String, String> =
@ -1150,7 +1149,7 @@ impl RunningState {
} else {
None
}
} else if args.len() > 0 {
} else if !args.is_empty() {
Some(args.remove(0))
} else {
None

View file

@ -244,7 +244,7 @@ impl BreakpointList {
return;
}
let ix = match self.selected_ix {
_ if self.breakpoints.len() == 0 => None,
_ if self.breakpoints.is_empty() => None,
None => Some(0),
Some(ix) => {
if ix == self.breakpoints.len() - 1 {
@ -268,7 +268,7 @@ impl BreakpointList {
return;
}
let ix = match self.selected_ix {
_ if self.breakpoints.len() == 0 => None,
_ if self.breakpoints.is_empty() => None,
None => Some(self.breakpoints.len() - 1),
Some(ix) => {
if ix == 0 {
@ -286,7 +286,7 @@ impl BreakpointList {
cx.propagate();
return;
}
let ix = if self.breakpoints.len() > 0 {
let ix = if !self.breakpoints.is_empty() {
Some(0)
} else {
None
@ -299,7 +299,7 @@ impl BreakpointList {
cx.propagate();
return;
}
let ix = if self.breakpoints.len() > 0 {
let ix = if !self.breakpoints.is_empty() {
Some(self.breakpoints.len() - 1)
} else {
None

View file

@ -223,7 +223,7 @@ impl ModuleList {
fn select_next(&mut self, _: &menu::SelectNext, _window: &mut Window, cx: &mut Context<Self>) {
let ix = match self.selected_ix {
_ if self.entries.len() == 0 => None,
_ if self.entries.is_empty() => None,
None => Some(0),
Some(ix) => {
if ix == self.entries.len() - 1 {
@ -243,7 +243,7 @@ impl ModuleList {
cx: &mut Context<Self>,
) {
let ix = match self.selected_ix {
_ if self.entries.len() == 0 => None,
_ if self.entries.is_empty() => None,
None => Some(self.entries.len() - 1),
Some(ix) => {
if ix == 0 {
@ -262,7 +262,7 @@ impl ModuleList {
_window: &mut Window,
cx: &mut Context<Self>,
) {
let ix = if self.entries.len() > 0 {
let ix = if !self.entries.is_empty() {
Some(0)
} else {
None
@ -271,7 +271,7 @@ impl ModuleList {
}
fn select_last(&mut self, _: &menu::SelectLast, _window: &mut Window, cx: &mut Context<Self>) {
let ix = if self.entries.len() > 0 {
let ix = if !self.entries.is_empty() {
Some(self.entries.len() - 1)
} else {
None

View file

@ -621,7 +621,7 @@ impl StackFrameList {
fn select_next(&mut self, _: &menu::SelectNext, _window: &mut Window, cx: &mut Context<Self>) {
let ix = match self.selected_ix {
_ if self.entries.len() == 0 => None,
_ if self.entries.is_empty() => None,
None => Some(0),
Some(ix) => {
if ix == self.entries.len() - 1 {
@ -641,7 +641,7 @@ impl StackFrameList {
cx: &mut Context<Self>,
) {
let ix = match self.selected_ix {
_ if self.entries.len() == 0 => None,
_ if self.entries.is_empty() => None,
None => Some(self.entries.len() - 1),
Some(ix) => {
if ix == 0 {
@ -660,7 +660,7 @@ impl StackFrameList {
_window: &mut Window,
cx: &mut Context<Self>,
) {
let ix = if self.entries.len() > 0 {
let ix = if !self.entries.is_empty() {
Some(0)
} else {
None
@ -669,7 +669,7 @@ impl StackFrameList {
}
fn select_last(&mut self, _: &menu::SelectLast, _window: &mut Window, cx: &mut Context<Self>) {
let ix = if self.entries.len() > 0 {
let ix = if !self.entries.is_empty() {
Some(self.entries.len() - 1)
} else {
None

View file

@ -291,7 +291,7 @@ impl VariableList {
}
self.session.update(cx, |session, cx| {
session.variables(scope.variables_reference, cx).len() > 0
!session.variables(scope.variables_reference, cx).is_empty()
})
})
.map(|scope| {
@ -997,7 +997,7 @@ impl VariableList {
DapEntry::Watcher { .. } => continue,
DapEntry::Variable(dap) => scopes[idx].1.push(dap.clone()),
DapEntry::Scope(scope) => {
if scopes.len() > 0 {
if !scopes.is_empty() {
idx += 1;
}

View file

@ -862,7 +862,7 @@ async fn test_random_diagnostics_with_inlays(cx: &mut TestAppContext, mut rng: S
21..=50 => mutated_diagnostics.update_in(cx, |diagnostics, window, cx| {
diagnostics.editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(window, cx);
if snapshot.buffer_snapshot.len() > 0 {
if !snapshot.buffer_snapshot.is_empty() {
let position = rng.gen_range(0..snapshot.buffer_snapshot.len());
let position = snapshot.buffer_snapshot.clip_offset(position, Bias::Left);
log::info!(

View file

@ -21030,7 +21030,7 @@ fn assert_breakpoint(
path: &Arc<Path>,
expected: Vec<(u32, Breakpoint)>,
) {
if expected.len() == 0usize {
if expected.is_empty() {
assert!(!breakpoints.contains_key(path), "{}", path.display());
} else {
let mut breakpoint = breakpoints

View file

@ -181,7 +181,7 @@ pub(crate) fn generate_auto_close_edits(
*/
{
let tag_node_name_equals = |node: &Node, name: &str| {
let is_empty = name.len() == 0;
let is_empty = name.is_empty();
if let Some(node_name) = node.named_child(TS_NODE_TAG_NAME_CHILD_INDEX) {
let range = node_name.byte_range();
return buffer.text_for_range(range).equals_str(name);
@ -207,7 +207,7 @@ pub(crate) fn generate_auto_close_edits(
cur = descendant;
}
assert!(ancestors.len() > 0);
assert!(!ancestors.is_empty());
let mut tree_root_node = open_tag;

View file

@ -420,7 +420,7 @@ impl EditorTestContext {
if expected_text == "[FOLDED]\n" {
assert!(is_folded, "excerpt {} should be folded", ix);
let is_selected = selections.iter().any(|s| s.head().excerpt_id == excerpt_id);
if expected_selections.len() > 0 {
if !expected_selections.is_empty() {
assert!(
is_selected,
"excerpt {ix} should be selected. got {:?}",

View file

@ -2175,7 +2175,7 @@ impl GitPanel {
let worktree = if worktrees.len() == 1 {
Task::ready(Some(worktrees.first().unwrap().clone()))
} else if worktrees.len() == 0 {
} else if worktrees.is_empty() {
let result = window.prompt(
PromptLevel::Warning,
"Unable to initialize a git repository",
@ -2758,22 +2758,22 @@ impl GitPanel {
}
}
if conflict_entries.len() == 0 && staged_count == 1 && pending_staged_count == 0 {
if conflict_entries.is_empty() && staged_count == 1 && pending_staged_count == 0 {
match pending_status_for_single_staged {
Some(TargetStatus::Staged) | None => {
self.single_staged_entry = single_staged_entry;
}
_ => {}
}
} else if conflict_entries.len() == 0 && pending_staged_count == 1 {
} else if conflict_entries.is_empty() && pending_staged_count == 1 {
self.single_staged_entry = last_pending_staged;
}
if conflict_entries.len() == 0 && changed_entries.len() == 1 {
if conflict_entries.is_empty() && changed_entries.len() == 1 {
self.single_tracked_entry = changed_entries.first().cloned();
}
if conflict_entries.len() > 0 {
if !conflict_entries.is_empty() {
self.entries.push(GitListEntry::Header(GitHeaderEntry {
header: Section::Conflict,
}));
@ -2781,7 +2781,7 @@ impl GitPanel {
.extend(conflict_entries.into_iter().map(GitListEntry::Status));
}
if changed_entries.len() > 0 {
if !changed_entries.is_empty() {
if !sort_by_path {
self.entries.push(GitListEntry::Header(GitHeaderEntry {
header: Section::Tracked,
@ -2790,7 +2790,7 @@ impl GitPanel {
self.entries
.extend(changed_entries.into_iter().map(GitListEntry::Status));
}
if new_entries.len() > 0 {
if !new_entries.is_empty() {
self.entries.push(GitListEntry::Header(GitHeaderEntry {
header: Section::New,
}));
@ -4476,7 +4476,7 @@ fn current_language_model(cx: &Context<'_, GitPanel>) -> Option<Arc<dyn Language
impl Render for GitPanel {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let project = self.project.read(cx);
let has_entries = self.entries.len() > 0;
let has_entries = !self.entries.is_empty();
let room = self
.workspace
.upgrade()

View file

@ -577,7 +577,7 @@ pub fn into_google(
top_k: None,
}),
safety_settings: None,
tools: (request.tools.len() > 0).then(|| {
tools: (!request.tools.is_empty()).then(|| {
vec![google_ai::Tool {
function_declarations: request
.tools

View file

@ -684,7 +684,7 @@ impl DapStore {
let shutdown_id = parent_session.update(cx, |parent_session, _| {
parent_session.remove_child_session_id(session_id);
if parent_session.child_session_ids().len() == 0 {
if parent_session.child_session_ids().is_empty() {
Some(parent_session.session_id())
} else {
None
@ -701,7 +701,7 @@ impl DapStore {
cx.emit(DapStoreEvent::DebugClientShutdown(session_id));
cx.background_spawn(async move {
if shutdown_children.len() > 0 {
if !shutdown_children.is_empty() {
let _ = join_all(shutdown_children).await;
}

View file

@ -461,7 +461,7 @@ impl PickerDelegate for TasksModalDelegate {
tooltip_label_text.push_str(&resolved_task.resolved.command_label);
}
if template.tags.len() > 0 {
if !template.tags.is_empty() {
tooltip_label_text.push('\n');
tooltip_label_text.push_str(
template

View file

@ -89,7 +89,7 @@ impl Vim {
return;
};
if prefix.len() > 0 {
if !prefix.is_empty() {
self.handle_literal_input(prefix, "", window, cx);
} else {
self.pop_operator(window, cx);

View file

@ -235,7 +235,7 @@ impl SerializedWorkspaceLocation {
pub fn sorted_paths(&self) -> Arc<Vec<PathBuf>> {
match self {
SerializedWorkspaceLocation::Local(paths, order) => {
if order.order().len() == 0 {
if order.order().is_empty() {
paths.paths().clone()
} else {
Arc::new(

View file

@ -4377,7 +4377,7 @@ mod tests {
}
}
}
if errors.len() > 0 {
if !errors.is_empty() {
panic!(
"Failed to build actions using {{}} as input: {:?}. Errors:\n{}",
failing_names,