From 83f6a1ea49b709cc0b4500a803fca1c3cc7655f2 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sun, 3 Mar 2024 10:53:23 -0500 Subject: [PATCH] Enable `clippy::vec_init_then_push` (#8771) This PR enables the [`clippy::vec_init_then_push`](https://rust-lang.github.io/rust-clippy/master/index.html#/vec_init_then_push) rule and fixes the outstanding violations. Release Notes: - N/A --- crates/collab/src/db/tests/buffer_tests.rs | 11 ++++++----- crates/workspace/src/workspace.rs | 3 +-- tooling/xtask/src/main.rs | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/collab/src/db/tests/buffer_tests.rs b/crates/collab/src/db/tests/buffer_tests.rs index ebc11a7019..8f9492d648 100644 --- a/crates/collab/src/db/tests/buffer_tests.rs +++ b/crates/collab/src/db/tests/buffer_tests.rs @@ -68,11 +68,12 @@ async fn test_channel_buffers(db: &Arc) { .unwrap(); let mut buffer_a = Buffer::new(0, text::BufferId::new(1).unwrap(), "".to_string()); - let mut operations = Vec::new(); - operations.push(buffer_a.edit([(0..0, "hello world")])); - operations.push(buffer_a.edit([(5..5, ", cruel")])); - operations.push(buffer_a.edit([(0..5, "goodbye")])); - operations.push(buffer_a.undo().unwrap().1); + let operations = vec![ + buffer_a.edit([(0..0, "hello world")]), + buffer_a.edit([(5..5, ", cruel")]), + buffer_a.edit([(0..5, "goodbye")]), + buffer_a.undo().unwrap().1, + ]; assert_eq!(buffer_a.text(), "hello, cruel world"); let operations = operations diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index f1b93b19b5..5acfd988b9 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -679,8 +679,7 @@ impl Workspace { let mut active_call = None; if let Some(call) = ActiveCall::try_global(cx) { let call = call.clone(); - let mut subscriptions = Vec::new(); - subscriptions.push(cx.subscribe(&call, Self::on_active_call_event)); + let subscriptions = vec![cx.subscribe(&call, Self::on_active_call_event)]; active_call = Some((call, subscriptions)); } diff --git a/tooling/xtask/src/main.rs b/tooling/xtask/src/main.rs index a0ad0fcd83..72c1588fe7 100644 --- a/tooling/xtask/src/main.rs +++ b/tooling/xtask/src/main.rs @@ -108,7 +108,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> { "clippy::suspicious_to_owned", "clippy::type_complexity", "clippy::unnecessary_to_owned", - "clippy::vec_init_then_push", ]; // When fixing violations automatically for a single package we don't care