Repository navigation
Description
🦀 Rust Guard Improvement Report
Improvement 1: extract_repo_id helper for callers that discard owner/repo
Category: Performance / Duplication
File(s): labels/helpers.rs (~L1280), lib.rs (L413, L596, L1277, L2056), labels/response_paths.rs (L1112)
Effort: Small (< 15 min)
Risk: Low
Problem
extract_repo_info allocates owner and repo Strings (via get_string_field), then builds a third repo_id String. Many call sites bind (_, _, repo_id) and drop the first two, so two allocations are wasted per call. These are in the per-request hot path.
Before
pub(crate) fn extract_repo_info(tool_args: &Value) -> (String, String, String) {
let owner = get_string_field(tool_args, field_names::OWNER);
let repo = get_string_field(tool_args, field_names::REPO);
let repo_id = format_repo_id(&owner, &repo);
(owner, repo, repo_id)
}
// caller
let (_, _, repo_id) = extract_repo_info(&input.tool_args);After
/// Extract only the "owner/repo" id (empty if either part is missing).
pub(crate) fn extract_repo_id(tool_args: &Value) -> String {
format_repo_id(
get_str_or(tool_args, field_names::OWNER, ""),
get_str_or(tool_args, field_names::REPO, ""),
)
}
// caller
let repo_id = extract_repo_id(&input.tool_args);Optionally have extract_repo_info reuse get_str_or(...).to_string(). Re-export it in lib.rs imports in place of extract_repo_info where no longer needed. Add a small unit test next to the existing extract_repo_info tests asserting equality with the third tuple element for: both present, missing owner, missing repo, non-string values.
Why This Matters
Removes 2 allocations per call at ~5 sites and makes intent explicit, with no behaviour change.
Improvement 2: Use get_str_or + field_names constants in lib.rs org/owner scope inference
Category: Duplication / Type Safety
File(s): lib.rs (L530–545, in infer_scope_for_baseline)
Effort: Small (< 15 min)
Risk: Low
Problem
infer_scope_for_baseline reads "owner"/"repo"/"organization_name" with raw literals and a hand-rolled tool_args.get(..).and_then(Value::as_str).unwrap_or("") chain, even though get_str_or and field_names::OWNER/REPO exist and are used everywhere else. (Earlier suggestions covered this pattern in other files, but this site remains.)
Before
let owner = tool_args.get("owner").and_then(Value::as_str).unwrap_or("");
let repo = tool_args.get("repo").and_then(Value::as_str).unwrap_or("");After
let owner = get_str_or(tool_args, field_names::OWNER, "");
let repo = get_str_or(tool_args, field_names::REPO, "");Do the same for the "organization_name" lookup, adding a field_names::ORGANIZATION_NAME constant if absent.
Why This Matters
Single source of truth for argument keys, so renames or typos are caught at compile time.
Codebase Health Summary
- Total Rust files: 9
- Total lines: ~25,850 (includes inline tests)
- Areas analyzed:
lib.rs,labels/helpers.rs,labels/response_paths.rs,labels/backend.rs,labels/tool_rules.rs,tools.rs - Areas with no further improvements: scope_names constants, allow(dead_code), non-test unwrap, raw string literal keys (non-test; except the
lib.rssite above)
Generated by Rust Guard Improver • Run: 43189247431
Generated by Rust Guard Improver · copilot · auto (Claude Sonnet 5.5) · ~28 AIC · ⊞ 6.4K · ◷
- expires on Nov 19, 2026, 9:15 AM UTC
Activity
Avoid discarded repository allocations in Rust guard (#16401)
[Repo Assist] rust-guard: add extract_repo_id helper to avoid discard…
[Repo Assist] rust-guard: reuse ORG_FIELD_ALIASES in infer_scope_for_…