From 17182ccabc7ce31d9fe6aca724522a00050e0cca Mon Sep 17 00:00:00 2001 From: Shivakumar Date: Fri, 21 Aug 2026 00:08:01 +0530 Subject: [PATCH] fix(clippy): chunks_exact_to_as_chunks + result_large_err from a newer stable clippy CI's clippy job pins dtolnay/rust-toolchain # stable, which floats. A newer stable Rust/clippy (1.98.0, per the lint doc URLs) started blocking CI on every PR on pre-existing code, confirmed unrelated to any in-flight PR's own diff (repros identically against clean master). - documents.rs (x2) / embed.rs: chunks_exact(4) -> as_chunks::<4>().0, clippy's own suggested fix (chunks_exact_to_as_chunks); same remainder-dropping behavior as before. - forward.rs: check_status's Err(Response) boxed (clippy::result_large_err -- axum::http::Response is >=128 bytes), updating its three match-arm callers to deref. Agentflare-Agent: claude-code_2-1-237_agent Agentflare-Branch: task/521-fix-clippy-chunks-exact-to-as-chunks-res Agentflare-Item: 521 --- crates/agentflare-store/src/documents.rs | 12 +++++++---- crates/agentflare-store/src/embed.rs | 6 ++++-- crates/flare-proxy/src/forward.rs | 26 +++++++++++++++--------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/agentflare-store/src/documents.rs b/crates/agentflare-store/src/documents.rs index 86baa84a..57a8a0ee 100644 --- a/crates/agentflare-store/src/documents.rs +++ b/crates/agentflare-store/src/documents.rs @@ -550,8 +550,10 @@ impl Store { |row| { let blob: Vec = row.get(0)?; let vec: Vec = blob - .chunks_exact(4) - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) + .as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) .collect(); Ok(vec) }, @@ -588,8 +590,10 @@ impl Store { return None; } let doc_vec: Vec = blob - .chunks_exact(4) - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) + .as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) .collect(); let sim = crate::embed::cosine_similarity(query_vec, &doc_vec)? as f64; Some(( diff --git a/crates/agentflare-store/src/embed.rs b/crates/agentflare-store/src/embed.rs index d3944605..960912ed 100644 --- a/crates/agentflare-store/src/embed.rs +++ b/crates/agentflare-store/src/embed.rs @@ -25,8 +25,10 @@ pub fn bytes_to_vec(b: &[u8]) -> Option> { return None; } Some( - b.chunks_exact(4) - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) + b.as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) .collect(), ) } diff --git a/crates/flare-proxy/src/forward.rs b/crates/flare-proxy/src/forward.rs index 8b5e57b7..0c620f28 100644 --- a/crates/flare-proxy/src/forward.rs +++ b/crates/flare-proxy/src/forward.rs @@ -125,7 +125,7 @@ async fn proxy_anthropic( let resp = match check_status(resp).await { Ok(resp) => resp, - Err(err) => return err, + Err(err) => return *err, }; Response::builder() @@ -170,7 +170,7 @@ async fn proxy_gemini( false, false, ), - Err(err) => err, + Err(err) => *err, } } @@ -212,7 +212,7 @@ async fn proxy_openai_compat( needs_heuristic, needs_think, ), - Err(err) => err, + Err(err) => *err, } } @@ -233,19 +233,25 @@ fn apply_extra_headers( /// Verify the upstream response succeeded, converting a non-2xx into an /// Anthropic-shaped error `Response`. On success, hands back the still-open /// `reqwest::Response` so the caller can stream its body. -async fn check_status(resp: reqwest::Response) -> Result { +/// +/// `Response` (`axum::http::Response`) is >=128 bytes, so +/// it's boxed in the `Err` variant rather than inflating every `Result` +/// return by that much even on the success path (`clippy::result_large_err`). +async fn check_status(resp: reqwest::Response) -> Result> { if resp.status().is_success() { return Ok(resp); } let status = resp.status(); let body = resp.text().await.unwrap_or_default(); let err_val: Value = serde_json::from_str(&body).unwrap_or(json!({"error": {"message": body}})); - Err(( - StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::BAD_GATEWAY), - [(axum::http::header::CONTENT_TYPE, "application/json")], - serde_json::to_string(&shape_xlat::error_to_anthropic(&err_val)).unwrap_or_default(), - ) - .into_response()) + Err(Box::new( + ( + StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::BAD_GATEWAY), + [(axum::http::header::CONTENT_TYPE, "application/json")], + serde_json::to_string(&shape_xlat::error_to_anthropic(&err_val)).unwrap_or_default(), + ) + .into_response(), + )) } /// Shared SSE loop for providers whose raw stream needs translating into