Skip to content

Commit 5b1cd6d

Browse files
timfennisclaude
andcommitted
📎 Fix all clippy warnings, add &mut [T] macro support
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5361ec6 commit 5b1cd6d

15 files changed

Lines changed: 110 additions & 78 deletions

File tree

‎.cargo/config.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rustflags = [
1212
"-Wclippy::dbg_macro",
1313
"-Wclippy::debug_assert_with_mut_call",
1414
"-Wclippy::doc_markdown",
15-
"-Wclippy::empty_enum",
15+
"-Wclippy::empty_enums",
1616
"-Wclippy::enum_glob_use",
1717
"-Wclippy::exit",
1818
"-Wclippy::expl_impl_clone_on_copy",
@@ -76,7 +76,7 @@ rustflags = [
7676
"-Wtrivial-numeric-casts",
7777
"-Wunused-crate-dependencies",
7878
"-Wunused-qualifications",
79-
"-Wclippy::as_conversions",
79+
"-Aclippy::as_conversions",
8080
"-Wclippy::as_pointer_underscore",
8181
"-Wclippy::doc_include_without_cfg",
8282
"-Wclippy::get_unwrap",

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Before commit
66
- Run `cargo fmt`
7-
- Run `cargo check` and fix warnings and errors
7+
- Run `cargo clippy` and fix all warnings
88
- Ensure all tests pass (`cargo test`)
99
- Do not leave `TODO` comments in code — either fix the issue immediately or open a GitHub issue and record it in `TODO.md`
1010

‎ndc_bin/build.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ fn main() {
55
.args(["rev-parse", "--short", "HEAD"])
66
.output()
77
.ok()
8-
.filter(|o| o.status.success()).map_or_else(|| "unknown".to_string(), |o| String::from_utf8_lossy(&o.stdout).trim().to_string());
8+
.filter(|o| o.status.success())
9+
.map_or_else(
10+
|| "unknown".to_string(),
11+
|o| String::from_utf8_lossy(&o.stdout).trim().to_string(),
12+
);
913

1014
let dirty = Command::new("git")
1115
.args(["diff", "--quiet", "HEAD"])

‎ndc_core/src/static_type.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,10 @@ impl StaticType {
314314

315315
// Parameters: contravariant, so we need GLB (greatest lower bound)
316316
let parameters = match (p1, p2) {
317-
(None, None) => None,
318317
(Some(ps1), Some(ps2)) if ps1.len() == ps2.len() => {
319318
Some(ps1.iter().zip(ps2).map(|(a, b)| a.glb(b)).collect())
320319
}
321-
// Incompatible parameter lists
320+
// Incompatible or unknown parameter lists
322321
_ => None,
323322
};
324323

‎ndc_lsp/src/backend.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ fn collect_hints(expr: &ExpressionLocation, text: &str, hints: &mut Vec<InlayHin
258258
}
259259
collect_hints(body, text, hints);
260260
}
261-
Expression::Statement(inner) => collect_hints(inner, text, hints),
262-
Expression::Grouping(inner) => collect_hints(inner, text, hints),
261+
Expression::Statement(inner) | Expression::Grouping(inner) => {
262+
collect_hints(inner, text, hints);
263+
}
263264
Expression::Block { statements } => {
264265
for s in statements {
265266
collect_hints(s, text, hints);
@@ -294,8 +295,9 @@ fn collect_hints(expr: &ExpressionLocation, text: &str, hints: &mut Vec<InlayHin
294295
}
295296
}
296297
match body.as_ref() {
297-
ForBody::Block(e) => collect_hints(e, text, hints),
298-
ForBody::List { expr: e, .. } => collect_hints(e, text, hints),
298+
ForBody::Block(e) | ForBody::List { expr: e, .. } => {
299+
collect_hints(e, text, hints);
300+
}
299301
ForBody::Map {
300302
key,
301303
value,

‎ndc_macros/src/function.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn wrap_function(function: &syn::ItemFn) -> syn::Result<Vec<WrappedFunction>
6969
.map(|(i, function_name)| {
7070
let ident = format_ident!("{original_identifier}_{i}");
7171
wrap_single(
72-
function.clone(),
72+
function,
7373
&ident,
7474
function_name,
7575
&return_type,
@@ -279,7 +279,7 @@ fn map_type_path(p: &syn::TypePath) -> syn::Result<TokenStream> {
279279
}
280280

281281
fn wrap_single(
282-
function: syn::ItemFn,
282+
function: &syn::ItemFn,
283283
identifier: &syn::Ident,
284284
register_as_function_name: &proc_macro2::Literal,
285285
return_type: &TokenStream,
@@ -295,7 +295,7 @@ fn wrap_single(
295295
};
296296

297297
let vm = try_generate_vm_native(
298-
&function,
298+
function,
299299
&inner_ident,
300300
register_as_function_name,
301301
docs,

‎ndc_macros/src/types.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ fn classify_ref_mut(inner: &syn::Type) -> Option<NdcType> {
176176
if is_collection_of_vm_value(inner, "Vec") {
177177
return Some(NdcType::MutVecOfValue);
178178
}
179+
// &mut [Value] — same extraction as &mut Vec<Value>, Rust auto-coerces
180+
if let syn::Type::Slice(slice) = inner
181+
&& classify_owned(&slice.elem) == Some(NdcType::VmValue)
182+
{
183+
return Some(NdcType::MutVecOfValue);
184+
}
179185
if is_collection_of_vm_value(inner, "HashMap") {
180186
return Some(NdcType::MutHashMap);
181187
}

‎ndc_macros/src/vm_convert.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,13 @@ fn try_vm_return_type(ty: &syn::Type) -> Option<(TokenStream, TokenStream)> {
462462
/// sense as the Ok type inside a `Result<()>`.
463463
fn try_vm_return_inner(ty: &syn::Type) -> Option<(TokenStream, TokenStream)> {
464464
if let syn::Type::Tuple(t) = ty
465-
&& t.elems.is_empty() {
466-
return Some((
467-
quote! { Ok(ndc_vm::value::Value::unit()) },
468-
quote! { ndc_core::StaticType::Tuple(vec![]) },
469-
));
470-
}
465+
&& t.elems.is_empty()
466+
{
467+
return Some((
468+
quote! { Ok(ndc_vm::value::Value::unit()) },
469+
quote! { ndc_core::StaticType::Tuple(vec![]) },
470+
));
471+
}
471472
vm_return_for_classified(ty)
472473
}
473474

‎ndc_stdlib/src/index.rs‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,25 @@ enum VmOffset {
200200

201201
fn extract_vm_offset(index_value: &Value, size: usize) -> Result<VmOffset, VmError> {
202202
if let Value::Object(obj) = index_value
203-
&& let Object::Iterator(iter) = obj.as_ref() {
204-
let iter_ref = iter.borrow();
205-
if let Some((start, end, inclusive)) = iter_ref.range_bounds() {
206-
let from_idx = to_forward_index(start, size, true)?;
207-
let to_idx = to_forward_index(end, size, true)?;
208-
let to_idx = if inclusive {
209-
(to_idx + 1).min(size)
210-
} else {
211-
to_idx
212-
};
213-
return Ok(VmOffset::Range(from_idx, to_idx));
214-
}
215-
if let Some(start) = iter_ref.unbounded_range_start() {
216-
let from_idx = to_forward_index(start, size, true)?;
217-
return Ok(VmOffset::Range(from_idx, size));
218-
}
219-
return Err(VmError::native("cannot use non-range iterator as index"));
203+
&& let Object::Iterator(iter) = obj.as_ref()
204+
{
205+
let iter_ref = iter.borrow();
206+
if let Some((start, end, inclusive)) = iter_ref.range_bounds() {
207+
let from_idx = to_forward_index(start, size, true)?;
208+
let to_idx = to_forward_index(end, size, true)?;
209+
let to_idx = if inclusive {
210+
(to_idx + 1).min(size)
211+
} else {
212+
to_idx
213+
};
214+
return Ok(VmOffset::Range(from_idx, to_idx));
220215
}
216+
if let Some(start) = iter_ref.unbounded_range_start() {
217+
let from_idx = to_forward_index(start, size, true)?;
218+
return Ok(VmOffset::Range(from_idx, size));
219+
}
220+
return Err(VmError::native("cannot use non-range iterator as index"));
221+
}
221222
let i = match index_value {
222223
Value::Int(i) => *i,
223224
Value::Object(obj) => match obj.as_ref() {
@@ -353,7 +354,7 @@ fn vm_set_at_index(container: &Value, index_value: &Value, rhs: Value) -> Result
353354
match container {
354355
Value::Object(obj) => match obj.as_ref() {
355356
Object::List(list) => {
356-
let mut list = list.try_borrow_mut().map_err(|_| {
357+
let mut list = list.try_borrow_mut().map_err(|_borrow_err| {
357358
VmError::native("Mutation error: you cannot mutate a value in a list while you're iterating over this list")
358359
})?;
359360
match extract_vm_offset(index_value, size)? {

‎ndc_stdlib/src/rand.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod inner {
2525
use ndc_core::num::Number;
2626

2727
/// Randomly shuffles the elements of the list in place.
28-
pub fn shuffle(list: &mut Vec<Value>) {
28+
pub fn shuffle(list: &mut [Value]) {
2929
list.shuffle(&mut rand::rng());
3030
}
3131

0 commit comments

Comments
 (0)