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 342077 : 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 342077 : switch (vis.get_vis_type ())
43 : {
44 75512 : case AST::Visibility::PUB:
45 75512 : return Visibility (Visibility::VisType::Public);
46 262713 : case AST::Visibility::PRIV:
47 262713 : case AST::Visibility::PUB_SELF:
48 262713 : return Visibility (Visibility::VisType::Private);
49 3852 : case AST::Visibility::PUB_CRATE:
50 3852 : case AST::Visibility::PUB_SUPER:
51 3852 : case AST::Visibility::PUB_IN_PATH:
52 3852 : return Visibility (Visibility::VisType::Restricted,
53 3852 : ASTLoweringSimplePath::translate (vis.get_path ()),
54 3852 : vis.get_locus ());
55 0 : break;
56 : }
57 :
58 0 : rust_unreachable ();
59 : }
60 :
61 5059 : ASTLowering::ASTLowering (AST::Crate &astCrate) : astCrate (astCrate) {}
62 :
63 5051 : ASTLowering::~ASTLowering () {}
64 :
65 : std::unique_ptr<HIR::Crate>
66 5059 : ASTLowering::Resolve (AST::Crate &astCrate)
67 : {
68 5059 : ASTLowering resolver (astCrate);
69 5059 : return resolver.go ();
70 5051 : }
71 :
72 : std::unique_ptr<HIR::Crate>
73 5059 : ASTLowering::go ()
74 : {
75 5059 : std::vector<std::unique_ptr<HIR::Item>> items;
76 :
77 28304 : for (auto &item : astCrate.items)
78 : {
79 23253 : auto translated = ASTLoweringItem::translate (*item);
80 23245 : if (translated != nullptr)
81 21980 : items.emplace_back (translated);
82 : }
83 :
84 5051 : auto &mappings = Analysis::Mappings::get ();
85 5051 : auto crate_num = mappings.crate.get_current_crate ();
86 5051 : Analysis::NodeMapping mapping (crate_num, astCrate.get_node_id (),
87 : mappings.get_next_hir_id (crate_num),
88 5051 : UNKNOWN_LOCAL_DEFID);
89 :
90 5051 : return std::unique_ptr<HIR::Crate> (
91 5051 : new HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping));
92 5051 : }
93 :
94 : // rust-ast-lower-block.h
95 : void
96 232042 : ASTLoweringBlock::visit (AST::BlockExpr &expr)
97 : {
98 232042 : tl::optional<HIR::LoopLabel> label;
99 232042 : if (expr.has_label ())
100 3 : label = lower_loop_label (expr.get_label ());
101 : else
102 : label = tl::nullopt;
103 :
104 232042 : std::vector<std::unique_ptr<HIR::Stmt>> block_stmts;
105 232042 : bool block_did_terminate = false;
106 :
107 371267 : 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 139225 : 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 139225 : 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 139225 : bool terminated = false;
124 139225 : auto translated_stmt = ASTLoweringStmt::translate (s.get (), &terminated);
125 139225 : block_did_terminate |= terminated;
126 :
127 139225 : if (translated_stmt)
128 132654 : block_stmts.emplace_back (translated_stmt);
129 : }
130 :
131 232042 : 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 232042 : HIR::ExprWithoutBlock *tail_expr = nullptr;
139 232042 : if (expr.has_tail_expr ())
140 : {
141 198792 : bool terminated = false;
142 198792 : tail_expr = (HIR::ExprWithoutBlock *)
143 198792 : ASTLoweringExpr::translate (expr.get_tail_expr (), &terminated);
144 198792 : block_did_terminate |= terminated;
145 : }
146 :
147 232042 : bool tail_reachable = !block_did_terminate;
148 232042 : auto crate_num = mappings.crate.get_current_crate ();
149 464084 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
150 232042 : mappings.get_next_hir_id (crate_num),
151 232042 : UNKNOWN_LOCAL_DEFID);
152 232042 : translated
153 232042 : = new HIR::BlockExpr (mapping, std::move (block_stmts),
154 464084 : std::unique_ptr<HIR::ExprWithoutBlock> (tail_expr),
155 232042 : tail_reachable, expr.get_inner_attrs (),
156 232042 : expr.get_outer_attrs (), label,
157 464084 : expr.get_start_locus (), expr.get_end_locus ());
158 :
159 232042 : terminated = block_did_terminate;
160 232042 : }
161 :
162 : void
163 9714 : ASTLoweringIfBlock::visit (AST::IfExpr &expr)
164 : {
165 9714 : bool ignored_terminated = false;
166 9714 : HIR::Expr *condition = ASTLoweringExpr::translate (expr.get_condition_expr (),
167 : &ignored_terminated);
168 9714 : HIR::BlockExpr *block
169 9714 : = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated);
170 :
171 9714 : auto crate_num = mappings.crate.get_current_crate ();
172 19428 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
173 9714 : mappings.get_next_hir_id (crate_num),
174 9714 : UNKNOWN_LOCAL_DEFID);
175 :
176 9714 : translated = new HIR::IfExpr (mapping, std::unique_ptr<HIR::Expr> (condition),
177 19428 : std::unique_ptr<HIR::BlockExpr> (block),
178 9714 : expr.get_locus ());
179 9714 : }
180 :
181 : void
182 14680 : ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr)
183 : {
184 14680 : HIR::Expr *condition
185 14680 : = ASTLoweringExpr::translate (expr.get_condition_expr ());
186 :
187 14680 : bool if_block_terminated = false;
188 14680 : bool else_block_termianted = false;
189 :
190 14680 : HIR::BlockExpr *if_block
191 14680 : = ASTLoweringBlock::translate (expr.get_if_block (), &if_block_terminated);
192 14680 : HIR::ExprWithBlock *else_block
193 14680 : = ASTLoweringExprWithBlock::translate (expr.get_else_block (),
194 : &else_block_termianted);
195 :
196 14680 : terminated = if_block_terminated && else_block_termianted;
197 :
198 14680 : auto crate_num = mappings.crate.get_current_crate ();
199 29360 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
200 14680 : mappings.get_next_hir_id (crate_num),
201 14680 : UNKNOWN_LOCAL_DEFID);
202 :
203 29360 : translated = new HIR::IfExprConseqElse (
204 14680 : mapping, std::unique_ptr<HIR::Expr> (condition),
205 29360 : std::unique_ptr<HIR::BlockExpr> (if_block),
206 29360 : std::unique_ptr<HIR::ExprWithBlock> (else_block), expr.get_locus ());
207 14680 : }
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 1163 : 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 1163 : HIR::Expr *kase_expr;
231 1163 : std::unique_ptr<HIR::Pattern> match_arm_pattern;
232 :
233 1163 : *branch_value = ASTLoweringExpr::translate (expr.get_value_expr ());
234 1163 : 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 1163 : rust_assert (expr.get_pattern () != nullptr);
240 :
241 1163 : match_arm_pattern
242 1163 : = ASTLoweringPattern::translate (*expr.get_pattern ())->clone_pattern ();
243 :
244 : // The match arm corresponding to the if let pattern when it matches.
245 1163 : HIR::MatchArm arm (std::move (match_arm_pattern), expr.get_locus (), nullptr,
246 1163 : {});
247 :
248 1163 : auto crate_num = mappings.crate.get_current_crate ();
249 2326 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
250 1163 : mappings.get_next_hir_id (crate_num),
251 1163 : UNKNOWN_LOCAL_DEFID);
252 :
253 1163 : match_arms.emplace_back (std::move (mapping), std::move (arm),
254 1163 : std::unique_ptr<HIR::Expr> (kase_expr));
255 :
256 : // The default match arm when the if let pattern does not match
257 2326 : Analysis::NodeMapping mapping_default (crate_num, expr.get_node_id (),
258 1163 : mappings.get_next_hir_id (crate_num),
259 1163 : UNKNOWN_LOCAL_DEFID);
260 :
261 1163 : auto match_arm_pattern_wildcard = std::unique_ptr<HIR::WildcardPattern> (
262 1163 : new HIR::WildcardPattern (mapping_default, expr.get_locus ()));
263 :
264 1163 : HIR::MatchArm arm_default (std::move (match_arm_pattern_wildcard),
265 2326 : expr.get_locus (), nullptr, {});
266 :
267 1163 : match_arms.emplace_back (std::move (mapping_default), std::move (arm_default),
268 1163 : std::unique_ptr<HIR::Expr> (kase_else_expr));
269 1163 : }
270 :
271 : void
272 758 : 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 758 : HIR::Expr *branch_value;
287 :
288 758 : std::vector<HIR::MatchCase> match_arms;
289 758 : auto crate_num = mappings.crate.get_current_crate ();
290 1516 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
291 758 : mappings.get_next_hir_id (crate_num),
292 758 : UNKNOWN_LOCAL_DEFID);
293 :
294 758 : HIR::TupleExpr *unit
295 758 : = new HIR::TupleExpr (mapping, {}, {}, {}, expr.get_locus ());
296 :
297 758 : desugar_iflet (expr, &branch_value, unit, match_arms);
298 :
299 758 : translated
300 758 : = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
301 1516 : std::move (match_arms), {}, {}, expr.get_locus ());
302 758 : }
303 :
304 : void
305 405 : 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 405 : HIR::Expr *branch_value;
322 405 : std::vector<HIR::MatchCase> match_arms;
323 :
324 405 : HIR::Expr *kase_else_expr
325 405 : = ASTLoweringExpr::translate (expr.get_else_block ());
326 :
327 405 : desugar_iflet (expr, &branch_value, kase_else_expr, match_arms);
328 :
329 405 : auto crate_num = mappings.crate.get_current_crate ();
330 810 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
331 405 : mappings.get_next_hir_id (crate_num),
332 405 : UNKNOWN_LOCAL_DEFID);
333 :
334 405 : translated
335 405 : = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
336 810 : std::move (match_arms), {}, {}, expr.get_locus ());
337 405 : }
338 :
339 : // rust-ast-lower-struct-field-expr.h
340 :
341 : void
342 9837 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field)
343 : {
344 9837 : HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ());
345 :
346 9837 : auto crate_num = mappings.crate.get_current_crate ();
347 9837 : Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
348 9837 : mappings.get_next_hir_id (crate_num),
349 9837 : UNKNOWN_LOCAL_DEFID);
350 :
351 9837 : translated = new HIR::StructExprFieldIdentifierValue (
352 29511 : mapping, field.get_field_name (), std::unique_ptr<HIR::Expr> (value),
353 19674 : field.get_locus ());
354 9837 : }
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 2371 : ASTLowerStructExprField::visit (AST::StructExprFieldIdentifier &field)
374 : {
375 2371 : auto crate_num = mappings.crate.get_current_crate ();
376 2371 : Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
377 2371 : mappings.get_next_hir_id (crate_num),
378 2371 : UNKNOWN_LOCAL_DEFID);
379 :
380 2371 : translated
381 2371 : = new HIR::StructExprFieldIdentifier (mapping, field.get_field_name (),
382 2371 : field.get_locus ());
383 2371 : }
384 :
385 : // rust-ast-lower-block.h
386 :
387 : void
388 1342 : ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr)
389 : {
390 1342 : HIR::BlockExpr *loop_block
391 1342 : = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated);
392 :
393 1342 : tl::optional<HIR::LoopLabel> loop_label;
394 1342 : if (expr.has_loop_label ())
395 7 : loop_label = lower_loop_label (expr.get_loop_label ());
396 :
397 1342 : HIR::Expr *loop_condition
398 1342 : = ASTLoweringExpr::translate (expr.get_predicate_expr (), &terminated);
399 :
400 1342 : auto crate_num = mappings.crate.get_current_crate ();
401 2684 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
402 1342 : mappings.get_next_hir_id (crate_num),
403 1342 : UNKNOWN_LOCAL_DEFID);
404 :
405 1342 : translated
406 1342 : = new HIR::WhileLoopExpr (mapping,
407 1342 : std::unique_ptr<HIR::Expr> (loop_condition),
408 2684 : std::unique_ptr<HIR::BlockExpr> (loop_block),
409 : expr.get_locus (), std::move (loop_label),
410 2684 : expr.get_outer_attrs ());
411 1342 : }
412 :
413 : void
414 62849 : ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr)
415 : {
416 62849 : HIR::Expr *branch_value
417 62849 : = ASTLoweringExpr::translate (expr.get_scrutinee_expr ());
418 :
419 62849 : std::vector<HIR::MatchCase> match_arms;
420 649298 : for (auto &match_case : expr.get_match_cases ())
421 : {
422 586449 : HIR::Expr *kase_expr
423 586449 : = ASTLoweringExpr::translate (match_case.get_expr ());
424 :
425 586449 : HIR::Expr *kase_guard_expr = nullptr;
426 586449 : if (match_case.get_arm ().has_match_arm_guard ())
427 : {
428 467 : kase_guard_expr = ASTLoweringExpr::translate (
429 : match_case.get_arm ().get_guard_expr ());
430 : }
431 :
432 586449 : std::unique_ptr<HIR::Pattern> match_arm_pattern;
433 :
434 586449 : match_arm_pattern
435 586449 : = ASTLoweringPattern::translate (*match_case.get_arm ().get_pattern ())
436 586449 : ->clone_pattern ();
437 :
438 586449 : HIR::MatchArm arm (std::move (match_arm_pattern), expr.get_locus (),
439 586449 : std::unique_ptr<HIR::Expr> (kase_guard_expr),
440 586449 : match_case.get_arm ().get_outer_attrs ());
441 :
442 586449 : auto crate_num = mappings.crate.get_current_crate ();
443 1172898 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
444 586449 : mappings.get_next_hir_id (crate_num),
445 586449 : UNKNOWN_LOCAL_DEFID);
446 :
447 586449 : match_arms.emplace_back (std::move (mapping), std::move (arm),
448 586449 : std::unique_ptr<HIR::Expr> (kase_expr));
449 586449 : }
450 :
451 62849 : auto crate_num = mappings.crate.get_current_crate ();
452 125698 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
453 62849 : mappings.get_next_hir_id (crate_num),
454 62849 : UNKNOWN_LOCAL_DEFID);
455 :
456 62849 : translated
457 62849 : = new HIR::MatchExpr (mapping, std::unique_ptr<HIR::Expr> (branch_value),
458 62849 : std::move (match_arms), expr.get_inner_attrs (),
459 125698 : expr.get_outer_attrs (), expr.get_locus ());
460 62849 : }
461 :
462 : // rust-ast-lower-expr.h
463 :
464 : void
465 944132 : ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
466 : {
467 944132 : auto crate_num = mappings.crate.get_current_crate ();
468 1888264 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
469 944132 : mappings.get_next_hir_id (crate_num),
470 944132 : UNKNOWN_LOCAL_DEFID);
471 :
472 944132 : if (expr.is_lang_item ())
473 : {
474 39282 : translated = new HIR::PathInExpression (mapping, expr.get_lang_item (),
475 19641 : expr.get_locus ());
476 19641 : return;
477 : }
478 :
479 924491 : auto &segments = expr.get_segments ();
480 :
481 924491 : std::vector<HIR::PathExprSegment> path_segments;
482 924491 : path_segments.reserve (segments.size ());
483 :
484 1991171 : for (auto &s : segments)
485 : {
486 1066680 : path_segments.push_back (lower_path_expr_seg ((s)));
487 :
488 : // insert the mappings for the segment
489 1066680 : HIR::PathExprSegment *lowered_seg = &path_segments.back ();
490 1066680 : mappings.hir.path_expr_segments.insert (lowered_seg);
491 : }
492 :
493 924491 : RawPath<HIR::PathExprSegment> path (std::move (path_segments),
494 924491 : expr.has_opening_scope_resolution ());
495 :
496 924491 : translated
497 924491 : = new HIR::PathInExpression (mapping, std::move (path), expr.get_locus ());
498 924491 : }
499 :
500 : HIR::QualifiedPathType
501 1344 : ASTLoweringBase::lower_qual_path_type (AST::QualifiedPathType &qualified_type)
502 : {
503 1344 : HIR::Type *type = ASTLoweringType::translate (qualified_type.get_type ());
504 1344 : HIR::TypePath *trait
505 1344 : = qualified_type.has_as_clause ()
506 1344 : ? ASTLowerTypePath::translate (qualified_type.get_as_type_path ())
507 : : nullptr;
508 :
509 1344 : auto crate_num = mappings.crate.get_current_crate ();
510 1344 : Analysis::NodeMapping mapping (crate_num, qualified_type.get_node_id (),
511 1344 : mappings.get_next_hir_id (crate_num),
512 1344 : UNKNOWN_LOCAL_DEFID);
513 :
514 1344 : return HIR::QualifiedPathType (mapping, std::unique_ptr<HIR::Type> (type),
515 2688 : std::unique_ptr<HIR::TypePath> (trait),
516 1344 : qualified_type.get_locus ());
517 : }
518 :
519 : void
520 1344 : ASTLowerQualPathInExpression::visit (AST::QualifiedPathInExpression &expr)
521 : {
522 1344 : HIR::QualifiedPathType qual_path_type
523 1344 : = lower_qual_path_type (expr.get_qualified_path_type ());
524 :
525 1344 : auto &segments = expr.get_segments ();
526 :
527 1344 : std::vector<HIR::PathExprSegment> path_segments;
528 1344 : path_segments.reserve (segments.size ());
529 :
530 2689 : for (auto &s : segments)
531 : {
532 1345 : path_segments.push_back (lower_path_expr_seg ((s)));
533 :
534 : // insert the mappings for the segment
535 1345 : HIR::PathExprSegment *lowered_seg = &path_segments.back ();
536 1345 : mappings.hir.path_expr_segments.insert (lowered_seg);
537 : }
538 :
539 1344 : RawPath<HIR::PathExprSegment> hir_path{path_segments,
540 1344 : expr.has_opening_scope_resolution ()};
541 :
542 1344 : auto crate_num = mappings.crate.get_current_crate ();
543 2688 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
544 1344 : mappings.get_next_hir_id (crate_num),
545 1344 : UNKNOWN_LOCAL_DEFID);
546 :
547 1344 : translated = new HIR::QualifiedPathInExpression (mapping, qual_path_type,
548 : std::move (hir_path),
549 : expr.get_locus (),
550 2688 : expr.get_outer_attrs ());
551 1344 : }
552 :
553 : ClosureParam
554 4538 : ASTLoweringBase::lower_closure_param (AST::ClosureParam ¶m)
555 : {
556 4538 : HIR::Pattern *param_pattern
557 4538 : = ASTLoweringPattern::translate (param.get_pattern ());
558 :
559 4538 : HIR::Type *param_type = param.has_type_given ()
560 4538 : ? ASTLoweringType::translate (param.get_type ())
561 : : nullptr;
562 :
563 9076 : return HIR::ClosureParam (std::unique_ptr<HIR::Pattern> (param_pattern),
564 : param.get_locus (),
565 4538 : param.has_type_given ()
566 9076 : ? std::unique_ptr<HIR::Type> (param_type)
567 : : nullptr,
568 13614 : param.get_outer_attrs ());
569 : }
570 :
571 : } // namespace HIR
572 : } // namespace Rust
|