LCOV - code coverage report
Current view: top level - gcc/rust/checks/lints/unused - rust-unused-context.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.1 % 39 32
Test Date: 2026-08-08 15:37:49 Functions: 90.9 % 11 10
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-unused-context.h"
      20              : 
      21              : namespace Rust {
      22              : namespace Analysis {
      23              : 
      24              : void
      25           19 : UnusedContext::add_variable (HirId id)
      26              : 
      27              : {
      28           19 :   used_vars.emplace (id);
      29           19 : }
      30              : 
      31              : bool
      32           23 : UnusedContext::is_variable_used (HirId id) const
      33              : {
      34           23 :   return used_vars.find (id) != used_vars.end ();
      35              : }
      36              : 
      37              : void
      38           10 : UnusedContext::add_assign (HirId id_def, HirId id)
      39              : {
      40           10 :   assigned_vars[id_def].push_back (id);
      41           10 : }
      42              : 
      43              : void
      44           19 : UnusedContext::remove_assign (HirId id_def)
      45              : {
      46           19 :   if (assigned_vars.find (id_def) != assigned_vars.end ())
      47              :     {
      48            3 :       assigned_vars[id_def].pop_back ();
      49              : 
      50            3 :       if (assigned_vars[id_def].empty ())
      51            1 :         assigned_vars.erase (id_def);
      52              :     }
      53           19 : }
      54              : 
      55              : bool
      56           10 : UnusedContext::is_variable_assigned (HirId id_def, HirId id)
      57              : {
      58           10 :   auto assigned_vec = assigned_vars[id_def];
      59           20 :   return std::find (assigned_vec.begin (), assigned_vec.end (), id)
      60           20 :          != assigned_vec.end ();
      61           10 : }
      62              : 
      63              : void
      64            6 : UnusedContext::add_mut (HirId id)
      65              : {
      66            6 :   mutable_vars.emplace (id);
      67            6 : }
      68              : 
      69              : void
      70           10 : UnusedContext::remove_mut (HirId id)
      71              : {
      72           10 :   mutable_vars.erase (id);
      73           10 : }
      74              : 
      75              : bool
      76            6 : UnusedContext::is_mut_used (HirId id) const
      77              : {
      78            6 :   return mutable_vars.find (id) == mutable_vars.end ();
      79              : }
      80              : 
      81              : void
      82            2 : UnusedContext::add_label (HirId id)
      83              : 
      84              : {
      85            2 :   used_labels.emplace (id);
      86            2 : }
      87              : 
      88              : bool
      89            4 : UnusedContext::is_label_used (HirId id) const
      90              : {
      91            4 :   return used_labels.find (id) != used_labels.end ();
      92              : }
      93              : 
      94              : std::string
      95            0 : UnusedContext::as_string () const
      96              : {
      97            0 :   std::stringstream ss;
      98            0 :   ss << "UnusedContext: ";
      99            0 :   for (const auto &v : used_vars)
     100              :     {
     101            0 :       ss << "HirId: " << v << "\n";
     102              :     }
     103            0 :   return ss.str ();
     104            0 : }
     105              : 
     106              : } // namespace Analysis
     107              : } // 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.