LCOV - code coverage report
Current view: top level - gcc/rust/ast - rust-desugar-try-block.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.7 % 19 18
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2025-2026 Free Software Foundation, Inc.
       2              : 
       3              : // This file is part of GCC.
       4              : 
       5              : // GCC is free software; you can redistribute it and/or modify it under
       6              : // the terms of the GNU General Public License as published by the Free
       7              : // Software Foundation; either version 3, or (at your option) any later
       8              : // version.
       9              : 
      10              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13              : // for more details.
      14              : 
      15              : // You should have received a copy of the GNU General Public License
      16              : // along with GCC; see the file COPYING3.  If not see
      17              : // <http://www.gnu.org/licenses/>.
      18              : 
      19              : #include "rust-desugar-try-block.h"
      20              : #include "rust-ast-builder.h"
      21              : #include "rust-expr.h"
      22              : 
      23              : namespace Rust {
      24              : namespace AST {
      25              : 
      26            1 : DesugarTryBlock::DesugarTryBlock () {}
      27              : 
      28              : void
      29            1 : DesugarTryBlock::go (std::unique_ptr<Expr> &ptr)
      30              : {
      31            1 :   rust_assert (ptr->get_expr_kind () == Expr::Kind::Try);
      32              : 
      33            1 :   auto original = static_cast<TryExpr &> (*ptr);
      34            1 :   auto desugared = DesugarTryBlock ().desugar (original);
      35              : 
      36            1 :   ptr = std::move (desugared);
      37            1 : }
      38              : 
      39              : std::unique_ptr<Expr>
      40            1 : DesugarTryBlock::desugar (TryExpr &expr)
      41              : {
      42            1 :   auto builder = Builder (expr.get_locus ());
      43            1 :   auto &block = expr.get_block_expr ();
      44              : 
      45            1 :   if (block.has_statements ())
      46            0 :     rust_sorry_at (expr.get_locus (),
      47              :                    "cannot desugar try-blocks with statements");
      48              : 
      49            1 :   auto tail_expr = builder.tuple ();
      50              : 
      51            1 :   if (block.has_tail_expr ())
      52            1 :     tail_expr = block.get_tail_expr ().clone_expr ();
      53              : 
      54              :   // Wrap in Try::from_ok call
      55            1 :   auto from_ok = builder.path_in_expression (LangItem::Kind::TRY_FROM_OK);
      56            2 :   auto call = builder.call (ptrify (from_ok), std::move (tail_expr));
      57              : 
      58            1 :   return builder.block (std::move (call));
      59            1 : }
      60              : 
      61              : } // namespace AST
      62              : } // namespace Rust
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.