aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-05-09 20:46:12 +0100
committerEdwin Cheng <[email protected]>2020-05-09 20:46:12 +0100
commit0f1d39133c28f28f57ba17aa795c1e6ca177cbff (patch)
treef6335141c8752c6badb5b8fda87a958339423e50 /crates/ra_syntax
parent8295a9340c1fbda805497035054ead0b10c0d88e (diff)
Improve panic message for ast_from_text
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/make.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 7b17fef49..12c5228f5 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -300,7 +300,12 @@ pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef {
300 300
301fn ast_from_text<N: AstNode>(text: &str) -> N { 301fn ast_from_text<N: AstNode>(text: &str) -> N {
302 let parse = SourceFile::parse(text); 302 let parse = SourceFile::parse(text);
303 let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); 303 let node = match parse.tree().syntax().descendants().find_map(N::cast) {
304 Some(it) => it,
305 None => {
306 panic!("Failed to make ast node `{}` from text {}", std::any::type_name::<N>(), text)
307 }
308 };
304 let node = node.syntax().clone(); 309 let node = node.syntax().clone();
305 let node = unroot(node); 310 let node = unroot(node);
306 let node = N::cast(node).unwrap(); 311 let node = N::cast(node).unwrap();