Skip to content

Commit 7860a34

Browse files
committed
transpile: Allow limited cast translation in patterns
1 parent 3e438a0 commit 7860a34

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(
@@ -3698,6 +3702,12 @@ impl<'c> Translation<'c> {
36983702
return Ok(val);
36993703
}
37003704

3705+
if ctx.is_pattern && !matches!(kind, CastKind::ToVoid | CastKind::ConstCast) {
3706+
return Err(TranslationError::generic(
3707+
"cast kind is not supported in patterns",
3708+
));
3709+
}
3710+
37013711
match kind {
37023712
CastKind::BitCast | CastKind::NoOp => {
37033713
self.convert_pointer_to_pointer_cast(source_cty.ctype, target_cty.ctype, val)

0 commit comments

Comments
 (0)