Skip to content

Commit fa8acfa

Browse files
committed
internal: Add some pattern constructors to SyntaxFactory
1 parent 396b56f commit fa8acfa

File tree

1 file changed

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

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ impl SyntaxFactory {
127127
ast
128128
}
129129

130+
pub fn wildcard_pat(&self) -> ast::WildcardPat {
131+
make::wildcard_pat().clone_for_update()
132+
}
133+
134+
pub fn literal_pat(&self, text: &str) -> ast::LiteralPat {
135+
make::literal_pat(text).clone_for_update()
136+
}
137+
138+
pub fn tuple_struct_pat(
139+
&self,
140+
path: ast::Path,
141+
fields: impl IntoIterator<Item = ast::Pat>,
142+
) -> ast::TupleStructPat {
143+
let (fields, input) = iterator_input(fields);
144+
let ast = make::tuple_struct_pat(path.clone(), fields).clone_for_update();
145+
146+
if let Some(mut mapping) = self.mappings() {
147+
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
148+
builder.map_node(path.syntax().clone(), ast.path().unwrap().syntax().clone());
149+
builder.map_children(input.into_iter(), ast.fields().map(|it| it.syntax().clone()));
150+
builder.finish(&mut mapping);
151+
}
152+
153+
ast
154+
}
155+
130156
pub fn block_expr(
131157
&self,
132158
statements: impl IntoIterator<Item = ast::Stmt>,

0 commit comments

Comments
 (0)