fix(monty): compile the JSON string cache on the declared 1.96 MSRV

Merged
YI
2mo ago
+1-1

Fixes #985.

Problem

CacheInner::entries is a Box<[CacheEntry; CAPACITY]> (CAPACITY = 16_384).
drop_all iterates it with a reference to the Box itself:

for entry in &mut inner.entries {

A for loop calls IntoIterator::into_iter on the expression as written, with
no auto-deref, so this needs &mut Box<[T; N]>: IntoIterator. That impl does not
exist on the rustc releases at or below the rust-version = "1.96" declared in
Cargo.toml, and the loop fails to compile:

error[E0277]: `[Option<(u64, Box<str>, Value)>; 16384]` is not an iterator
  --> crates/monty/src/modules/json/string_cache.rs:98
   |
98 |             for entry in &mut inner.entries {
   |                  ^^^^^^^^^^^^ `[Option<(u64, Box<str>, Value)>; 16384]` is not an iterator

Fix

Dereference the Box so the loop borrows the array, and [T; N] has implemented
IntoIterator for &mut [T; N] since Rust 1.53:

for entry in &mut *inner.entries {

This is a one-line, source-compatible change. Behaviour is unchanged: the loop
still visits every one of the CAPACITY slots and keeps the existing
entry.take() / value.drop_with(heap) sequence, including the
value.drop_with(heap) ordering guarantee that cached values must be dropped
while the heap is still alive (it is called from VM::drop() before teardown).

I used &mut *inner.entries rather than inner.entries.iter_mut() because the
workspace lints against the pedantic group, which includes
clippy::explicit_iter_loop — that attribute would fire on the .iter_mut()
spelling.

Verification

  • cargo check -p monty --lib passes on rustc 1.99.0 both before and after, so
    this is a strict addition and does not regress current toolchains.

  • The failing pattern was confirmed with an isolated reproducer, where the only
    difference between the two spellings is the deref:

    let mut entries: Box<[u64; 16384]> = Box::new([0; 16384]);
    for entry in &mut entries { ... }        // E0277 on rustc 1.85.1
    for entry in &mut *entries { ... }       // compiles on 1.85.1 and 1.99.0
    
  • clippy-driver --edition=2024 -W clippy::pedantic (with the same allows listed
    in the workspace Cargo.toml) reports nothing on the new loop.

No other source file is touched.


Summary by cubic

Fixes the monty JSON string cache so it builds on the declared 1.96 MSRV. The teardown loop in drop_all iterated &mut Box<[T; N]>, which only gained an IntoIterator impl on newer rustc and caused E0277; dereferencing the box borrows the array itself, which has supported IntoIterator for &mut [T; N] since Rust 1.53. Behavior is unchanged: the loop still visits all CAPACITY slots and preserves the entry.take() / value.drop_with(heap) sequence so values are dropped before the heap is torn down. The deref spelling is used rather than .iter_mut() because the workspace's pedantic lint set would flag the latter.