Skip to content

Commit b987740

Browse files
committed
fix(ci): resolve cargo fmt drift and doc warnings
- ensemble_translation.rs: cargo fmt reformatted a long match expression - noricum-ir lib.rs: rustdoc was parsing `Vec<T>` in a doc string as an unclosed HTML tag; wrapped the type examples in backticks. - noricum-core type_contract.rs: intra-doc link `[`MAX_CONTRACT_RETRIES`]` pointed at a private constant; downgraded to a plain code span. All three were promoted to errors by RUSTDOCFLAGS=-D warnings in CI. Verified locally with `cargo fmt --all -- --check` (exit 0) and `RUSTDOCFLAGS=-D warnings cargo doc --no-deps --workspace` (exit 0).
1 parent ac02002 commit b987740

3 files changed

Lines changed: 102 additions & 69 deletions

File tree

crates/noricum-agents/src/ensemble_translation.rs

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,26 @@ pub fn evaluate_candidate(
141141
estimated_cost_usd: f64,
142142
) -> TranslationCandidate {
143143
// Gate 1: Compilation
144-
let (compiles, compiler_errors) = match noricum_tools::compiler::check_rust_compiles(rust_source)
145-
{
146-
Ok(result) => {
147-
let errors: Vec<String> = if !result.success {
148-
result
149-
.stderr
150-
.lines()
151-
.filter(|l| l.contains("error"))
152-
.map(String::from)
153-
.collect()
154-
} else {
155-
Vec::new()
156-
};
157-
(result.success, errors)
158-
}
159-
Err(e) => {
160-
debug!(error = %e, "compilation check failed for candidate {}", config_label);
161-
(false, vec![format!("Compilation check error: {e}")])
162-
}
163-
};
144+
let (compiles, compiler_errors) =
145+
match noricum_tools::compiler::check_rust_compiles(rust_source) {
146+
Ok(result) => {
147+
let errors: Vec<String> = if !result.success {
148+
result
149+
.stderr
150+
.lines()
151+
.filter(|l| l.contains("error"))
152+
.map(String::from)
153+
.collect()
154+
} else {
155+
Vec::new()
156+
};
157+
(result.success, errors)
158+
}
159+
Err(e) => {
160+
debug!(error = %e, "compilation check failed for candidate {}", config_label);
161+
(false, vec![format!("Compilation check error: {e}")])
162+
}
163+
};
164164

165165
// Gate 2: Unsafe counting
166166
let unsafe_count = noricum_tools::compiler::count_unsafe_blocks(rust_source);
@@ -175,10 +175,7 @@ pub fn evaluate_candidate(
175175

176176
info!(
177177
label = config_label,
178-
compiles,
179-
unsafe_count,
180-
idiomatic_score,
181-
"evaluated ensemble candidate"
178+
compiles, unsafe_count, idiomatic_score, "evaluated ensemble candidate"
182179
);
183180

184181
TranslationCandidate {
@@ -218,27 +215,28 @@ pub fn evaluate_candidate_with_specs(
218215
// Optional Gate: Spec validation (only if compiles and traces available)
219216
if candidate.compiles
220217
&& let Some(traces) = traces
221-
&& !traces.is_empty() {
222-
match noricum_tools::spec_mining::validate_against_specs(rust_source, traces) {
223-
Ok(spec_result) => {
224-
candidate.specs_passed = Some(spec_result.passed);
225-
candidate.specs_total = Some(spec_result.total_specs);
226-
info!(
227-
label = config_label,
228-
specs_passed = spec_result.passed,
229-
specs_total = spec_result.total_specs,
230-
"P38: spec validation for ensemble candidate"
231-
);
232-
}
233-
Err(e) => {
234-
debug!(
235-
label = config_label,
236-
error = %e,
237-
"P38: spec validation failed for ensemble candidate"
238-
);
239-
}
240-
}
218+
&& !traces.is_empty()
219+
{
220+
match noricum_tools::spec_mining::validate_against_specs(rust_source, traces) {
221+
Ok(spec_result) => {
222+
candidate.specs_passed = Some(spec_result.passed);
223+
candidate.specs_total = Some(spec_result.total_specs);
224+
info!(
225+
label = config_label,
226+
specs_passed = spec_result.passed,
227+
specs_total = spec_result.total_specs,
228+
"P38: spec validation for ensemble candidate"
229+
);
241230
}
231+
Err(e) => {
232+
debug!(
233+
label = config_label,
234+
error = %e,
235+
"P38: spec validation failed for ensemble candidate"
236+
);
237+
}
238+
}
239+
}
242240

243241
candidate
244242
}
@@ -707,10 +705,7 @@ mod tests {
707705
#[test]
708706
fn test_estimate_candidate_cost_anthropic() {
709707
let cost = estimate_candidate_cost(1_000_000, 500_000, &ProviderKind::Anthropic);
710-
assert!(
711-
(cost - 10.5).abs() < 0.01,
712-
"expected ~$10.50, got ${cost}"
713-
);
708+
assert!((cost - 10.5).abs() < 0.01, "expected ~$10.50, got ${cost}");
714709
}
715710

716711
#[test]
@@ -945,9 +940,30 @@ pub fn hash_key(s: *const u8) -> u64 {
945940
let c = "unsigned long hash_key(const char *str) { unsigned long hash = 5381; int c; while ((c = *str++)) hash = ((hash << 5) + hash) + c; return hash; }";
946941

947942
let candidates = vec![
948-
evaluate_candidate(good_rust, c, "claude-0.3", ProviderKind::Anthropic, 0.3, 0.05),
949-
evaluate_candidate(mid_rust, c, "deepseek-0.3", ProviderKind::DeepSeek, 0.3, 0.01),
950-
evaluate_candidate(bad_rust, c, "deepseek-0.6", ProviderKind::DeepSeek, 0.6, 0.01),
943+
evaluate_candidate(
944+
good_rust,
945+
c,
946+
"claude-0.3",
947+
ProviderKind::Anthropic,
948+
0.3,
949+
0.05,
950+
),
951+
evaluate_candidate(
952+
mid_rust,
953+
c,
954+
"deepseek-0.3",
955+
ProviderKind::DeepSeek,
956+
0.3,
957+
0.01,
958+
),
959+
evaluate_candidate(
960+
bad_rust,
961+
c,
962+
"deepseek-0.6",
963+
ProviderKind::DeepSeek,
964+
0.6,
965+
0.01,
966+
),
951967
];
952968

953969
let compiled_count = candidates.iter().filter(|c| c.compiles).count();

crates/noricum-core/src/type_contract.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You translate C type definitions to idiomatic Rust. You output ONLY valid Rust c
2929
/// 4. Post-process: strip fences, strip impl blocks
3030
/// 5. Validate with `check_rust_compiles()`
3131
/// 6. Try rule engine fixes before LLM retry
32-
/// 7. Retry up to [`MAX_CONTRACT_RETRIES`] times on failure
32+
/// 7. Retry up to `MAX_CONTRACT_RETRIES` times on failure
3333
/// 8. Return `None` if all retries fail (graceful degradation)
3434
pub async fn generate_type_contract(
3535
client: &LlmClient,
@@ -59,9 +59,12 @@ pub async fn generate_type_contract(
5959
};
6060

6161
// Use Easy difficulty — type translation is a focused task
62-
let model_sel =
63-
select_model(provider_config, noricum_ir::Difficulty::Easy, "type_contract")
64-
.map_err(|e| CoreError::Orchestration(format!("P33 model selection: {e}")))?;
62+
let model_sel = select_model(
63+
provider_config,
64+
noricum_ir::Difficulty::Easy,
65+
"type_contract",
66+
)
67+
.map_err(|e| CoreError::Orchestration(format!("P33 model selection: {e}")))?;
6568
let model = &model_sel.model;
6669

6770
let c_abbreviated = abbreviate_c_for_context(c_source, CONTRACT_C_CONTEXT_MAX_LINES);
@@ -122,10 +125,8 @@ pub async fn generate_type_contract(
122125
&result.stderr[..result.stderr.len().min(500)]
123126
);
124127
// Try mechanical fixes via rule engine before LLM retry
125-
let parsed_errors =
126-
noricum_tools::repair_rules::parse_rustc_errors(&result.stderr);
127-
let fixed =
128-
noricum_tools::repair_rules::apply_all_rules(&contract, &parsed_errors);
128+
let parsed_errors = noricum_tools::repair_rules::parse_rustc_errors(&result.stderr);
129+
let fixed = noricum_tools::repair_rules::apply_all_rules(&contract, &parsed_errors);
129130
if fixed != contract {
130131
match noricum_tools::compiler::check_rust_compiles(&fixed) {
131132
Ok(r2) if r2.success => {
@@ -339,9 +340,7 @@ fn strip_impl_blocks(rust_source: &str) -> String {
339340
i = skip_braced_block_lines(&lines, i);
340341
continue;
341342
}
342-
if (trimmed.starts_with("pub fn ") || trimmed.starts_with("fn "))
343-
&& trimmed.contains('(')
344-
{
343+
if (trimmed.starts_with("pub fn ") || trimmed.starts_with("fn ")) && trimmed.contains('(') {
345344
if trimmed.contains('{') {
346345
i = skip_braced_block_lines(&lines, i);
347346
} else {
@@ -449,9 +448,14 @@ fn fix_contract_compilation_issues(source: &str) -> String {
449448

450449
// Replace derive(Debug, Clone) → derive(Debug) to avoid E0277 on non-Clone fields
451450
if trimmed.starts_with("#[derive(") && fixed.contains("Clone") {
452-
fixed = fixed.replace(", Clone", "").replace("Clone, ", "").replace("Clone", "Debug");
451+
fixed = fixed
452+
.replace(", Clone", "")
453+
.replace("Clone, ", "")
454+
.replace("Clone", "Debug");
453455
// Deduplicate Debug
454-
fixed = fixed.replace("Debug, Debug", "Debug").replace("(Debug, )", "(Debug)");
456+
fixed = fixed
457+
.replace("Debug, Debug", "Debug")
458+
.replace("(Debug, )", "(Debug)");
455459
}
456460

457461
result.push_str(&fixed);
@@ -707,18 +711,31 @@ pub type MzUint = u32;
707711
assert!(result.contains("Debug"), "Debug should remain");
708712

709713
// dyn multi-trait → usize
710-
assert!(!result.contains("dyn std::io::Read"), "trait objects should be replaced");
714+
assert!(
715+
!result.contains("dyn std::io::Read"),
716+
"trait objects should be replaced"
717+
);
711718
assert!(result.contains("usize"), "should have usize replacements");
712719

713720
// raw pointers → usize
714721
assert!(!result.contains("*mut"), "raw pointers should be replaced");
715722

716723
// type aliases commented out (not active code)
717-
assert!(result.contains("// P33: stripped alias"), "aliases should be commented out");
718-
assert!(!result.contains("\npub type MzBool"), "aliases should not be active");
724+
assert!(
725+
result.contains("// P33: stripped alias"),
726+
"aliases should be commented out"
727+
);
728+
assert!(
729+
!result.contains("\npub type MzBool"),
730+
"aliases should not be active"
731+
);
719732

720733
// Should compile
721734
let compile = noricum_tools::compiler::check_rust_compiles(&result).unwrap();
722-
assert!(compile.success, "Fixed contract should compile: {}", compile.stderr);
735+
assert!(
736+
compile.success,
737+
"Fixed contract should compile: {}",
738+
compile.stderr
739+
);
723740
}
724741
}

crates/noricum-ir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum SemanticHint {
6767
kind: String,
6868
/// C functions/structs involved
6969
involved: Vec<String>,
70-
/// Suggested Rust type (e.g., "Vec<T>", "HashMap<K, V>", "BTreeMap<K, V>")
70+
/// Suggested Rust type (e.g., `Vec<T>`, `HashMap<K, V>`, `BTreeMap<K, V>`)
7171
rust_type: String,
7272
},
7373
/// Algorithm pattern detected

0 commit comments

Comments
 (0)