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-08-22 16:33:35 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-expr.h"
      21              : 
      22              : namespace Rust {
      23              : namespace AST {
      24              : 
      25           31 : DesugarTryBlock::DesugarTryBlock () {}
      26              : 
      27              : void
      28           31 : DesugarTryBlock::go (std::unique_ptr<Expr> &ptr, Builder::Source node_source)
      29              : {
      30           31 :   rust_assert (ptr->get_expr_kind () == Expr::Kind::Try);
      31              : 
      32           31 :   auto original = static_cast<TryExpr &> (*ptr);
      33           31 :   auto desugared = DesugarTryBlock ().desugar (original, node_source);
      34              : 
      35           31 :   ptr = std::move (desugared);
      36           31 : }
      37              : 
      38              : std::unique_ptr<Expr>
      39           31 : DesugarTryBlock::desugar (TryExpr &expr, Builder::Source node_source)
      40              : {
      41           31 :   auto builder = Builder (expr.get_locus (), node_source);
      42           31 :   auto &block = expr.get_block_expr ();
      43              : 
      44           31 :   if (block.has_statements ())
      45            0 :     rust_sorry_at (expr.get_locus (),
      46              :                    "cannot desugar try-blocks with statements");
      47              : 
      48           31 :   auto tail_expr = builder.tuple ();
      49              : 
      50           31 :   if (block.has_tail_expr ())
      51           31 :     tail_expr = block.get_tail_expr ().clone_expr ();
      52              : 
      53              :   // Wrap in Try::from_ok call
      54           31 :   auto from_ok = builder.path_in_expression (LangItem::Kind::TRY_FROM_OK);
      55           62 :   auto call = builder.call (ptrify (from_ok), std::move (tail_expr));
      56              : 
      57           31 :   return builder.block (std::move (call));
      58           31 : }
      59              : 
      60              : } // namespace AST
      61              : } // 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.