Skip to content

Commit bfb40a6

Browse files
Merge #4396
4396: Improve panic message for ast_from_text r=jonas-schievink a=edwin0cheng Related: #4368 Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2 parents 74e72e9 + 0f1d391 commit bfb40a6

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)