Skip to content

[rust-guard] Rust Guard: Fix double extract_repo_info call + remove stale dead_code annotations in lib.rs #2226

@github-actions

Description

@github-actions

🦀 Rust Guard Improvement Report

Improvement 1: Fix Double extract_repo_info Call in response_paths.rs

Category: Duplication
File(s): guards/github-guard/rust-guard/src/labels/response_paths.rs
Effort: Small (< 15 min)
Risk: Low

Problem

In the "get_file_contents" branch of label_response_paths, extract_repo_info(tool_args) is called twice on consecutive lines to obtain the three components (owner, repo, repo_id) — but each call assigns only part of the tuple, discarding the rest via _:

line 352: let (_arg_owner, _arg_repo, arg_repo_full) = extract_repo_info(tool_args);
line 353: let (arg_owner, arg_repo, _) = extract_repo_info(tool_args);

Every other branch in the same function (list_pull_requests, list_issues, list_commits, list_releases, etc.) calls extract_repo_info exactly once and captures all three parts. This double call is an oversight that allocates three String values twice for no benefit.

Suggested Change

Merge the two calls into one:

Before

"get_file_contents" => {
    let (_arg_owner, _arg_repo, arg_repo_full) = extract_repo_info(tool_args);
    let (arg_owner, arg_repo, _) = extract_repo_info(tool_args);
    let secrecy = repo_visibility_secrecy(&arg_owner, &arg_repo, &arg_repo_full, ctx);

After

"get_file_contents" => {
    let (arg_owner, arg_repo, arg_repo_full) = extract_repo_info(tool_args);
    let secrecy = repo_visibility_secrecy(&arg_owner, &arg_repo, &arg_repo_full, ctx);

Why This Matters

  • Eliminates a redundant heap allocation (three String objects are created twice)
  • Removes misleading _arg_owner/_arg_repo bindings that look intentionally suppressed
  • Makes this branch consistent with every other branch in the same match

Improvement 2: Remove 6 Stale #[allow(dead_code)] Annotations from lib.rs

Category: Dead Code
File(s): guards/github-guard/rust-guard/src/lib.rs
Effort: Small (< 15 min)
Risk: Low

Problem

Six items in lib.rs carry #[allow(dead_code)] annotations that are no longer needed. All of them are actively called from submodules (labels/, permissions.rs) via crate::* paths, meaning Rust's dead-code lint would not fire if the annotations were removed:

Item Where it's called
pub fn invoke_backend labels/backend.rs:58, permissions.rs:159
pub enum LogLevel lib.rs itself (variant conversions in log())
fn log_debug labels/backend.rs, permissions.rs, labels/mod.rs
fn log_info labels/response_items.rs, labels/response_paths.rs, labels/backend.rs
fn log_warn labels/helpers.rs, labels/backend.rs, and others
fn log_error labels/backend.rs

These annotations were added as defensive scaffolding when the functions had no callers. Now that the logging and backend-call infrastructure is wired into all label modules, the suppressions are stale noise that:

  • Masks legitimate future dead-code warnings
  • Misleads reviewers into thinking these items may be unused

Suggested Change

Remove the six #[allow(dead_code)] attributes:

Before

#[allow(dead_code)]
pub fn invoke_backend(
    tool_name: &str,
    args_json: &str,
    result_buffer: &mut [u8],
) -> Result(usize, i32) { ... }

#[repr(u32)]
#[allow(dead_code)]
pub enum LogLevel { ... }

#[allow(dead_code)]
fn log_debug(msg: &str) { ... }

#[allow(dead_code)]
fn log_info(msg: &str) { ... }

#[allow(dead_code)]
fn log_warn(msg: &str) { ... }

#[allow(dead_code)]
fn log_error(msg: &str) { ... }

After

pub fn invoke_backend(
    tool_name: &str,
    args_json: &str,
    result_buffer: &mut [u8],
) -> Result(usize, i32) { ... }

#[repr(u32)]
pub enum LogLevel { ... }

fn log_debug(msg: &str) { ... }

fn log_info(msg: &str) { ... }

fn log_warn(msg: &str) { ... }

fn log_error(msg: &str) { ... }

Why This Matters

  • Removes misleading annotations from a high-traffic file
  • Ensures future dead-code lints on these items are not silently suppressed
  • Consistent with the ongoing effort to remove stale #[allow(dead_code)] annotations across the codebase (similar cleanups done previously in constants.rs, helpers.rs, backend.rs)

Codebase Health Summary

  • Total Rust files: 10
  • Total lines: 6,390
  • Areas analyzed: lib.rs, permissions.rs, tools.rs, labels/mod.rs, labels/backend.rs, labels/constants.rs, labels/helpers.rs, labels/response_items.rs, labels/response_paths.rs, labels/tool_rules.rs
  • Areas with no further improvements: labels/constants.rs (previously cleaned), labels/tool_rules.rs (recent cleanups applied)

Generated by Rust Guard Improver • Run: §23336520206

Generated by Rust Guard Improver ·

  • expires on Mar 27, 2026, 9:28 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions