LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 98.7 % 300 296
Test Date: 2026-11-14 16:39:50 Functions: 100.0 % 20 20
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-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-ast-lower.h"
      20              : #include "rust-ast-lower-item.h"
      21              : #include "rust-ast-lower-stmt.h"
      22              : #include "rust-ast-lower-expr.h"
      23              : #include "rust-ast-lower-block.h"
      24              : #include "rust-ast-lower-type.h"
      25              : #include "rust-ast-lower-pattern.h"
      26              : #include "rust-ast-lower-struct-field-expr.h"
      27              : #include "rust-expr.h"
      28              : #include "rust-hir-expr.h"
      29              : 
      30              : namespace Rust {
      31              : namespace HIR {
      32              : using HIR::ClosureParam;
      33              : 
      34              : Visibility
      35       244673 : translate_visibility (const AST::Visibility &vis)
      36              : {
      37              :   // FIXME: How do we create a private visibility here? Is it always private if
      38              :   // the AST vis is an error?
      39              :   // FIXME: We need to add a `create_private()` static function to the
      40              :   // AST::Visibility class and use it when the vis is empty in the parser...
      41              : 
      42       244673 :   switch (vis.get_vis_type ())
      43              :     {
      44        54084 :     case AST::Visibility::PUB:
      45        54084 :       return Visibility (Visibility::VisType::Public);
      46       187989 :     case AST::Visibility::PRIV:
      47       187989 :     case AST::Visibility::PUB_SELF:
      48       187989 :       return Visibility (Visibility::VisType::Private);
      49         2600 :     case AST::Visibility::PUB_CRATE:
      50         2600 :     case AST::Visibility::PUB_SUPER:
      51         2600 :     case AST::Visibility::PUB_IN_PATH:
      52         2600 :       return Visibility (Visibility::VisType::Restricted,
      53         2600 :                          ASTLoweringSimplePath::translate (vis.get_path ()),
      54         2600 :                          vis.get_locus ());
      55            0 :       break;
      56              :     }
      57              : 
      58            0 :   rust_unreachable ();
      59              : }
      60              : 
      61         5055 : ASTLowering::ASTLowering (AST::Crate &astCrate) : astCrate (astCrate) {}
      62              : 
      63         5047 : ASTLowering::~ASTLowering () {}
      64              : 
      65              : std::unique_ptr<HIR::Crate>
      66         5055 : ASTLowering::Resolve (AST::Crate &astCrate)
      67              : {
      68         5055 :   ASTLowering resolver (astCrate);
      69         5055 :   return resolver.go ();
      70         5047 : }
      71              : 
      72              : std::unique_ptr<HIR::Crate>
      73         5055 : ASTLowering::go ()
      74              : {
      75         5055 :   std::vector<std::unique_ptr<HIR::Item>> items;
      76              : 
      77        28056 :   for (auto &item : astCrate.items)
      78              :     {
      79        23009 :       auto translated = ASTLoweringItem::translate (*item);
      80        23001 :       if (translated != nullptr)
      81        21744 :         items.emplace_back (translated);
      82              :     }
      83              : 
      84         5047 :   auto &mappings = Analysis::Mappings::get ();
      85         5047 :   auto crate_num = mappings.crate.get_current_crate ();
      86         5047 :   Analysis::NodeMapping mapping (crate_num, astCrate.get_node_id (),
      87              :                                  mappings.get_next_hir_id (crate_num),
      88         5047 :                                  UNKNOWN_LOCAL_DEFID);
      89              : 
      90         5047 :   return std::unique_ptr<HIR::Crate> (
      91         5047 :     new HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping));
      92         5047 : }
      93              : 
      94              : // rust-ast-lower-block.h
      95              : void
      96       165028 : ASTLoweringBlock::visit (AST::BlockExpr &expr)
      97              : {
      98       165028 :   tl::optional<HIR::LoopLabel> label;
      99       165028 :   if (expr.has_label ())
     100            3 :     label = lower_loop_label (expr.get_label ());
     101              :   else
     102              :     label = tl::nullopt;
     103              : 
     104       165028 :   std::vector<std::unique_ptr<HIR::Stmt>> block_stmts;
     105       165028 :   bool block_did_terminate = false;
     106              : 
     107       268051 :   for (auto &s : expr.get_statements ())
     108              :     {
     109              :       // FIXME: We basically need to do that check for *every* single node in
     110              :       // the AST. this isn't realistic and this should be turned into an
     111              :       // optional, debug-visitor instead, which goes through the entire AST and
     112              :       // checks if any of the nodes are macro invocations
     113       103023 :       if (s->get_stmt_kind () == AST::Stmt::Kind::MacroInvocation)
     114            0 :         rust_fatal_error (
     115            0 :           s->get_locus (),
     116              :           "macro invocations should not get lowered to HIR - At "
     117              :           "this point in "
     118              :           "the pipeline, they should all have been expanded");
     119              : 
     120       103023 :       if (s->get_stmt_kind () != AST::Stmt::Kind::Item && block_did_terminate)
     121           20 :         rust_warning_at (s->get_locus (), 0, "unreachable statement");
     122              : 
     123       103023 :       bool terminated = false;
     124       103023 :       auto translated_stmt = ASTLoweringStmt::translate (s.get (), &terminated);
     125       103023 :       block_did_terminate |= terminated;
     126              : 
     127       103023 :       if (translated_stmt)
     128        98636 :         block_stmts.emplace_back (translated_stmt);
     129              :     }
     130              : 
     131       165028 :   if (expr.has_tail_expr () && block_did_terminate)
     132              :     {
     133              :       // warning unreachable tail expressions
     134           18 :       rust_warning_at (expr.get_tail_expr ().get_locus (), 0,
     135              :                        "unreachable expression");
     136              :     }
     137              : 
     138       165028 :   HIR::ExprWithoutBlock *tail_expr = nullptr;
     139       165028 :   if (expr.has_tail_expr ())
     140              :     {
     141       139904 :       bool terminated = false;
     142       139904 :       tail_expr = (HIR::ExprWithoutBlock *)
     143       139904 :         ASTLoweringExpr::translate (expr.get_tail_expr (), &terminated);
     144       139904 :       block_did_terminate |= terminated;
     145              :     }
     146              : 
     147       165028 :   bool tail_reachable = !block_did_terminate;
     148       165028 :   auto crate_num = mappings.crate.get_current_crate ();
     149       330056 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     150       165028 :                                  mappings.get_next_hir_id (crate_num),
     151       165028 :                                  UNKNOWN_LOCAL_DEFID);
     152       165028 :   translated
     153       165028 :     = new HIR::BlockExpr (mapping, std::move (block_stmts),
     154       330056 :                           std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr),
     155       165028 :                           tail_reachable, expr.get_inner_attrs (),
     156       165028 :                           expr.get_outer_attrs (), label,
     157       330056 :                           expr.get_start_locus (), expr.get_end_locus ());
     158              : 
     159       165028 :   terminated = block_did_terminate;
     160       165028 : }
     161              : 
     162              : void
     163         7172 : ASTLoweringIfBlock::visit (AST::IfExpr &expr)
     164              : {
     165         7172 :   bool ignored_terminated = false;
     166         7172 :   HIR::Expr *condition = ASTLoweringExpr::translate (expr.get_condition_expr (),
     167              :                                                      &ignored_terminated);
     168         7172 :   HIR::BlockExpr *block
     169         7172 :     = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
     170              : 
     171         7172 :   auto crate_num = mappings.crate.get_current_crate ();
     172        14344 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     173         7172 :                                  mappings.get_next_hir_id (crate_num),
     174         7172 :                                  UNKNOWN_LOCAL_DEFID);
     175              : 
     176         7172 :   translated = new HIR::IfExpr (mapping, std::unique_ptr<HIR::Expr> (condition),
     177        14344 :                                 std::unique_ptr<HIR::BlockExpr> (block),
     178         7172 :                                 expr.get_locus ());
     179         7172 : }
     180              : 
     181              : void
     182        10280 : ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr)
     183              : {
     184        10280 :   HIR::Expr *condition
     185        10280 :     = ASTLoweringExpr::translate (expr.get_condition_expr ());
     186              : 
     187        10280 :   bool if_block_terminated = false;
     188        10280 :   bool else_block_termianted = false;
     189              : 
     190        10280 :   HIR::BlockExpr *if_block
     191        10280 :     = ASTLoweringBlock::translate (expr.get_if_block (), &if_block_terminated);
     192        10280 :   HIR::ExprWithBlock *else_block
     193        10280 :     = ASTLoweringExprWithBlock::translate (expr.get_else_block (),
     194              :                                            &else_block_termianted);
     195              : 
     196        10280 :   terminated = if_block_terminated && else_block_termianted;
     197              : 
     198        10280 :   auto crate_num = mappings.crate.get_current_crate ();
     199        20560 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     200        10280 :                                  mappings.get_next_hir_id (crate_num),
     201        10280 :                                  UNKNOWN_LOCAL_DEFID);
     202              : 
     203        20560 :   translated = new HIR::IfExprConseqElse (
     204        10280 :     mapping, std::unique_ptr<HIR::Expr> (condition),
     205        20560 :     std::unique_ptr<HIR::BlockExpr> (if_block),
     206        20560 :     std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
     207        10280 : }
     208              : 
     209              : /**
     210              :  *  Lowers the common part "if let 'pattern' = 'expr' { 'if_block' }" of
     211              :  *  IfLetExpr[ConseqElse]:
     212              :  *  - 'expr' is lowered into *BRANCH_VALUE
     213              :  *  - 'pattern' + 'if_block' are lowered and resulting ARM pushed in MATCH_ARMS
     214              :  *  - 'KASE_ELSE_EXPR' is the lowered HIR to be used in the else part.
     215              :  *
     216              :  *  Looks like:
     217              :  *
     218              :  *  match (expr) {
     219              :  *    pattern => {if_block}
     220              :  *    _ => kase_else_expr
     221              :  *  }
     222              :  *
     223              :  */
     224              : void
     225          799 : ASTLoweringIfLetBlock::desugar_iflet (AST::IfLetExpr &expr,
     226              :                                       HIR::Expr **branch_value,
     227              :                                       HIR::Expr *kase_else_expr,
     228              :                                       std::vector<HIR::MatchCase> &match_arms)
     229              : {
     230          799 :   HIR::Expr *kase_expr;
     231          799 :   std::unique_ptr<HIR::Pattern> match_arm_pattern;
     232              : 
     233          799 :   *branch_value = ASTLoweringExpr::translate (expr.get_value_expr ());
     234          799 :   kase_expr = ASTLoweringExpr::translate (expr.get_if_block ());
     235              : 
     236              :   // (stable) if let only accepts a single pattern, but (unstable) if let chains
     237              :   // need more than one pattern.
     238              :   // We don't support if let chains, so only support a single pattern.
     239          799 :   rust_assert (expr.get_pattern () != nullptr);
     240              : 
     241          799 :   match_arm_pattern
     242          799 :     = ASTLoweringPattern::translate (*expr.get_pattern ())->clone_pattern ();
     243              : 
     244              :   // The match arm corresponding to the if let pattern when it matches.
     245          799 :   HIR::MatchArm arm (std::move (match_arm_pattern), expr.get_locus (), nullptr,
     246          799 :                      {});
     247              : 
     248          799 :   auto crate_num = mappings.crate.get_current_crate ();
     249         1598 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     250          799 :                                  mappings.get_next_hir_id (crate_num),
     251          799 :                                  UNKNOWN_LOCAL_DEFID);
     252              : 
     253          799 :   match_arms.emplace_back (std::move (mapping), std::move (arm),
     254          799 :                            std::unique_ptr<HIR::Expr> (kase_expr));
     255              : 
     256              :   // The default match arm when the if let pattern does not match
     257         1598 :   Analysis::NodeMapping mapping_default (crate_num, expr.get_node_id (),
     258          799 :                                          mappings.get_next_hir_id (crate_num),
     259          799 :                                          UNKNOWN_LOCAL_DEFID);
     260              : 
     261          799 :   auto match_arm_pattern_wildcard = std::unique_ptr<HIR::WildcardPattern> (
     262          799 :     new HIR::WildcardPattern (mapping_default, expr.get_locus ()));
     263              : 
     264          799 :   HIR::MatchArm arm_default (std::move (match_arm_pattern_wildcard),
     265         1598 :                              expr.get_locus (), nullptr, {});
     266              : 
     267          799 :   match_arms.emplace_back (std::move (mapping_default), std::move (arm_default),
     268          799 :                            std::unique_ptr<HIR::Expr> (kase_else_expr));
     269          799 : }
     270              : 
     271              : void
     272          514 : ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr)
     273              : {
     274              :   // Desugar:
     275              :   //   if let Some(y) = some_value {
     276              :   //     bar();
     277              :   //   }
     278              :   //
     279              :   //   into:
     280              :   //
     281              :   //   match some_value {
     282              :   //     Some(y) => {bar();},
     283              :   //     _ => ()
     284              :   //   }
     285              : 
     286          514 :   HIR::Expr *branch_value;
     287              : 
     288          514 :   std::vector<HIR::MatchCase> match_arms;
     289          514 :   auto crate_num = mappings.crate.get_current_crate ();
     290         1028 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     291          514 :                                  mappings.get_next_hir_id (crate_num),
     292          514 :                                  UNKNOWN_LOCAL_DEFID);
     293              : 
     294          514 :   HIR::TupleExpr *unit
     295          514 :     = new HIR::TupleExpr (mapping, {}, {}, {}, expr.get_locus ());
     296              : 
     297          514 :   desugar_iflet (expr, &branch_value, unit, match_arms);
     298              : 
     299          514 :   translated
     300          514 :     = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
     301         1028 :                           std::move (match_arms), {}, {}, expr.get_locus ());
     302          514 : }
     303              : 
     304              : void
     305          285 : ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr)
     306              : {
     307              :   // desugar:
     308              :   //   if let Some(y) = some_value {
     309              :   //     bar();
     310              :   //   } else {
     311              :   //     baz();
     312              :   //   }
     313              :   //
     314              :   //   into
     315              :   //   match some_value {
     316              :   //     Some(y) => {bar();},
     317              :   //     _ => {baz();}
     318              :   //   }
     319              :   //
     320              : 
     321          285 :   HIR::Expr *branch_value;
     322          285 :   std::vector<HIR::MatchCase> match_arms;
     323              : 
     324          285 :   HIR::Expr *kase_else_expr
     325          285 :     = ASTLoweringExpr::translate (expr.get_else_block ());
     326              : 
     327          285 :   desugar_iflet (expr, &branch_value, kase_else_expr, match_arms);
     328              : 
     329          285 :   auto crate_num = mappings.crate.get_current_crate ();
     330          570 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     331          285 :                                  mappings.get_next_hir_id (crate_num),
     332          285 :                                  UNKNOWN_LOCAL_DEFID);
     333              : 
     334          285 :   translated
     335          285 :     = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
     336          570 :                           std::move (match_arms), {}, {}, expr.get_locus ());
     337          285 : }
     338              : 
     339              : // rust-ast-lower-struct-field-expr.h
     340              : 
     341              : void
     342         7441 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field)
     343              : {
     344         7441 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ());
     345              : 
     346         7441 :   auto crate_num = mappings.crate.get_current_crate ();
     347         7441 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     348         7441 :                                  mappings.get_next_hir_id (crate_num),
     349         7441 :                                  UNKNOWN_LOCAL_DEFID);
     350              : 
     351         7441 :   translated = new HIR::StructExprFieldIdentifierValue (
     352        22323 :     mapping, field.get_field_name (), std::unique_ptr<HIR::Expr> (value),
     353        14882 :     field.get_locus ());
     354         7441 : }
     355              : 
     356              : void
     357           44 : ASTLowerStructExprField::visit (AST::StructExprFieldIndexValue &field)
     358              : {
     359           44 :   HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ());
     360              : 
     361           44 :   auto crate_num = mappings.crate.get_current_crate ();
     362           44 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     363           44 :                                  mappings.get_next_hir_id (crate_num),
     364           44 :                                  UNKNOWN_LOCAL_DEFID);
     365              : 
     366           44 :   translated
     367           44 :     = new HIR::StructExprFieldIndexValue (mapping, field.get_index (),
     368           44 :                                           std::unique_ptr<HIR::Expr> (value),
     369           44 :                                           field.get_locus ());
     370           44 : }
     371              : 
     372              : void
     373         1687 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifier &field)
     374              : {
     375         1687 :   auto crate_num = mappings.crate.get_current_crate ();
     376         1687 :   Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
     377         1687 :                                  mappings.get_next_hir_id (crate_num),
     378         1687 :                                  UNKNOWN_LOCAL_DEFID);
     379              : 
     380         1687 :   translated
     381         1687 :     = new HIR::StructExprFieldIdentifier (mapping, field.get_field_name (),
     382         1687 :                                           field.get_locus ());
     383         1687 : }
     384              : 
     385              : // rust-ast-lower-block.h
     386              : 
     387              : void
     388          934 : ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr)
     389              : {
     390          934 :   HIR::BlockExpr *loop_block
     391          934 :     = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated);
     392              : 
     393          934 :   tl::optional<HIR::LoopLabel> loop_label;
     394          934 :   if (expr.has_loop_label ())
     395            7 :     loop_label = lower_loop_label (expr.get_loop_label ());
     396              : 
     397          934 :   HIR::Expr *loop_condition
     398          934 :     = ASTLoweringExpr::translate (expr.get_predicate_expr (), &terminated);
     399              : 
     400          934 :   auto crate_num = mappings.crate.get_current_crate ();
     401         1868 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     402          934 :                                  mappings.get_next_hir_id (crate_num),
     403          934 :                                  UNKNOWN_LOCAL_DEFID);
     404              : 
     405          934 :   translated
     406          934 :     = new HIR::WhileLoopExpr (mapping,
     407          934 :                               std::unique_ptr<HIR::Expr> (loop_condition),
     408         1868 :                               std::unique_ptr<HIR::BlockExpr> (loop_block),
     409              :                               expr.get_locus (), std::move (loop_label),
     410         1868 :                               expr.get_outer_attrs ());
     411          934 : }
     412              : 
     413              : void
     414        42417 : ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr)
     415              : {
     416        42417 :   HIR::Expr *branch_value
     417        42417 :     = ASTLoweringExpr::translate (expr.get_scrutinee_expr ());
     418              : 
     419        42417 :   std::vector<HIR::MatchCase> match_arms;
     420       434562 :   for (auto &match_case : expr.get_match_cases ())
     421              :     {
     422       392145 :       HIR::Expr *kase_expr
     423       392145 :         = ASTLoweringExpr::translate (match_case.get_expr ());
     424              : 
     425       392145 :       HIR::Expr *kase_guard_expr = nullptr;
     426       392145 :       if (match_case.get_arm ().has_match_arm_guard ())
     427              :         {
     428          335 :           kase_guard_expr = ASTLoweringExpr::translate (
     429              :             match_case.get_arm ().get_guard_expr ());
     430              :         }
     431              : 
     432       392145 :       std::unique_ptr<HIR::Pattern> match_arm_pattern;
     433              : 
     434       392145 :       match_arm_pattern
     435       392145 :         = ASTLoweringPattern::translate (*match_case.get_arm ().get_pattern ())
     436       392145 :             ->clone_pattern ();
     437              : 
     438       392145 :       HIR::MatchArm arm (std::move (match_arm_pattern), expr.get_locus (),
     439       392145 :                          std::unique_ptr<HIR::Expr> (kase_guard_expr),
     440       392145 :                          match_case.get_arm ().get_outer_attrs ());
     441              : 
     442       392145 :       auto crate_num = mappings.crate.get_current_crate ();
     443       784290 :       Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     444       392145 :                                      mappings.get_next_hir_id (crate_num),
     445       392145 :                                      UNKNOWN_LOCAL_DEFID);
     446              : 
     447       392145 :       match_arms.emplace_back (std::move (mapping), std::move (arm),
     448       392145 :                                std::unique_ptr<HIR::Expr> (kase_expr));
     449       392145 :     }
     450              : 
     451        42417 :   auto crate_num = mappings.crate.get_current_crate ();
     452        84834 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     453        42417 :                                  mappings.get_next_hir_id (crate_num),
     454        42417 :                                  UNKNOWN_LOCAL_DEFID);
     455              : 
     456        42417 :   translated
     457        42417 :     = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
     458        42417 :                           std::move (match_arms), expr.get_inner_attrs (),
     459        84834 :                           expr.get_outer_attrs (), expr.get_locus ());
     460        42417 : }
     461              : 
     462              : // rust-ast-lower-expr.h
     463              : 
     464              : void
     465       641310 : ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
     466              : {
     467       641310 :   auto crate_num = mappings.crate.get_current_crate ();
     468      1282620 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     469       641310 :                                  mappings.get_next_hir_id (crate_num),
     470       641310 :                                  UNKNOWN_LOCAL_DEFID);
     471              : 
     472       641310 :   if (expr.is_lang_item ())
     473              :     {
     474        26610 :       translated = new HIR::PathInExpression (mapping, expr.get_lang_item (),
     475        13305 :                                               expr.get_locus ());
     476        13305 :       return;
     477              :     }
     478              : 
     479       628005 :   auto &segments = expr.get_segments ();
     480              : 
     481       628005 :   std::vector<HIR::PathExprSegment> path_segments;
     482       628005 :   path_segments.reserve (segments.size ());
     483              : 
     484      1355027 :   for (auto &s : segments)
     485              :     {
     486       727022 :       path_segments.push_back (lower_path_expr_seg ((s)));
     487              : 
     488              :       // insert the mappings for the segment
     489       727022 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     490       727022 :       mappings.hir.path_expr_segments.insert (lowered_seg);
     491              :     }
     492              : 
     493       628005 :   RawPath<HIR::PathExprSegment> path (std::move (path_segments),
     494       628005 :                                       expr.has_opening_scope_resolution ());
     495              : 
     496       628005 :   translated
     497       628005 :     = new HIR::PathInExpression (mapping, std::move (path), expr.get_locus ());
     498       628005 : }
     499              : 
     500              : HIR::QualifiedPathType
     501          944 : ASTLoweringBase::lower_qual_path_type (AST::QualifiedPathType &qualified_type)
     502              : {
     503          944 :   HIR::Type *type = ASTLoweringType::translate (qualified_type.get_type ());
     504          944 :   HIR::TypePath *trait
     505          944 :     = qualified_type.has_as_clause ()
     506          944 :         ? ASTLowerTypePath::translate (qualified_type.get_as_type_path ())
     507              :         : nullptr;
     508              : 
     509          944 :   auto crate_num = mappings.crate.get_current_crate ();
     510          944 :   Analysis::NodeMapping mapping (crate_num, qualified_type.get_node_id (),
     511          944 :                                  mappings.get_next_hir_id (crate_num),
     512          944 :                                  UNKNOWN_LOCAL_DEFID);
     513              : 
     514          944 :   return HIR::QualifiedPathType (mapping, std::unique_ptr<HIR::Type> (type),
     515         1888 :                                  std::unique_ptr<HIR::TypePath> (trait),
     516          944 :                                  qualified_type.get_locus ());
     517              : }
     518              : 
     519              : void
     520          944 : ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr)
     521              : {
     522          944 :   HIR::QualifiedPathType qual_path_type
     523          944 :     = lower_qual_path_type (expr.get_qualified_path_type ());
     524              : 
     525          944 :   auto &segments = expr.get_segments ();
     526              : 
     527          944 :   std::vector<HIR::PathExprSegment> path_segments;
     528          944 :   path_segments.reserve (segments.size ());
     529              : 
     530         1889 :   for (auto &s : segments)
     531              :     {
     532          945 :       path_segments.push_back (lower_path_expr_seg ((s)));
     533              : 
     534              :       // insert the mappings for the segment
     535          945 :       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
     536          945 :       mappings.hir.path_expr_segments.insert (lowered_seg);
     537              :     }
     538              : 
     539          944 :   RawPath<HIR::PathExprSegment> hir_path{path_segments,
     540          944 :                                          expr.has_opening_scope_resolution ()};
     541              : 
     542          944 :   auto crate_num = mappings.crate.get_current_crate ();
     543         1888 :   Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
     544          944 :                                  mappings.get_next_hir_id (crate_num),
     545          944 :                                  UNKNOWN_LOCAL_DEFID);
     546              : 
     547          944 :   translated = new HIR::QualifiedPathInExpression (mapping, qual_path_type,
     548              :                                                    std::move (hir_path),
     549              :                                                    expr.get_locus (),
     550         1888 :                                                    expr.get_outer_attrs ());
     551          944 : }
     552              : 
     553              : ClosureParam
     554         3098 : ASTLoweringBase::lower_closure_param (AST::ClosureParam &param)
     555              : {
     556         3098 :   HIR::Pattern *param_pattern
     557         3098 :     = ASTLoweringPattern::translate (param.get_pattern ());
     558              : 
     559         3098 :   HIR::Type *param_type = param.has_type_given ()
     560         3098 :                             ? ASTLoweringType::translate (param.get_type ())
     561              :                             : nullptr;
     562              : 
     563         6196 :   return HIR::ClosureParam (std::unique_ptr<HIR::Pattern> (param_pattern),
     564              :                             param.get_locus (),
     565         3098 :                             param.has_type_given ()
     566         6196 :                               ? std::unique_ptr<HIR::Type> (param_type)
     567              :                               : nullptr,
     568         9294 :                             param.get_outer_attrs ());
     569              : }
     570              : 
     571              : } // namespace HIR
     572              : } // namespace Rust
        

Generated by: LCOV version 2.5.0-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.