Skip to content

Commit 0f1d391

Browse files
committed
Improve panic message for ast_from_text
1 parent 8295a93 commit 0f1d391

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/ra_syntax/src/ast/make.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,12 @@ pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef {
300300

301301
fn ast_from_text<N: AstNode>(text: &str) -> N {
302302
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+
};
304309
let node = node.syntax().clone();
305310
let node = unroot(node);
306311
let node = N::cast(node).unwrap();

0 commit comments

Comments
 (0)