]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_db/src/helpers.rs
Merge #11455
[rust.git] / crates / ide_db / src / helpers.rs
index 2d3d64093385c3ac2525ba66f80cf8a23530817b..c355016c5dfd054dac27f949f37eeb4a6882bab6 100644 (file)
@@ -82,6 +82,9 @@ pub fn pick_best_token(
 ) -> Option<SyntaxToken> {
     tokens.max_by_key(move |t| f(t.kind()))
 }
+pub fn pick_token<T: AstToken>(mut tokens: TokenAtOffset<SyntaxToken>) -> Option<T> {
+    tokens.find_map(T::cast)
+}
 
 /// Converts the mod path struct into its ast representation.
 pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
@@ -226,6 +229,7 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
         | ast::Expr::TryExpr(_)
         | ast::Expr::TupleExpr(_)
         | ast::Expr::WhileExpr(_)
+        | ast::Expr::LetExpr(_)
         | ast::Expr::YieldExpr(_) => cb(expr),
     }
 }