mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
fix: bug in extract_function: should not import ControlFlow in some cases
This commit is contained in:
parent
e402c494b7
commit
05e8b926e6
1 changed files with 27 additions and 1 deletions
|
@ -147,7 +147,12 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
||||||
_ => format_function(ctx, module, &fun, old_indent, new_indent),
|
_ => format_function(ctx, module, &fun, old_indent, new_indent),
|
||||||
};
|
};
|
||||||
|
|
||||||
if fn_def.contains("ControlFlow") {
|
// There are external control flows
|
||||||
|
if fun
|
||||||
|
.control_flow
|
||||||
|
.kind
|
||||||
|
.is_some_and(|kind| matches!(kind, FlowKind::Break(_, _) | FlowKind::Continue(_)))
|
||||||
|
{
|
||||||
let scope = match scope {
|
let scope = match scope {
|
||||||
ImportScope::File(it) => ImportScope::File(builder.make_mut(it)),
|
ImportScope::File(it) => ImportScope::File(builder.make_mut(it)),
|
||||||
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
|
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
|
||||||
|
@ -4968,6 +4973,27 @@ pub fn testfn(arg: &mut Foo) {
|
||||||
fn $0fun_name(arg: &mut Foo) {
|
fn $0fun_name(arg: &mut Foo) {
|
||||||
arg.field = 8;
|
arg.field = 8;
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn does_not_import_control_flow() {
|
||||||
|
check_assist(
|
||||||
|
extract_function,
|
||||||
|
r#"
|
||||||
|
//- minicore: try
|
||||||
|
fn func() {
|
||||||
|
$0let cf = "I'm ControlFlow";$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn func() {
|
||||||
|
fun_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn $0fun_name() {
|
||||||
|
let cf = "I'm ControlFlow";
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue