https://gcc.gnu.org/g:eba7cd78ddf1a8ad7208b09029aff8a88a8d0b89

commit r16-2974-geba7cd78ddf1a8ad7208b09029aff8a88a8d0b89
Author: Arthur Cohen <arthur.co...@embecosm.com>
Date:   Tue Jul 22 16:29:09 2025 +0200

    gccrs: desugar: Add assertions for try-blocks and question-mark
    
    gcc/rust/ChangeLog:
    
            * ast/rust-desugar-question-mark.cc (DesugarQuestionMark::go): Add 
assertion for the
            expr's type.
            * ast/rust-desugar-try-block.cc (DesugarTryBlock::go): Likewise.

Diff:
---
 gcc/rust/ast/rust-desugar-question-mark.cc | 3 ++-
 gcc/rust/ast/rust-desugar-try-block.cc     | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-desugar-question-mark.cc 
b/gcc/rust/ast/rust-desugar-question-mark.cc
index ef2bdb87307f..01400d834b07 100644
--- a/gcc/rust/ast/rust-desugar-question-mark.cc
+++ b/gcc/rust/ast/rust-desugar-question-mark.cc
@@ -18,7 +18,6 @@
 
 #include "rust-desugar-question-mark.h"
 #include "rust-ast-builder.h"
-#include "rust-ast-visitor.h"
 
 namespace Rust {
 namespace AST {
@@ -28,6 +27,8 @@ DesugarQuestionMark::DesugarQuestionMark () {}
 void
 DesugarQuestionMark::go (std::unique_ptr<Expr> &ptr)
 {
+  rust_assert (ptr->get_expr_kind () == Expr::Kind::ErrorPropagation);
+
   auto original = static_cast<ErrorPropagationExpr &> (*ptr);
   auto desugared = DesugarQuestionMark ().desugar (original);
 
diff --git a/gcc/rust/ast/rust-desugar-try-block.cc 
b/gcc/rust/ast/rust-desugar-try-block.cc
index cd03350e98b8..07f06aabec89 100644
--- a/gcc/rust/ast/rust-desugar-try-block.cc
+++ b/gcc/rust/ast/rust-desugar-try-block.cc
@@ -28,6 +28,8 @@ DesugarTryBlock::DesugarTryBlock () {}
 void
 DesugarTryBlock::go (std::unique_ptr<Expr> &ptr)
 {
+  rust_assert (ptr->get_expr_kind () == Expr::Kind::Try);
+
   auto original = static_cast<TryExpr &> (*ptr);
   auto desugared = DesugarTryBlock ().desugar (original);

Reply via email to