Replace .unwrap() with proper proc macro error handling in codegen

The generated proc macro code was using .unwrap() for parse failures,
causing panics instead of emitting proper Rust compile errors. Replace
both unwrap calls with match expressions that call
e.into_compile_error().into() to surface parse failures as compiler
diagnostics in the generated proc macros.

https://claude.ai/code/session_01D2g6zGJsBeUEzxBb7AvFDt
This commit is contained in:
Claude
2026-03-08 09:11:41 +00:00
parent 36c85500bd
commit 0ac3a473d4
+2 -2
View File
@@ -89,7 +89,7 @@ fn codegen_pattern_parse(pattern: &Pattern) -> String {
let b = &bindings[0];
let ty = binding_kind_to_type(&b.kind);
return format!(
" let {name}: {ty} = syn::parse2(input.clone()).unwrap(); // TODO: proper error\n",
" let {name}: {ty} = match syn::parse2(input.clone()) {{ Ok(v) => v, Err(e) => return e.into_compile_error().into() }};\n",
name = b.name,
ty = ty
);
@@ -149,7 +149,7 @@ fn codegen_structural_pattern(pattern: &Pattern, bindings: &[BindingInfo]) -> St
};
out.push_str(&format!(" {}\n", ret_expr));
out.push_str(" };\n");
out.push_str(" __parser.parse2(input.clone()).unwrap() // TODO: proper error\n");
out.push_str(" match __parser.parse2(input.clone()) { Ok(v) => v, Err(e) => return e.into_compile_error().into() }\n");
out.push_str(" };\n");
out