Assist: replace unwrap with match

This commit is contained in:
Unreal Hoang 2020-03-26 18:16:10 +09:00
parent 785eb32f49
commit d9df0f43ac
No known key found for this signature in database
GPG key ID: F66217BDC6F37CFA
5 changed files with 230 additions and 0 deletions

View file

@ -250,6 +250,10 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
.unwrap_or_else(|| panic!("unhandled token: {:?}", kind))
}
pub fn unreachable_macro_call() -> ast::MacroCall {
ast_from_text(&format!("unreachable!()"))
}
fn ast_from_text<N: AstNode>(text: &str) -> N {
let parse = SourceFile::parse(text);
let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap();