Skip to content

Commit 3985bd5

Browse files
emilkclaude
andauthored
Enable more lints (#24066)
## Which issue does this PR close? - Part of #18467 - Follow-up to #24076 ## Rationale for this change There are a lot of lints we can enable to, which different abilities to: * Simplify the code * Write more efficient code * Catch bugs * etc ## What changes are included in this PR? One commit per new lint (maybe easiest to review commit by commit!). I hope to add even more lints in later PRsq ## Are these changes tested? Covered by existing tests plus the clippy CI job. ## Are there any user-facing changes? No. --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 591ae10 commit 3985bd5

18 files changed

Lines changed: 81 additions & 48 deletions

File tree

‎Cargo.toml‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,71 @@ uuid = "1.23"
210210
zstd = { version = "0.13", default-features = false }
211211

212212
# Keep this list sorted alphabetically.
213+
# See https://github.com/apache/datafusion/issues/18467 for the ongoing effort of
214+
# picking useful non-default lints.
213215
[workspace.lints.clippy]
214216
# https://github.com/apache/datafusion/issues/18881
215217
allow_attributes = "warn"
218+
as_ptr_cast_mut = "warn"
216219
assigning_clones = "warn"
220+
clear_with_drain = "warn"
221+
coerce_container_to_any = "warn"
222+
debug_assert_with_mut_call = "warn"
223+
decimal_bitwise_operands = "warn"
224+
default_union_representation = "warn"
225+
doc_include_without_cfg = "warn"
226+
empty_enum_variants_with_brackets = "warn"
227+
exit = "warn"
228+
flat_map_option = "warn"
229+
fn_to_numeric_cast_any = "warn"
230+
imprecise_flops = "warn"
231+
index_refutable_slice = "warn"
217232
inefficient_to_string = "warn"
233+
infinite_loop = "warn"
234+
invalid_upcast_comparisons = "warn"
235+
ip_constant = "warn"
236+
iter_filter_is_ok = "warn"
237+
iter_filter_is_some = "warn"
238+
iter_on_empty_collections = "warn"
218239
# Detects large stack-allocated futures that may cause stack overflow crashes (see threshold in clippy.toml)
219240
large_futures = "warn"
241+
large_include_file = "warn"
242+
macro_use_imports = "warn"
243+
manual_ilog2 = "warn"
244+
manual_instant_elapsed = "warn"
245+
manual_is_power_of_two = "warn"
246+
match_wild_err_arm = "warn"
247+
mem_forget = "warn"
248+
mismatching_type_param_order = "warn"
249+
mut_mut = "warn"
220250
# https://github.com/apache/datafusion/issues/18503
221251
needless_pass_by_value = "warn"
252+
negative_feature_names = "warn"
253+
non_zero_suggestions = "warn"
254+
nonstandard_macro_braces = "warn"
222255
or_fun_call = "warn"
256+
path_buf_push_overwrite = "warn"
257+
pathbuf_init_then_push = "warn"
258+
precedence_bits = "warn"
259+
pub_underscore_fields = "warn"
260+
rc_mutex = "warn"
261+
ref_option_ref = "warn"
262+
same_length_and_capacity = "warn"
263+
str_split_at_newline = "warn"
264+
string_add_assign = "warn"
265+
suspicious_xor_used_as_pow = "warn"
266+
trailing_empty_array = "warn"
267+
transmute_ptr_to_ptr = "warn"
268+
uninhabited_references = "warn"
223269
uninlined_format_args = "warn"
224270
unnecessary_lazy_evaluations = "warn"
271+
unnecessary_self_imports = "warn"
225272
unused_async = "warn"
273+
unused_rounding = "warn"
226274
used_underscore_binding = "warn"
275+
verbose_file_reads = "warn"
276+
wildcard_dependencies = "warn"
277+
zero_sized_map_values = "warn"
227278

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

‎benchmarks/src/clickbench.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ pub struct RunOpt {
111111

112112
/// Get the SQL file path
113113
pub fn get_query_path(query_dir: &Path, query: usize) -> PathBuf {
114-
let mut query_path = query_dir.to_path_buf();
115-
query_path.push(format!("q{query}.sql"));
116-
query_path
114+
query_dir.join(format!("q{query}.sql"))
117115
}
118116

119117
/// Get the SQL statement from the specified query file

‎datafusion-cli/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg"
2121
)]
2222
#![cfg_attr(docsrs, feature(doc_cfg))]
23-
#![doc = include_str!("../README.md")]
23+
#![cfg_attr(doc, doc = include_str!("../README.md"))]
2424
pub const DATAFUSION_CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
2525

2626
pub mod catalog;

‎datafusion/common/src/cse.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ mod test {
808808
) -> HashSet<u64> {
809809
id_array
810810
.iter_mut()
811-
.flat_map(|(_, id_option)| {
811+
.filter_map(|(_, id_option)| {
812812
id_option.as_mut().map(|node_id| {
813813
let hash = node_id.hash;
814814
node_id.hash = 0;

‎datafusion/common/src/utils/proxy.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ where
166166
if cfg!(debug_assertions) {
167167
// In debug mode, check that the element is not already present
168168
debug_assert!(
169-
self.find_entry(hash, |y| y == &x).is_err(),
169+
self.find(hash, |y| y == &x).is_none(),
170170
"attempted to insert duplicate element into HashTableAllocExt::insert_accounted"
171171
);
172172
}

‎datafusion/core/benches/parquet_query_sql.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use parquet::file::properties::{WriterProperties, WriterVersion};
3232
use rand::distr::Alphanumeric;
3333
use rand::distr::uniform::SampleUniform;
3434
use rand::prelude::*;
35-
use std::fs::File;
36-
use std::io::Read;
3735
use std::ops::Range;
3836
use std::path::Path;
3937
use std::sync::Arc;
@@ -211,9 +209,7 @@ fn criterion_benchmark(c: &mut Criterion) {
211209
.unwrap();
212210

213211
// We read the queries from a file so they can be changed without recompiling the benchmark
214-
let mut queries_file = File::open("benches/parquet_query_sql.sql").unwrap();
215-
let mut queries = String::new();
216-
queries_file.read_to_string(&mut queries).unwrap();
212+
let queries = std::fs::read_to_string("benches/parquet_query_sql.sql").unwrap();
217213

218214
for query in queries.split(';') {
219215
let query = query.trim();

‎datafusion/core/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@
761761
//! [`RecordBatch`]: arrow::array::RecordBatch
762762
//! [`RecordBatchReader`]: arrow::record_batch::RecordBatchReader
763763
//! [`Array`]: arrow::array::Array
764-
#![doc = include_str!("optimizer_rule_reference.md")]
764+
#![cfg_attr(doc, doc = include_str!("optimizer_rule_reference.md"))]
765765

766766
extern crate core;
767767
#[cfg(feature = "sql")]

‎datafusion/core/tests/physical_optimizer/pushdown_utils.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ pub fn format_execution_plan(plan: &Arc<dyn ExecutionPlan>) -> Vec<String> {
434434
}
435435

436436
fn format_lines(s: &str) -> Vec<String> {
437-
s.trim().split('\n').map(|s| s.to_string()).collect()
437+
s.trim().lines().map(|s| s.to_string()).collect()
438438
}
439439

440440
pub fn format_plan_for_test(plan: &Arc<dyn ExecutionPlan>) -> String {

‎datafusion/core/tests/physical_optimizer/test_utils.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub fn format_execution_plan(plan: &Arc<dyn ExecutionPlan>) -> Vec<String> {
838838
}
839839

840840
fn format_lines(s: &str) -> Vec<String> {
841-
s.trim().split('\n').map(|s| s.to_string()).collect()
841+
s.trim().lines().map(|s| s.to_string()).collect()
842842
}
843843

844844
/// Create a simple ProjectionExec with column indices (simplified version)

‎datafusion/datasource-arrow/src/source.rs‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl From<ArrowSource> for Arc<dyn FileSource> {
512512

513513
#[cfg(test)]
514514
mod tests {
515-
use std::{fs::File, io::Read};
515+
use std::fs::File;
516516

517517
use arrow::datatypes::{DataType, Field, Schema};
518518
use arrow_ipc::reader::{FileReader, StreamReader};
@@ -528,11 +528,8 @@ mod tests {
528528
for filename in ["example.arrow", "example_stream.arrow"] {
529529
let path = format!("tests/data/{filename}");
530530
let path_str = path.as_str();
531-
let mut file = File::open(path_str)?;
532-
let file_size = file.metadata()?.len();
533-
534-
let mut buffer = Vec::new();
535-
file.read_to_end(&mut buffer)?;
531+
let buffer = std::fs::read(path_str)?;
532+
let file_size = buffer.len() as u64;
536533
let bytes = Bytes::from(buffer);
537534

538535
let object_store = Arc::new(InMemory::new());
@@ -572,11 +569,8 @@ mod tests {
572569
let filename = "example.arrow";
573570
let path = format!("tests/data/{filename}");
574571
let path_str = path.as_str();
575-
let mut file = File::open(path_str)?;
576-
let file_size = file.metadata()?.len();
577-
578-
let mut buffer = Vec::new();
579-
file.read_to_end(&mut buffer)?;
572+
let buffer = std::fs::read(path_str)?;
573+
let file_size = buffer.len() as u64;
580574
let bytes = Bytes::from(buffer);
581575

582576
let object_store = Arc::new(InMemory::new());
@@ -613,11 +607,8 @@ mod tests {
613607
let filename = "example_stream.arrow";
614608
let path = format!("tests/data/{filename}");
615609
let path_str = path.as_str();
616-
let mut file = File::open(path_str)?;
617-
let file_size = file.metadata()?.len();
618-
619-
let mut buffer = Vec::new();
620-
file.read_to_end(&mut buffer)?;
610+
let buffer = std::fs::read(path_str)?;
611+
let file_size = buffer.len() as u64;
621612
let bytes = Bytes::from(buffer);
622613

623614
let object_store = Arc::new(InMemory::new());
@@ -678,11 +669,8 @@ mod tests {
678669
let filename = "example_stream.arrow";
679670
let path = format!("tests/data/{filename}");
680671
let path_str = path.as_str();
681-
let mut file = File::open(path_str)?;
682-
let file_size = file.metadata()?.len();
683-
684-
let mut buffer = Vec::new();
685-
file.read_to_end(&mut buffer)?;
672+
let buffer = std::fs::read(path_str)?;
673+
let file_size = buffer.len() as u64;
686674
let bytes = Bytes::from(buffer);
687675

688676
let object_store = Arc::new(InMemory::new());

0 commit comments

Comments
 (0)