코드리뷰리팩토링보안by affaan-m
러스트 빌드 및 수정
러스트 빌드 오류, 빌려쓰기 체커 문제, 의존성 문제를 점진적으로 수정합니다.
한 줄 평가 — 다음 사람 도와주세요
언제 쓰나
러스트 프로젝트에서 빌드 오류나 빌려쓰기 체커 문제가 발생할 때 사용합니다.
SKILL.md
Lattice 한국어 번역 · 원본 affaan-m/everything-claude-code (841beea). 복사 → 저장하면 Claude Code가 인식합니다.
---
description: Rust 빌드 오류, borrow checker 문제 및 종속성 문제를 점진적으로 해결합니다. 최소한의 수술적 수정을 위해 rust-build-resolver 에이전트를 호출합니다.
---
# Rust 빌드 및 수정
이 명령어는 **rust-build-resolver** 에이전트를 호출하여 최소한의 변경으로 Rust 빌드 오류를 점진적으로 수정합니다.
## 이 명령어는 무엇을 하나요?
1. **진단 실행**: `cargo check`, `cargo clippy`, `cargo fmt --check` 실행
2. **오류 구문 분석**: 오류 코드 및 영향을 받은 파일 식별
3. **점진적 수정**: 한 번에 하나의 오류
4. **각 수정 사항 확인**: 각 변경 후 `cargo check` 다시 실행
5. **요약 보고**: 무엇이 수정되었고 무엇이 남아 있는지 표시
## 언제 사용해야 하나요?
`/rust-build`는 다음과 같은 경우에 사용하세요:
- `cargo build` 또는 `cargo check`가 오류와 함께 실패하는 경우
- `cargo clippy`가 경고를 보고하는 경우
- Borrow checker 또는 lifetime 오류로 컴파일이 차단되는 경우
- Cargo 종속성 해결에 실패하는 경우
- 빌드를 중단시키는 변경 사항을 pull한 후
## 실행되는 진단 명령어
```bash
# 기본 빌드 확인
cargo check 2>&1
# 린트 및 제안
clippy -- -D warnings 2>&1
# 서식 확인
cargo fmt --check 2>&1
# 종속성 문제
cargo tree --duplicates
# 보안 감사 (사용 가능한 경우)
if command -v cargo-audit >/dev/null; then cargo audit; else echo "cargo-audit not installed"; fi
```
## 예시 세션
````text
User: /rust-build
Agent:
# Rust Build Resolution
## Initial Diagnostics
```bash
$ cargo check
error[E0502]: cannot borrow `map` as mutable because it is also borrowed as immutable
--> src/service/cache.rs:25:5
error[E0308]: mismatched types
--> src/handler/api.rs:42:12
error[E0425]: cannot find value `db` in this scope
--> src/handler/api.rs:58:9
```
Errors found: 3
## Fix 1: Borrow Checker Error
File: src/service/cache.rs:25
Error: E0502 — cannot borrow `map` as mutable because also borrowed as immutable
Cause: Immutable borrow still active during mutable insert
```rust
// Changed: restructured to end immutable borrow before mutable access
if !map.contains_key("key") {
map.insert("key".into(), default);
}
```
```bash
$ cargo check
# 2 errors remaining
```
## Fix 2: Type Mismatch
File: src/handler/api.rs:42
Error: E0308 — mismatched types: expected `usize`, found `&str`
```rust
// Changed
let count = params.get("count");
// To
let count: usize = params.get("count")
.and_then(|s| s.parse().ok())
.unwrap_or(0);
```
```bash
$ cargo check
# 1 error remaining
```
## Fix 3: Unresolved Name
File: src/handler/api.rs:58
Error: E0425 — cannot find value `db` in this scope
Cause: Missing import
```rust
// Added
use crate::db;
```
```bash
$ cargo check
# Build successful!
```
## Final Verification
```bash
$ cargo clippy -- -D warnings
# No warnings
$ cargo test
running 6 tests
test service::cache::tests::test_insert ... ok
test service::cache::tests::test_get ... ok
test handler::api::tests::test_parse_count ... ok
test handler::api::tests::test_missing_count ... ok
test handler::api::tests::test_db_import ... ok
test handler::api::tests::test_response ... ok
test result: ok. 6 passed; 0 failed; 0 ignored
```
## Summary
| Metric | Count |
|--------|-------|
| Build errors fixed | 3 |
| Clippy warnings fixed | 0 |
| Files modified | 2 |
| Remaining issues | 0 |
Build Status: SUCCESS
````
## 일반적인 오류 수정
| Error | Typical Fix |
|-------|-------------|
| `cannot borrow as mutable` | Restructure to end immutable borrow first; clone only if justified |
| `does not live long enough` | Use owned type or add lifetime annotation |
| `cannot move out of` | Restructure to take ownership; clone only as last resort |
| `mismatched types` | Add `.into()`, `as`, or explicit conversion |
| `trait X not implemented` | Add `#[derive(Trait)]` or implement manually |
| `unresolved import` | Add to Cargo.toml or fix `use` path |
| `cannot find value` | Add import or fix path |
## 수정 전략
1. **빌드 오류 우선** - 코드는 컴파일되어야 합니다.
2. **Clippy 경고 두 번째** - 의심스러운 구문 수정
3. **서식 세 번째** - `cargo fmt` 규정 준수
4. **한 번에 하나의 수정** - 각 변경 사항 확인
5. **최소한의 변경** - 리팩터링하지 말고 그냥 수정
## 중단 조건
에이전트는 다음과 같은 경우 중단하고 보고합니다:
- 3회 시도 후에도 동일한 오류가 지속되는 경우
- 수정 시 더 많은 오류가 발생하는 경우
- 아키텍처 변경이 필요한 경우
- borrow checker 오류로 데이터 소유권 재설계가 필요한 경우
## 관련 명령어
- `/rust-test` - 빌드 성공 후 테스트 실행
- `/rust-review` - 코드 품질 검토
- `verification-loop` skill - 전체 검증 루프
## 관련 항목
- Agent: `agents/rust-build-resolver.md`
- Skill: `skills/rust-patterns/`필요한 도구
호버하면 설명CC
설치 + 호출 (2단계)
Claude Code CLI 기준.
- 1
SKILL.md 저장
아래 버튼으로 복사 → 다음 경로로 저장.
~/.claude/skills/everything-claude-code-158/SKILL.md - 2
호출
Claude Code 채팅창에서 자연어로 부르면 자동 발동:
예) 러스트 프로젝트에서 빌드 오류나 빌려쓰기 체커 문제가 발생할 때 사용합니다
트리거가 안 잡히면 SKILL.md의
description줄에 더 구체적인 한국어 키워드를 추가해보세요.