mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
include for
in convert to guarded return assist
This commit is contained in:
parent
9d8889cdfc
commit
721e79035d
1 changed files with 28 additions and 2 deletions
|
@ -8,7 +8,7 @@ use syntax::{
|
||||||
make,
|
make,
|
||||||
},
|
},
|
||||||
ted, AstNode,
|
ted, AstNode,
|
||||||
SyntaxKind::{FN, LOOP_EXPR, WHILE_EXPR, WHITESPACE},
|
SyntaxKind::{FN, FOR_EXPR, LOOP_EXPR, WHILE_EXPR, WHITESPACE},
|
||||||
T,
|
T,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
|
||||||
let parent_container = parent_block.syntax().parent()?;
|
let parent_container = parent_block.syntax().parent()?;
|
||||||
|
|
||||||
let early_expression: ast::Expr = match parent_container.kind() {
|
let early_expression: ast::Expr = match parent_container.kind() {
|
||||||
WHILE_EXPR | LOOP_EXPR => make::expr_continue(None),
|
WHILE_EXPR | LOOP_EXPR | FOR_EXPR => make::expr_continue(None),
|
||||||
FN => make::expr_return(None),
|
FN => make::expr_return(None),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
@ -426,6 +426,32 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn convert_let_inside_for() {
|
||||||
|
check_assist(
|
||||||
|
convert_to_guarded_return,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
for n in ns {
|
||||||
|
if$0 let Some(n) = n {
|
||||||
|
foo(n);
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
for n in ns {
|
||||||
|
let Some(n) = n else { continue };
|
||||||
|
foo(n);
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_arbitrary_if_let_patterns() {
|
fn convert_arbitrary_if_let_patterns() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Reference in a new issue