Generate assertion for enum tuple variants with error collection
(value_expr: &TokenStream, pattern: &PatternEnum)
| 442 | |
| 443 | /// Generate assertion for enum tuple variants with error collection |
| 444 | fn expand_enum_assertion(value_expr: &TokenStream, pattern: &PatternEnum) -> TokenStream { |
| 445 | let variant_path = &pattern.path; |
| 446 | let elements = &pattern.elements; |
| 447 | let span = variant_path.span(); |
| 448 | |
| 449 | let error_push = generate_error_push( |
| 450 | span, |
| 451 | quote!(format!("{:?}", #value_expr)), |
| 452 | quote!(None), |
| 453 | pattern.node_id, |
| 454 | ); |
| 455 | |
| 456 | // Special handling for unit variants (empty elements) |
| 457 | if elements.is_empty() { |
| 458 | quote_spanned! {span=> |
| 459 | if !matches!(#value_expr, #variant_path) { |
| 460 | #error_push |
| 461 | } |
| 462 | } |
| 463 | } else { |
| 464 | // Use helper to process elements with appropriate path |
| 465 | let (match_patterns, element_assertions) = process_tuple_elements(elements, "__elem_"); |
| 466 | |
| 467 | quote_spanned! {span=> |
| 468 | #[allow(unreachable_patterns)] |
| 469 | match &#value_expr { |
| 470 | #variant_path(#(#match_patterns),*) => { |
| 471 | #(#element_assertions)* |
| 472 | }, |
| 473 | _ => { |
| 474 | #error_push |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /// Generate range assertion with error collection |
| 482 | fn expand_range_assertion(value_expr: &TokenStream, pattern: &PatternRange) -> TokenStream { |
no test coverage detected