Skip to content

Commit 2db3aea

Browse files
authored
chore: Enforce clippy::needless_pass_by_value globally across the workspace (#18904)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #18503 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> We have already enforce the lint rule for all workspace crates, now we can enable it globally. In this PR: - adds the lint rule to the top-level `cargo.toml` - There are some utility modules (`datafusion-examples`, tests) have not been fixed before, and after we have enable the linter rule at workspace level, these violations showed up. This PR suppresses all of them, since those violations are acceptable. - Keep the per-crate configuration unchanged For example when we enforce it in `datafusion-sql`, in its `lib.rs`, we have ``` // #18503 #![deny(clippy::needless_pass_by_value)] #![cfg_attr(test, allow(clippy::needless_pass_by_value))] ``` This enforces the rule at the crate level but ignores all violations in tests. We cannot disable lint checks for tests from the global (top-level Cargo.toml) configuration, so we have to keep these per-crate settings until Cargo or Clippy adds support for this in the future. I'll leave a note in the tracking issue. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 6ea305e commit 2db3aea

File tree

36 files changed

+55
-3
lines changed

36 files changed

+55
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ or_fun_call = "warn"
192192
unnecessary_lazy_evaluations = "warn"
193193
uninlined_format_args = "warn"
194194
inefficient_to_string = "warn"
195+
needless_pass_by_value = "warn"
195196

196197
[workspace.lints.rust]
197198
unexpected_cfgs = { level = "warn", check-cfg = [

datafusion-examples/examples/custom_data_source/custom_datasource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ struct CustomExec {
196196
}
197197

198198
impl CustomExec {
199+
#[expect(clippy::needless_pass_by_value)]
199200
fn new(
200201
projections: Option<&Vec<usize>>,
201202
schema: SchemaRef,

datafusion-examples/examples/execution_monitoring/memory_pool_execution_plan.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl ExternalBatchBufferer {
142142
}
143143
}
144144

145+
#[expect(clippy::needless_pass_by_value)]
145146
fn add_batch(&mut self, batch_data: Vec<u8>) -> Result<()> {
146147
let additional_memory = batch_data.len();
147148

datafusion-examples/examples/flight/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl FlightService for FlightServiceImpl {
189189
}
190190
}
191191

192+
#[expect(clippy::needless_pass_by_value)]
192193
fn to_tonic_err(e: datafusion::error::DataFusionError) -> Status {
193194
Status::internal(format!("{e:?}"))
194195
}

datafusion-examples/examples/query_planning/pruning.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl PruningStatistics for MyCatalog {
190190
}
191191
}
192192

193+
#[expect(clippy::needless_pass_by_value)]
193194
fn create_pruning_predicate(expr: Expr, schema: &SchemaRef) -> PruningPredicate {
194195
let df_schema = DFSchema::try_from(Arc::clone(schema)).unwrap();
195196
let props = ExecutionProps::new();

datafusion/core/benches/aggregate_query_sql.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use std::hint::black_box;
3131
use std::sync::Arc;
3232
use tokio::runtime::Runtime;
3333

34+
#[expect(clippy::needless_pass_by_value)]
3435
fn query(ctx: Arc<Mutex<SessionContext>>, rt: &Runtime, sql: &str) {
3536
let df = rt.block_on(ctx.lock().sql(sql)).unwrap();
3637
black_box(rt.block_on(df.collect()).unwrap());

datafusion/core/benches/csv_load.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::time::Duration;
3434
use test_utils::AccessLogGenerator;
3535
use tokio::runtime::Runtime;
3636

37+
#[expect(clippy::needless_pass_by_value)]
3738
fn load_csv(
3839
ctx: Arc<Mutex<SessionContext>>,
3940
rt: &Runtime,

datafusion/core/benches/data_utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ fn create_record_batch(
139139

140140
/// Create record batches of `partitions_len` partitions and `batch_size` for each batch,
141141
/// with a total number of `array_len` records
142+
#[expect(clippy::needless_pass_by_value)]
142143
pub fn create_record_batches(
143144
schema: SchemaRef,
144145
array_len: usize,

datafusion/core/benches/dataframe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn create_context(field_count: u32) -> datafusion_common::Result<Arc<SessionCont
4545
Ok(Arc::new(ctx))
4646
}
4747

48+
#[expect(clippy::needless_pass_by_value)]
4849
fn run(column_count: u32, ctx: Arc<SessionContext>, rt: &Runtime) {
4950
black_box(rt.block_on(async {
5051
let mut data_frame = ctx.table("t").await.unwrap();

datafusion/core/benches/distinct_query_sql.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::hint::black_box;
3434
use std::{sync::Arc, time::Duration};
3535
use tokio::runtime::Runtime;
3636

37+
#[expect(clippy::needless_pass_by_value)]
3738
fn query(ctx: Arc<Mutex<SessionContext>>, rt: &Runtime, sql: &str) {
3839
let df = rt.block_on(ctx.lock().sql(sql)).unwrap();
3940
black_box(rt.block_on(df.collect()).unwrap());
@@ -124,6 +125,7 @@ async fn distinct_with_limit(
124125
Ok(())
125126
}
126127

128+
#[expect(clippy::needless_pass_by_value)]
127129
fn run(rt: &Runtime, plan: Arc<dyn ExecutionPlan>, ctx: Arc<TaskContext>) {
128130
black_box(rt.block_on(distinct_with_limit(plan.clone(), ctx.clone()))).unwrap();
129131
}

0 commit comments

Comments
 (0)