-
Notifications
You must be signed in to change notification settings - Fork 16
Description
π¦ Rust Guard Improvement Report
Improvement 1: Remove Two Stale #[allow(dead_code)] Annotations in backend.rs
Category: Dead Code
File(s): guards/github-guard/rust-guard/src/labels/backend.rs
Effort: Small (< 5 min)
Risk: Low
Problem
Two #[allow(dead_code)] annotations in backend.rs suppress compiler warnings for functions that are actually called in production. The annotations are stale β likely left over from an earlier time when these functions were not yet wired up.
is_repo_private(line 56): Called bytool_rules.rs(Γ2),response_items.rs(Γ3),helpers.rs(Γ2), andresponse_paths.rs(Γ3) β 10 production call sites.get_issue_author_association(line 405): Called byhelpers.rs:1119to enrich issue integrity whenauthor_associationis absent from list responses.
These stale #[allow(dead_code)] attributes are misleading β they suggest the functions are unused, making a reviewer question whether they should be removed.
Suggested Change
Remove the two #[allow(dead_code)] lines only.
Before
/// Check whether a repository is private using the backend MCP server.
// ...
#[allow(dead_code)] // β stale: called in 10 places
pub fn is_repo_private(owner: &str, repo: &str) -> Option(bool) {
is_repo_private_with_callback(crate::invoke_backend, owner, repo)
}
// ...
#[allow(dead_code)] // β stale: called in helpers.rs:1119
pub fn get_issue_author_association(owner: &str, repo: &str, issue_number: &str) -> Option(String) {
get_issue_author_association_with_callback(crate::invoke_backend, owner, repo, issue_number)
}After
/// Check whether a repository is private using the backend MCP server.
// ...
pub fn is_repo_private(owner: &str, repo: &str) -> Option(bool) {
is_repo_private_with_callback(crate::invoke_backend, owner, repo)
}
// ...
pub fn get_issue_author_association(owner: &str, repo: &str, issue_number: &str) -> Option(String) {
get_issue_author_association_with_callback(crate::invoke_backend, owner, repo, issue_number)
}Why This Matters
Stale #[allow(dead_code)] annotations create noise that desensitises reviewers to real dead code warnings. They make it harder to identify functions that are genuinely unused (like is_owner or is_forked_pull_request_with_callback below). Removing them lets the compiler enforce correctness and makes code reviews easier.
Improvement 2: Remove is_forked_pull_request_with_callback (Superseded by get_pull_request_facts_with_callback)
Category: Dead Code
File(s): guards/github-guard/rust-guard/src/labels/backend.rs
Effort: Medium (15β20 min)
Risk: Low
Problem
is_forked_pull_request_with_callback (lines 215β282) is a standalone function that checks whether a PR is from a fork by calling pull_request_read. It:
- Has
#[allow(dead_code)]β it has zero production call sites. - Is only called from 3 unit tests within the same file (lines 727β744).
- Duplicates a subset of the logic already inside
get_pull_request_facts_with_callback(lines 285β357), which also extractsis_forked(stored asPullRequestFacts.is_forked) alongsideauthor_association,author_login, andis_merged.
The _with_callback pattern exists to allow injection of a mock backend in tests. get_pull_request_facts_with_callback already follows this same pattern and its result includes is_forked. There is no production wrapper (is_forked_pull_request) that calls it β making it a dead-end function.
Suggested Change
- Delete
is_forked_pull_request_with_callback(lines 215β282). - Convert the 3 tests that call it into tests on
get_pull_request_facts_with_callback, verifyingfacts.is_forkedβ this preserves the test coverage.
Before
/// Determine whether a pull request is from a fork.
// ...
#[allow(dead_code)]
pub fn is_forked_pull_request_with_callback(
callback: GithubMcpCallback,
owner: &str,
repo: &str,
pull_number: &str,
) -> Option(bool) {
// ... ~60 lines fetching PR and extracting base/head full_name ...
}
// In tests:
#[test]
fn test_is_forked_pull_request_direct() {
let result =
is_forked_pull_request_with_callback(direct_pr_callback, "owner", "repo", "123");
assert_eq!(result, Some(false));
}
#[test]
fn test_is_forked_pull_request_forked() {
let result = is_forked_pull_request_with_callback(fork_pr_callback, "owner", "repo", "123");
assert_eq!(result, Some(true));
}
#[test]
fn test_is_forked_pull_request_wrapped_response() {
let result =
is_forked_pull_request_with_callback(wrapped_fork_pr_callback, "owner", "repo", "123");
assert_eq!(result, Some(true));
}After
// is_forked_pull_request_with_callback deleted entirely.
// Tests migrated to get_pull_request_facts_with_callback:
#[test]
fn test_pull_request_facts_direct_pr_not_forked() {
let facts = get_pull_request_facts_with_callback(direct_pr_callback, "owner", "repo", "123");
assert_eq!(facts.map(|f| f.is_forked), Some(Some(false)));
}
#[test]
fn test_pull_request_facts_forked_pr() {
let facts = get_pull_request_facts_with_callback(fork_pr_callback, "owner", "repo", "123");
assert_eq!(facts.map(|f| f.is_forked), Some(Some(true)));
}
#[test]
fn test_pull_request_facts_wrapped_response_forked() {
let facts =
get_pull_request_facts_with_callback(wrapped_fork_pr_callback, "owner", "repo", "123");
assert_eq!(facts.map(|f| f.is_forked), Some(Some(true)));
}Why This Matters
- Removes ~70 lines of dead code (function + tests), reducing maintenance surface.
- Migrating the fork-detection tests to
get_pull_request_facts_with_callbackgives that function β the one that's actually used in production β its first direct unit tests, which is a net coverage gain. - Follows the single-function principle: the PR lookup is done once (
get_pull_request_facts), not via two independent functions that make the same network call.
Codebase Health Summary
- Total Rust files: 10
- Total lines: 8,510
- Areas analyzed:
backend.rs,helpers.rs,tool_rules.rs,response_items.rs,response_paths.rs,mod.rs,constants.rs,lib.rs,permissions.rs,tools.rs - Areas with no further improvements:
constants.rs,response_items.rs,response_paths.rs
Generated by Rust Guard Improver β’ Run: Β§23430373144
Generated by Rust Guard Improver Β· β·
- expires on Mar 30, 2026, 9:38 AM UTC