Skip to content

Commit 8cc9772

Browse files
committed
Rust: borrow Ast nodes
1 parent 7f0430b commit 8cc9772

File tree

4 files changed

+907
-907
lines changed

4 files changed

+907
-907
lines changed

rust/ast-generator/src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ use ra_ap_syntax::ast::{{
452452
use ra_ap_syntax::{{ast, AstNode}};
453453
454454
impl Translator<'_> {{
455-
fn emit_else_branch(&mut self, node: ast::ElseBranch) -> Label<generated::Expr> {{
455+
fn emit_else_branch(&mut self, node: &ast::ElseBranch) -> Label<generated::Expr> {{
456456
match node {{
457-
ast::ElseBranch::IfExpr(inner) => self.emit_if_expr(inner).into(),
458-
ast::ElseBranch::Block(inner) => self.emit_block_expr(inner).into(),
457+
ast::ElseBranch::IfExpr(ref inner) => self.emit_if_expr(inner).into(),
458+
ast::ElseBranch::Block(ref inner) => self.emit_block_expr(inner).into(),
459459
}}
460460
}}\n"
461461
)?;
@@ -465,7 +465,7 @@ impl Translator<'_> {{
465465

466466
writeln!(
467467
buf,
468-
" pub(crate) fn emit_{}(&mut self, node: ast::{}) -> Label<generated::{}> {{",
468+
" pub(crate) fn emit_{}(&mut self, node: &ast::{}) -> Label<generated::{}> {{",
469469
to_lower_snake_case(type_name),
470470
type_name,
471471
class_name
@@ -474,7 +474,7 @@ impl Translator<'_> {{
474474
for variant in &node.variants {
475475
writeln!(
476476
buf,
477-
" ast::{}::{}(inner) => self.emit_{}(inner).into(),",
477+
" ast::{}::{}(ref inner) => self.emit_{}(inner).into(),",
478478
type_name,
479479
variant,
480480
to_lower_snake_case(variant)
@@ -496,7 +496,7 @@ impl Translator<'_> {{
496496

497497
writeln!(
498498
buf,
499-
" pub(crate) fn emit_{}(&mut self, node: ast::{}) -> Label<generated::{}> {{",
499+
" pub(crate) fn emit_{}(&mut self, node: &ast::{}) -> Label<generated::{}> {{",
500500
to_lower_snake_case(type_name),
501501
type_name,
502502
class_name
@@ -525,15 +525,15 @@ impl Translator<'_> {{
525525
} else if field.is_many {
526526
writeln!(
527527
buf,
528-
" let {} = node.{}().map(|x| self.emit_{}(x)).collect();",
528+
" let {} = node.{}().map(|x| self.emit_{}(&x)).collect();",
529529
class_field_name,
530530
struct_field_name,
531531
to_lower_snake_case(type_name)
532532
)?;
533533
} else {
534534
writeln!(
535535
buf,
536-
" let {} = node.{}().map(|x| self.emit_{}(x));",
536+
" let {} = node.{}().map(|x| self.emit_{}(&x));",
537537
class_field_name,
538538
struct_field_name,
539539
to_lower_snake_case(type_name)
@@ -555,15 +555,15 @@ impl Translator<'_> {{
555555
writeln!(buf, " {},", class_field_name)?;
556556
}
557557
writeln!(buf, " }});")?;
558-
writeln!(buf, " self.emit_location(label, &node);")?;
558+
writeln!(buf, " self.emit_location(label, node);")?;
559559
writeln!(
560560
buf,
561561
" emit_detached!({}, self, node, label);",
562562
class_name
563563
)?;
564564
writeln!(
565565
buf,
566-
" self.emit_tokens(&node, label.into(), node.syntax().children_with_tokens());"
566+
" self.emit_tokens(node, label.into(), node.syntax().children_with_tokens());"
567567
)?;
568568
writeln!(buf, " label")?;
569569

rust/extractor/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Extractor<'_> {
6565
no_location,
6666
);
6767
}
68-
translator.emit_source_file(ast);
68+
translator.emit_source_file(&ast);
6969
translator.trap.commit().unwrap_or_else(|err| {
7070
log::error!(
7171
"Failed to write trap file for: {}: {}",

rust/extractor/src/translate/base.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,32 @@ use ra_ap_syntax::{
2727
#[macro_export]
2828
macro_rules! emit_detached {
2929
(MacroCall, $self:ident, $node:ident, $label:ident) => {
30-
$self.extract_macro_call_expanded(&$node, $label);
30+
$self.extract_macro_call_expanded($node, $label);
3131
};
3232
(Function, $self:ident, $node:ident, $label:ident) => {
33-
$self.extract_canonical_origin(&$node, $label.into());
33+
$self.extract_canonical_origin($node, $label.into());
3434
};
3535
(Trait, $self:ident, $node:ident, $label:ident) => {
36-
$self.extract_canonical_origin(&$node, $label.into());
36+
$self.extract_canonical_origin($node, $label.into());
3737
};
3838
(Struct, $self:ident, $node:ident, $label:ident) => {
39-
$self.extract_canonical_origin(&$node, $label.into());
39+
$self.extract_canonical_origin($node, $label.into());
4040
};
4141
(Enum, $self:ident, $node:ident, $label:ident) => {
42-
$self.extract_canonical_origin(&$node, $label.into());
42+
$self.extract_canonical_origin($node, $label.into());
4343
};
4444
(Union, $self:ident, $node:ident, $label:ident) => {
45-
$self.extract_canonical_origin(&$node, $label.into());
45+
$self.extract_canonical_origin($node, $label.into());
4646
};
4747
(Module, $self:ident, $node:ident, $label:ident) => {
48-
$self.extract_canonical_origin(&$node, $label.into());
48+
$self.extract_canonical_origin($node, $label.into());
4949
};
5050
// TODO canonical origin of other items
5151
(Path, $self:ident, $node:ident, $label:ident) => {
52-
$self.extract_canonical_destination(&$node, $label);
52+
$self.extract_canonical_destination($node, $label);
5353
};
5454
(MethodCallExpr, $self:ident, $node:ident, $label:ident) => {
55-
$self.extract_method_canonical_destination(&$node, $label);
55+
$self.extract_method_canonical_destination($node, $label);
5656
};
5757
($($_:tt)*) => {};
5858
}
@@ -252,20 +252,20 @@ impl<'a> Translator<'a> {
252252
) -> Option<Label<generated::AstNode>> {
253253
match expand_to {
254254
ra_ap_hir_expand::ExpandTo::Statements => {
255-
ast::MacroStmts::cast(expanded).map(|x| self.emit_macro_stmts(x).into())
255+
ast::MacroStmts::cast(expanded).map(|x| self.emit_macro_stmts(&x).into())
256256
}
257257
ra_ap_hir_expand::ExpandTo::Items => {
258-
ast::MacroItems::cast(expanded).map(|x| self.emit_macro_items(x).into())
258+
ast::MacroItems::cast(expanded).map(|x| self.emit_macro_items(&x).into())
259259
}
260260

261261
ra_ap_hir_expand::ExpandTo::Pattern => {
262-
ast::Pat::cast(expanded).map(|x| self.emit_pat(x).into())
262+
ast::Pat::cast(expanded).map(|x| self.emit_pat(&x).into())
263263
}
264264
ra_ap_hir_expand::ExpandTo::Type => {
265-
ast::Type::cast(expanded).map(|x| self.emit_type(x).into())
265+
ast::Type::cast(expanded).map(|x| self.emit_type(&x).into())
266266
}
267267
ra_ap_hir_expand::ExpandTo::Expr => {
268-
ast::Expr::cast(expanded).map(|x| self.emit_expr(x).into())
268+
ast::Expr::cast(expanded).map(|x| self.emit_expr(&x).into())
269269
}
270270
}
271271
}

0 commit comments

Comments
 (0)