Skip to content

Commit cec7848

Browse files
committed
transpile: Allow limited cast translation in patterns
1 parent 3055e1f commit cec7848

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • c2rust-transpile/src/translator

c2rust-transpile/src/translator/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,7 +2967,11 @@ impl<'c> Translation<'c> {
29672967
if ctx.is_pattern
29682968
&& !matches!(
29692969
expr_kind,
2970-
CExprKind::Paren(..) | CExprKind::ConstantExpr(..) | CExprKind::Literal(..)
2970+
CExprKind::Paren(..)
2971+
| CExprKind::ConstantExpr(..)
2972+
| CExprKind::Literal(..)
2973+
| CExprKind::ImplicitCast(..)
2974+
| CExprKind::ExplicitCast(..)
29712975
)
29722976
{
29732977
return Err(TranslationError::generic(
@@ -3703,6 +3707,12 @@ impl<'c> Translation<'c> {
37033707
return Ok(val);
37043708
}
37053709

3710+
if ctx.is_pattern && !matches!(kind, CastKind::ToVoid | CastKind::ConstCast) {
3711+
return Err(TranslationError::generic(
3712+
"cast kind is not supported in patterns",
3713+
));
3714+
}
3715+
37063716
match kind {
37073717
CastKind::BitCast | CastKind::NoOp => {
37083718
self.convert_pointer_to_pointer_cast(source_cty, target_cty, val)

0 commit comments

Comments
 (0)