From 0ac3a473d492dcb95a99554b2e9141397e2fb092 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Mar 2026 09:11:41 +0000 Subject: [PATCH] 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 --- misses-compiler/src/codegen.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misses-compiler/src/codegen.rs b/misses-compiler/src/codegen.rs index 4e176ed..758d219 100644 --- a/misses-compiler/src/codegen.rs +++ b/misses-compiler/src/codegen.rs @@ -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