3732: Assist: replace unwrap with match r=matklad a=unrealhoang

attempt on #3669

Co-authored-by: Unreal Hoang <unrealhoang@gmail.com>
This commit is contained in:
bors[bot] 2020-03-26 15:38:03 +00:00 committed by GitHub
commit 20c110e57f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();