aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/introduce_variable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/introduce_variable.rs')
-rw-r--r--crates/ra_assists/src/introduce_variable.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs
index 95c18d0e3..470ffe120 100644
--- a/crates/ra_assists/src/introduce_variable.rs
+++ b/crates/ra_assists/src/introduce_variable.rs
@@ -3,7 +3,8 @@ use hir::db::HirDatabase;
3use ra_syntax::{ 3use ra_syntax::{
4 ast::{self, AstNode}, 4 ast::{self, AstNode},
5 SyntaxKind::{ 5 SyntaxKind::{
6 BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, 6 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
7 WHITESPACE,
7 }, 8 },
8 SyntaxNode, TextUnit, 9 SyntaxNode, TextUnit,
9}; 10};
@@ -80,10 +81,12 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
80/// In general that's true for any expression, but in some cases that would produce invalid code. 81/// In general that's true for any expression, but in some cases that would produce invalid code.
81fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> { 82fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
82 match node.kind() { 83 match node.kind() {
83 PATH_EXPR => None, 84 PATH_EXPR | LOOP_EXPR => None,
84 BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()), 85 BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()),
85 RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), 86 RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
86 LOOP_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), 87 BLOCK_EXPR => {
88 ast::BlockExpr::cast(node).filter(|it| it.is_standalone()).map(ast::Expr::from)
89 }
87 _ => ast::Expr::cast(node), 90 _ => ast::Expr::cast(node),
88 } 91 }
89} 92}