|
1 | 1 | //! Source file parsing. |
2 | 2 | use crate::{ |
| 3 | + iter_util::IterExt as _, |
3 | 4 | rename::RenameExt, |
4 | 5 | target_os, |
5 | 6 | type_parser::{parse_rust_type, parse_rust_type_from_string, type_name}, |
@@ -278,7 +279,7 @@ pub fn parse_input( |
278 | 279 | ) |
279 | 280 | } |
280 | 281 |
|
281 | | -/// Check if we have not parsed any relavent typehsared types. |
| 282 | +/// Check if we have not parsed any relevant typehsared types. |
282 | 283 | fn is_parsed_data_empty(parsed_data: &ParsedData) -> bool { |
283 | 284 | parsed_data.enums.is_empty() |
284 | 285 | && parsed_data.aliases.is_empty() |
@@ -474,14 +475,21 @@ pub(crate) fn parse_enum(e: &ItemEnum, valid_os: Option<&[&str]>) -> Result<Rust |
474 | 475 | .collect::<Result<Vec<_>, _>>()?; |
475 | 476 |
|
476 | 477 | // Check if the enum references itself recursively in any of its variants |
477 | | - let is_recursive = variants.iter().any(|v| match v { |
478 | | - RustEnumVariant::Unit(_) => false, |
479 | | - RustEnumVariant::Tuple { ty, .. } => ty.contains_type(&original_enum_ident), |
480 | | - RustEnumVariant::AnonymousStruct { fields, .. } => fields |
481 | | - .iter() |
482 | | - .any(|f| f.ty.contains_type(&original_enum_ident)), |
483 | | - _ => panic!("unrecgonized enum type"), |
484 | | - }); |
| 478 | + let is_recursive = variants.iter().try_any(|v| { |
| 479 | + Ok(match v { |
| 480 | + RustEnumVariant::Unit(_) => false, |
| 481 | + RustEnumVariant::Tuple { ty, .. } => ty.contains_type(&original_enum_ident), |
| 482 | + RustEnumVariant::AnonymousStruct { fields, .. } => fields |
| 483 | + .iter() |
| 484 | + .any(|f| f.ty.contains_type(&original_enum_ident)), |
| 485 | + _ => { |
| 486 | + return Err(ParseError::new( |
| 487 | + &e, |
| 488 | + ParseErrorKind::UnsupportedType("Unsupported enum type".into()), |
| 489 | + )) |
| 490 | + } |
| 491 | + }) |
| 492 | + })?; |
485 | 493 |
|
486 | 494 | let shared = RustEnumShared { |
487 | 495 | id: get_ident(Some(&e.ident), &e.attrs, None), |
|
0 commit comments