Skip to content

Commit 3dcda33

Browse files
committed
minor: Add item_const constructor to SyntaxFactory
1 parent a18e38e commit 3dcda33

File tree

1 file changed

+27
-0
lines changed
  • src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory

1 file changed

+27
-0
lines changed

src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,33 @@ impl SyntaxFactory {
188188
ast
189189
}
190190

191+
pub fn item_const(
192+
&self,
193+
visibility: Option<ast::Visibility>,
194+
name: ast::Name,
195+
ty: ast::Type,
196+
expr: ast::Expr,
197+
) -> ast::Const {
198+
let ast = make::item_const(visibility.clone(), name.clone(), ty.clone(), expr.clone())
199+
.clone_for_update();
200+
201+
if let Some(mut mapping) = self.mappings() {
202+
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
203+
if let Some(visibility) = visibility {
204+
builder.map_node(
205+
visibility.syntax().clone(),
206+
ast.visibility().unwrap().syntax().clone(),
207+
);
208+
}
209+
builder.map_node(name.syntax().clone(), ast.name().unwrap().syntax().clone());
210+
builder.map_node(ty.syntax().clone(), ast.ty().unwrap().syntax().clone());
211+
builder.map_node(expr.syntax().clone(), ast.body().unwrap().syntax().clone());
212+
builder.finish(&mut mapping);
213+
}
214+
215+
ast
216+
}
217+
191218
pub fn turbofish_generic_arg_list(
192219
&self,
193220
args: impl IntoIterator<Item = ast::GenericArg> + Clone,

0 commit comments

Comments
 (0)