Skip to content

Commit a28ba02

Browse files
authored
Enable more clippy lints (apache#24837)
## Which issue does this PR close? - Part of apache#18467. ## Rationale for this change Continuing the work in: - apache#24466 - apache#24566 Turn on more `clippy::pedantic` lints from the opt-out list in `Cargo.toml`, picking ones that buy performance, correctness, or readability. ## What changes are included in this PR? One commit per lint, each removing its `"allow"` line from `Cargo.toml` and fixing every site. Review one commit at a time! Let me know if you disagree with any and I'll revert it. | Lint | Sites | Fix | | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----: | ------------------------------------------------------------------------------- | | [`needless_bitwise_bool`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_bitwise_bool) | 1 | `#[expect]`: the non-short-circuiting `\|` is the point of the branchless IN-list kernel | | [`unicode_not_nfc`](https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc) | 2 | two copies of the same decomposed literal; one now covers the composed form, both written with `\u{...}` | | [`format_collect`](https://rust-lang.github.io/rust-clippy/master/index.html#format_collect) | 4 | `fold` + `write!` into one `String` instead of a `format!` alloc per item | | [`large_digit_groups`](https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups) | 3 | `#[expect]`: the single `_` marks the decimal point of fixed-point test literals | | [`borrow_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr) | 6 | explicit `&raw const` / `&raw mut` | | [`doc_comment_double_space_linebreaks`](https://rust-lang.github.io/rust-clippy/master/index.html#doc_comment_double_space_linebreaks) | 8 | stray trailing spaces, not intended hard breaks | | [`single_char_pattern`](https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern) | 23 | `char` patterns instead of one-character `&str` patterns | | [`format_push_string`](https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string) | 42 | `write!`/`writeln!` into the target `String`, dropping the temporary alloc | | [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr) | 83 | `ptr.cast::<T>()`, which cannot silently change constness | ## What is the testing strategy for this PR? `cargo clippy --workspace --all-targets --all-features -- -D warnings` reports no warnings, and the extended test suite passes. The changes are mechanical and behavior-preserving, so no new tests, with one exception: the `unicode_not_nfc` commit turns a duplicated `reverse` test case into real coverage of the composed grapheme. ## Are there any user-facing changes? No.
1 parent 19d31c5 commit a28ba02

76 files changed

Lines changed: 345 additions & 263 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.toml‎

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -270,61 +270,52 @@ wildcard_dependencies = "warn"
270270

271271
# Pedantic lints we opt out of, with the number of hits at the time we enabled `pedantic`.
272272
# Some of these we should consider enabling.
273-
borrow_as_ptr = "allow" # 6 hits
274-
cast_lossless = "allow" # 361 hits
275-
cast_possible_truncation = "allow" # 911 hits
276-
cast_possible_wrap = "allow" # 493 hits
277-
cast_precision_loss = "allow" # 266 hits
278-
cast_sign_loss = "allow" # 440 hits
279-
default_trait_access = "allow" # 221 hits
280-
doc_comment_double_space_linebreaks = "allow" # 6 hits
281-
doc_markdown = "allow" # 4933 hits; needs a long `doc-valid-idents` list in `clippy.toml`
282-
enum_glob_use = "allow" # 98 hits
283-
explicit_into_iter_loop = "allow" # 55 hits
284-
explicit_iter_loop = "allow" # 189 hits
285-
float_cmp = "allow" # 8 hits; exact float comparisons are often intentional here
286-
format_collect = "allow" # 4 hits
287-
format_push_string = "allow" # 34 hits
288-
from_iter_instead_of_collect = "allow" # 51 hits
289-
if_not_else = "allow" # 133 hits
290-
ignored_unit_patterns = "allow" # 52 hits
291-
implicit_clone = "allow" # 198 hits
292-
implicit_hasher = "allow" # 17 hits
293-
inline_always = "allow" # 45 hits
294-
items_after_statements = "allow" # 171 hits
295-
large_digit_groups = "allow" # 3 hits
296-
manual_string_new = "allow" # 84 hits
297-
many_single_char_names = "allow" # 12 hits; short names are idiomatic in the numeric kernels
298-
map_unwrap_or = "allow" # 198 hits
299-
match_bool = "allow" # 46 hits
300-
match_same_arms = "allow" # 261 hits
301-
match_wildcard_for_single_variants = "allow" # 132 hits
302-
missing_errors_doc = "allow" # 1807 hits
303-
missing_fields_in_debug = "allow" # 29 hits
304-
missing_panics_doc = "allow" # 244 hits
305-
must_use_candidate = "allow" # 2726 hits
306-
needless_bitwise_bool = "allow" # 1 hit
307-
needless_raw_string_hashes = "allow" # 540 hits
308-
ptr_as_ptr = "allow" # 83 hits
309-
redundant_closure_for_method_calls = "allow" # 686 hits
310-
redundant_else = "allow" # 48 hits
311-
return_self_not_must_use = "allow" # 644 hits
312-
semicolon_if_nothing_returned = "allow" # 1353 hits
313-
similar_names = "allow" # 228 hits; too many false positives, e.g. `expr`/`exprs`
314-
single_char_pattern = "allow" # 23 hits
315-
single_match_else = "allow" # 155 hits
316-
struct_excessive_bools = "allow" # 24 hits
317-
struct_field_names = "allow" # 14 hits
318-
too_many_lines = "allow" # 484 hits
319-
trivially_copy_pass_by_ref = "allow" # 74 hits
320-
unicode_not_nfc = "allow" # 2 hits
321-
unnecessary_literal_bound = "allow" # 471 hits
322-
unnecessary_wraps = "allow" # 427 hits
323-
unnested_or_patterns = "allow" # 68 hits
324-
unreadable_literal = "allow" # 502 hits
325-
unused_self = "allow" # 69 hits
326-
used_underscore_items = "allow" # 28 hits
327-
wildcard_imports = "allow" # 48 hits; `use crate::prelude::*` is idiomatic
273+
cast_lossless = "allow" # 361 hits
274+
cast_possible_truncation = "allow" # 911 hits
275+
cast_possible_wrap = "allow" # 493 hits
276+
cast_precision_loss = "allow" # 266 hits
277+
cast_sign_loss = "allow" # 440 hits
278+
default_trait_access = "allow" # 221 hits
279+
doc_markdown = "allow" # 4933 hits; needs a long `doc-valid-idents` list in `clippy.toml`
280+
enum_glob_use = "allow" # 98 hits
281+
explicit_into_iter_loop = "allow" # 55 hits
282+
explicit_iter_loop = "allow" # 189 hits
283+
float_cmp = "allow" # 8 hits; exact float comparisons are often intentional here
284+
from_iter_instead_of_collect = "allow" # 51 hits
285+
if_not_else = "allow" # 133 hits
286+
ignored_unit_patterns = "allow" # 52 hits
287+
implicit_clone = "allow" # 198 hits
288+
implicit_hasher = "allow" # 17 hits; some sites feed arrow APIs that require the default hasher
289+
inline_always = "allow" # 45 hits
290+
items_after_statements = "allow" # 171 hits
291+
manual_string_new = "allow" # 84 hits
292+
many_single_char_names = "allow" # 12 hits; short names are idiomatic in the numeric kernels
293+
map_unwrap_or = "allow" # 198 hits
294+
match_bool = "allow" # 46 hits
295+
match_same_arms = "allow" # 261 hits
296+
match_wildcard_for_single_variants = "allow" # 132 hits
297+
missing_errors_doc = "allow" # 1807 hits
298+
missing_fields_in_debug = "allow" # 29 hits
299+
missing_panics_doc = "allow" # 244 hits
300+
must_use_candidate = "allow" # 2726 hits
301+
needless_raw_string_hashes = "allow" # 540 hits
302+
redundant_closure_for_method_calls = "allow" # 686 hits
303+
redundant_else = "allow" # 48 hits
304+
return_self_not_must_use = "allow" # 644 hits
305+
semicolon_if_nothing_returned = "allow" # 1353 hits
306+
similar_names = "allow" # 228 hits; too many false positives, e.g. `expr`/`exprs`
307+
single_match_else = "allow" # 155 hits
308+
struct_excessive_bools = "allow" # 24 hits
309+
struct_field_names = "allow" # 14 hits
310+
too_many_lines = "allow" # 484 hits
311+
trivially_copy_pass_by_ref = "allow" # 74 hits
312+
unnecessary_literal_bound = "allow" # 471 hits
313+
unnecessary_wraps = "allow" # 427 hits
314+
unnested_or_patterns = "allow" # 68 hits
315+
unreadable_literal = "allow" # 502 hits
316+
unused_self = "allow" # 69 hits
317+
used_underscore_items = "allow" # 28 hits
318+
wildcard_imports = "allow" # 48 hits; `use crate::prelude::*` is idiomatic
328319

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

‎benchmarks/src/bin/benchmark_runner.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use datafusion_common_runtime::SpawnedTask;
4040
use serde::{Serialize, Serializer};
4141
use std::collections::{BTreeMap, BTreeSet};
4242
use std::ffi::{OsStr, OsString};
43+
use std::fmt::Write as _;
4344
use std::io::IsTerminal;
4445
use std::path::Path;
4546

@@ -333,12 +334,14 @@ fn format_suite_list(suites: &[SuiteMetadata]) -> String {
333334
} else {
334335
"queries "
335336
};
336-
output.push_str(&format!(
337-
" {:<24} {} {query_word}{}\n",
337+
writeln!(
338+
output,
339+
" {:<24} {} {query_word}{}",
338340
suite.name(),
339341
suite.benchmark_count(),
340342
suite.description()
341-
));
343+
)
344+
.ok();
342345
}
343346
output.trim_end().to_string()
344347
}

‎benchmarks/src/sql_benchmark_runner.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use datafusion::prelude::SessionContext;
2626
use datafusion_common::{DataFusionError, exec_datafusion_err};
2727
use std::any::Any;
2828
use std::collections::{BTreeMap, HashMap};
29+
use std::fmt::Write as _;
2930
use std::fs;
3031
use std::panic::{AssertUnwindSafe, catch_unwind};
3132
use std::path::{Path, PathBuf};
@@ -357,7 +358,7 @@ pub fn format_benchmark_list(benchmarks: &BTreeMap<String, Vec<SqlBenchmark>>) -
357358
} else {
358359
"queries"
359360
};
360-
output.push_str(&format!(" {name:<24} {} {query_word}\n", benchmarks.len()));
361+
writeln!(output, " {name:<24} {} {query_word}", benchmarks.len()).ok();
361362
}
362363

363364
output.trim_end().to_string()
@@ -439,7 +440,7 @@ fn format_subgroup_list(benchmark_name: &str, benchmarks: &[SqlBenchmark]) -> St
439440
output.push_str(" <none>");
440441
} else {
441442
for entry in entries {
442-
output.push_str(&format!(" {entry}\n"));
443+
writeln!(output, " {entry}").ok();
443444
}
444445
}
445446

@@ -485,7 +486,7 @@ fn format_query_list(
485486
output.push_str(" <none>");
486487
} else {
487488
for entry in entries {
488-
output.push_str(&format!(" {entry}\n"));
489+
writeln!(output, " {entry}").ok();
489490
}
490491
}
491492

‎benchmarks/src/util/memory.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ fn print_allocator_stats() {
5353
std::ptr::null_mut(),
5454
std::ptr::null_mut(),
5555
std::ptr::null_mut(),
56-
&mut peak_rss,
56+
&raw mut peak_rss,
5757
std::ptr::null_mut(),
58-
&mut peak_commit,
59-
&mut page_faults,
58+
&raw mut peak_commit,
59+
&raw mut page_faults,
6060
);
6161
}
6262

‎datafusion-cli/src/highlighter.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
//! The syntax highlighter.
1919
20+
use std::fmt::Write as _;
2021
use std::{
2122
borrow::Cow::{self, Borrowed},
2223
fmt::Display,
@@ -66,7 +67,9 @@ impl Highlighter for SyntaxHighlighter {
6667
Token::SingleQuotedString(_) => {
6768
out_line.push_str(&Color::green(token));
6869
}
69-
other => out_line.push_str(&format!("{other}")),
70+
other => {
71+
write!(out_line, "{other}").ok();
72+
}
7073
}
7174
}
7275
out_line.into()

‎datafusion-examples/examples/builtin_functions/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! - `date_time`
3131
//! (file: date_time.rs, desc: Examples of date-time related functions and queries)
3232
//!
33-
//! - `function_factory`
33+
//! - `function_factory`
3434
//! (file: function_factory.rs, desc: Register `CREATE FUNCTION` handler to implement SQL macros)
3535
//!
3636
//! - `regexp`

‎datafusion-examples/examples/custom_data_source/main.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
//! Each subcommand runs a corresponding example:
2828
//! - `all` — run all examples included in this module
2929
//!
30-
//! - `adapter_serialization`
30+
//! - `adapter_serialization`
3131
//! (file: adapter_serialization.rs, desc: Preserve custom PhysicalExprAdapter information during plan serialization using PhysicalExtensionCodec interception)
3232
//!
33-
//! - `csv_json_opener`
33+
//! - `csv_json_opener`
3434
//! (file: csv_json_opener.rs, desc: Use low-level FileOpener APIs for CSV/JSON)
3535
//!
3636
//! - `csv_sql_streaming`
3737
//! (file: csv_sql_streaming.rs, desc: Run a streaming SQL query against CSV data)
3838
//!
39-
//! - `custom_datasource`
39+
//! - `custom_datasource`
4040
//! (file: custom_datasource.rs, desc: Query a custom TableProvider)
4141
//!
4242
//! - `custom_file_casts`

‎datafusion-examples/examples/data_io/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//! - `parquet_emb_idx`
4646
//! (file: parquet_embedded_index.rs, desc: Store a custom index inside Parquet files)
4747
//!
48-
//! - `parquet_enc`
48+
//! - `parquet_enc`
4949
//! (file: parquet_encrypted.rs, desc: Read & write encrypted Parquet files)
5050
//!
5151
//! - `parquet_enc_with_kms`

‎datafusion-examples/examples/data_io/parquet_encrypted_with_kms.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl EncryptionFactory for TestEncryptionFactory {
241241
.with_footer_key_metadata(key_metadata.clone());
242242

243243
let encrypted_columns: HashSet<&str> =
244-
config.encrypted_columns.split(",").collect();
244+
config.encrypted_columns.split(',').collect();
245245
if !encrypted_columns.is_empty() {
246246
// Set up per-column encryption.
247247
for field in schema.fields().iter() {

‎datafusion-examples/examples/dataframe/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! Each subcommand runs a corresponding example:
2828
//! - `all` — run all examples included in this module
2929
//!
30-
//! - `cache_factory`
30+
//! - `cache_factory`
3131
//! (file: cache_factory.rs, desc: Custom lazy caching for DataFrames using `CacheFactory`)
3232
//
3333
//! - `dataframe`

0 commit comments

Comments
 (0)