LCOV - code coverage report
Current view: top level - gcc/rust/checks/lints/unused - rust-unused-collector.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 83.0 % 47 39
Test Date: 2026-02-28 14:20:25 Functions: 80.0 % 10 8
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-collector.h"
      20              : #include "rust-hir-expr.h"
      21              : #include "rust-hir-full-decls.h"
      22              : #include "rust-hir-item.h"
      23              : #include "rust-hir-path.h"
      24              : #include "rust-hir-pattern.h"
      25              : #include "rust-immutable-name-resolution-context.h"
      26              : 
      27              : namespace Rust {
      28              : namespace Analysis {
      29            9 : UnusedCollector::UnusedCollector (UnusedContext &context)
      30            9 :   : nr_context (
      31            9 :     Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()),
      32           18 :     mappings (Analysis::Mappings::get ()), unused_context (context)
      33            9 : {}
      34              : void
      35            9 : UnusedCollector::go (HIR::Crate &crate)
      36              : {
      37           25 :   for (auto &item : crate.get_items ())
      38           16 :     item->accept_vis (*this);
      39            9 : }
      40              : 
      41              : void
      42           10 : UnusedCollector::visit (HIR::PathInExpression &expr)
      43              : {
      44           10 :   mark_path_used (expr);
      45           10 :   walk (expr);
      46           10 : }
      47              : 
      48              : void
      49            0 : UnusedCollector::visit (HIR::QualifiedPathInExpression &expr)
      50              : {
      51            0 :   mark_path_used (expr);
      52            0 :   walk (expr);
      53            0 : }
      54              : 
      55              : void
      56            0 : UnusedCollector::visit (HIR::StructExprFieldIdentifier &ident)
      57              : {
      58            0 :   mark_path_used (ident);
      59            0 :   walk (ident);
      60            0 : }
      61              : 
      62              : void
      63            9 : UnusedCollector::visit (HIR::AssignmentExpr &expr)
      64              : {
      65            9 :   auto def_id = get_def_id (expr.get_lhs ());
      66            9 :   HirId id = expr.get_lhs ().get_mappings ().get_hirid ();
      67            9 :   unused_context.remove_mut (def_id);
      68            9 :   unused_context.add_assign (def_id, id);
      69            9 :   visit_outer_attrs (expr);
      70            9 :   expr.get_rhs ().accept_vis (*this);
      71            9 : }
      72              : 
      73              : void
      74            8 : UnusedCollector::visit (HIR::IdentifierPattern &pattern)
      75              : {
      76            8 :   if (pattern.is_mut ())
      77            3 :     unused_context.add_mut (pattern.get_mappings ().get_hirid ());
      78              : 
      79            8 :   walk (pattern);
      80            8 : }
      81              : 
      82              : void
      83            2 : UnusedCollector::visit (HIR::StructPatternFieldIdent &pattern)
      84              : {
      85            2 :   if (pattern.is_mut ())
      86            2 :     unused_context.add_mut (pattern.get_mappings ().get_hirid ());
      87              : 
      88            2 :   walk (pattern);
      89            2 : }
      90              : 
      91              : void
      92            2 : UnusedCollector::visit (HIR::BreakExpr &expr)
      93              : {
      94            2 :   if (!expr.has_label ())
      95              :     return;
      96            1 :   mark_label_used (expr.get_label ());
      97            1 :   walk (expr);
      98              : }
      99              : 
     100              : void
     101            2 : UnusedCollector::visit (HIR::ContinueExpr &expr)
     102              : {
     103            2 :   if (!expr.has_label ())
     104              :     return;
     105            1 :   mark_label_used (expr.get_label ());
     106            1 :   walk (expr);
     107              : }
     108              : 
     109              : } // namespace Analysis
     110              : } // 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.