aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-10 19:01:20 +0100
committerGitHub <[email protected]>2020-05-10 19:01:20 +0100
commitbfb40a698dab10adcd1284ce4c7a2a10f36ba4e7 (patch)
tree35c576e09fb73b3114d3e1e71bb9a3963b17ec35 /crates/ra_syntax
parent74e72e9afa58e5ba1e5a693211fc91a128e1b415 (diff)
parent0f1d39133c28f28f57ba17aa795c1e6ca177cbff (diff)
Merge #4396
4396: Improve panic message for ast_from_text r=jonas-schievink a=edwin0cheng Related: #4368 Co-authored-by: Edwin Cheng <[email protected]>
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();