Skip to content

Commit c7e25ff

Browse files
emilkclaude
andcommitted
feat: enable clippy::unnecessary_safety_comment
Catches `// SAFETY:` comments that do not sit in front of anything unsafe, so that a `SAFETY:` comment reliably means "an unsafe block follows, and here is why it is sound". * Three comments documented an `unwrap` or a safe copy rather than unsafe code, so they lose the `SAFETY:` prefix. * Three sat in front of an `if` while the `unsafe` block was inside it, so they move next to the block they justify. * Two were prose false positives, where the lint matched "safety:" in the middle of a doc comment. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 391b0e1 commit c7e25ff

9 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ unchecked_time_subtraction = "warn"
301301
uninhabited_references = "warn"
302302
uninlined_format_args = "warn"
303303
unnecessary_lazy_evaluations = "warn"
304+
unnecessary_safety_comment = "warn"
304305
unnecessary_safety_doc = "warn"
305306
unnecessary_self_imports = "warn"
306307
unused_async = "warn"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const JSON_CONVERTER_BUFFER_SIZE: usize = 2 * 1024 * 1024;
6666
/// A stream wrapper that holds SpawnedTask handles to keep them alive
6767
/// until the stream is fully consumed or dropped.
6868
///
69-
/// This ensures cancel-safety: when the stream is dropped, the tasks
69+
/// This ensures cancel-safety. When the stream is dropped, the tasks
7070
/// are properly aborted via SpawnedTask's Drop implementation.
7171
struct JsonArrayStream {
7272
inner: ReceiverStream<std::result::Result<RecordBatch, arrow::error::ArrowError>>,

‎datafusion/functions-aggregate/src/percentile_cont.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::utils::validate_percentile_expr;
6363

6464
/// Precision multiplier for linear interpolation calculations.
6565
///
66-
/// This value of 1,000,000 was chosen to balance precision with overflow safety:
66+
/// This value of 1,000,000 was chosen to balance precision against overflow:
6767
/// - Provides 6 decimal places of precision for the fractional component
6868
/// - Small enough to avoid overflow when multiplied with typical numeric values
6969
/// - Sufficient precision for most statistical applications

‎datafusion/functions/src/string/repeat.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ where
306306
// Doubling strategy: copy what we have so far until we reach the target
307307
while buffer.len() < src.len() * count {
308308
let copy_len = buffer.len().min(src.len() * count - buffer.len());
309-
// SAFETY: we're copying valid UTF-8 bytes that we already verified
309+
// We're copying valid UTF-8 bytes that we already verified
310310
buffer.extend_from_within(..copy_len);
311311
}
312312
}

‎datafusion/functions/src/unicode/character_length.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ where
158158
} else {
159159
let values: Vec<_> = (0..array.len())
160160
.map(|i| {
161-
// Safety: we are iterating with array.len() so the index is always valid
162161
if array.is_null(i) {
163162
T::default_value()
164163
} else {
164+
// SAFETY: we are iterating with array.len() so the index is always valid
165165
let value = unsafe { array.value_unchecked(i) };
166166
if value.is_empty() {
167167
T::default_value()

‎datafusion/optimizer/src/extract_equijoin_predicate.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl OptimizerRule for ExtractEquijoinPredicate {
9595
&& equijoin_predicates.is_empty()
9696
&& non_equijoin_expr.is_some()
9797
{
98-
// SAFETY: checked in the outer `if`
98+
// Checked in the outer `if`
9999
let expr = non_equijoin_expr.clone().unwrap();
100100
let (equijoin_predicates, non_equijoin_expr) =
101101
split_is_not_distinct_from_and_other_join_predicate(

‎datafusion/physical-expr-common/src/binary_map.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ fn single_null_buffer(num_values: usize, null_index: usize) -> NullBuffer {
557557
null_builder.append_n_non_nulls(null_index);
558558
null_builder.append_null();
559559
null_builder.append_n_non_nulls(num_values - null_index - 1);
560-
// SAFETY: inner builder must be constructed
560+
// The inner builder must be constructed
561561
null_builder.finish().unwrap()
562562
}
563563

‎datafusion/physical-plan/src/sorts/cursor.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,19 @@ impl CursorValues for StringViewArray {
460460

461461
#[inline(always)]
462462
fn compare(l: &Self, l_idx: usize, r: &Self, r_idx: usize) -> Ordering {
463-
// SAFETY: Prior assertions guarantee that l_idx and r_idx are valid indices.
463+
// Prior assertions guarantee that l_idx and r_idx are valid indices.
464464
// Null-checks are assumed to have been handled in the wrapper (e.g., ArrayValues).
465465
// And the bound is checked in is_finished, it is safe to call get_unchecked
466466
if l.data_buffers().is_empty() && r.data_buffers().is_empty() {
467+
// SAFETY: see above
467468
let l_view = unsafe { l.views().get_unchecked(l_idx) };
469+
// SAFETY: see above
468470
let r_view = unsafe { r.views().get_unchecked(r_idx) };
469471
return StringViewArray::inline_key_fast(*l_view)
470472
.cmp(&StringViewArray::inline_key_fast(*r_view));
471473
}
472474

475+
// SAFETY: see above
473476
unsafe { GenericByteViewArray::compare_unchecked(l, l_idx, r, r_idx) }
474477
}
475478

‎datafusion/spark/src/function/string/length.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ where
154154
} else {
155155
let values: Vec<_> = (0..array.len())
156156
.map(|i| {
157-
// Safety: we are iterating with array.len() so the index is always valid
158157
if array.is_null(i) {
159158
i32::default()
160159
} else {
160+
// SAFETY: we are iterating with array.len() so the index is always valid
161161
let value = unsafe { array.value_unchecked(i) };
162162
if value.is_empty() {
163163
i32::default()

0 commit comments

Comments
 (0)