aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/make.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r--crates/ra_syntax/src/ast/make.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 7b17fef49..d0e960fb4 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -13,6 +13,10 @@ pub fn name_ref(text: &str) -> ast::NameRef {
13 ast_from_text(&format!("fn f() {{ {}; }}", text)) 13 ast_from_text(&format!("fn f() {{ {}; }}", text))
14} 14}
15 15
16pub fn type_ref(text: &str) -> ast::TypeRef {
17 ast_from_text(&format!("impl {} for D {{}};", text))
18}
19
16pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { 20pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
17 ast_from_text(&format!("use {};", name_ref)) 21 ast_from_text(&format!("use {};", name_ref))
18} 22}
@@ -300,7 +304,12 @@ pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef {
300 304
301fn ast_from_text<N: AstNode>(text: &str) -> N { 305fn ast_from_text<N: AstNode>(text: &str) -> N {
302 let parse = SourceFile::parse(text); 306 let parse = SourceFile::parse(text);
303 let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); 307 let node = match parse.tree().syntax().descendants().find_map(N::cast) {
308 Some(it) => it,
309 None => {
310 panic!("Failed to make ast node `{}` from text {}", std::any::type_name::<N>(), text)
311 }
312 };
304 let node = node.syntax().clone(); 313 let node = node.syntax().clone();
305 let node = unroot(node); 314 let node = unroot(node);
306 let node = N::cast(node).unwrap(); 315 let node = N::cast(node).unwrap();