@@ -2,11 +2,17 @@ use std::{hash::BuildHasherDefault, iter};
2
2
3
3
use ast:: make;
4
4
use either:: Either ;
5
- use hir:: { HirDisplay , InFile , Local , Semantics , TypeInfo } ;
5
+ use hir:: { HirDisplay , InFile , Local , ModuleDef , Semantics , TypeInfo } ;
6
6
use ide_db:: {
7
7
defs:: { Definition , NameRefClass } ,
8
- helpers:: insert_use:: { insert_use, ImportScope } ,
9
- helpers:: node_ext:: { preorder_expr, walk_expr, walk_pat, walk_patterns_in_expr} ,
8
+ helpers:: {
9
+ insert_use:: { insert_use, ImportScope } ,
10
+ FamousDefs ,
11
+ } ,
12
+ helpers:: {
13
+ mod_path_to_ast,
14
+ node_ext:: { preorder_expr, walk_expr, walk_pat, walk_patterns_in_expr} ,
15
+ } ,
10
16
search:: { FileReference , ReferenceCategory , SearchScope } ,
11
17
RootDatabase ,
12
18
} ;
@@ -129,11 +135,20 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option
129
135
ImportScope :: Block ( it) => ImportScope :: Block ( builder. make_mut ( it) ) ,
130
136
} ;
131
137
132
- insert_use (
133
- & scope,
134
- make:: path_from_text ( "std::ops::ControlFlow" ) ,
135
- & ctx. config . insert_use ,
136
- ) ;
138
+ let control_flow_enum =
139
+ FamousDefs ( & ctx. sema , Some ( module. krate ( ) ) ) . core_ops_ControlFlow ( ) ;
140
+
141
+ if let Some ( control_flow_enum) = control_flow_enum {
142
+ let mod_path = module. find_use_path_prefixed (
143
+ ctx. sema . db ,
144
+ ModuleDef :: from ( control_flow_enum) ,
145
+ ctx. config . insert_use . prefix_kind ,
146
+ ) ;
147
+
148
+ if let Some ( mod_path) = mod_path {
149
+ insert_use ( & scope, mod_path_to_ast ( & mod_path) , & ctx. config . insert_use ) ;
150
+ }
151
+ }
137
152
}
138
153
139
154
match ctx. config . snippet_cap {
@@ -3304,6 +3319,7 @@ fn foo() {
3304
3319
check_assist (
3305
3320
extract_function,
3306
3321
r#"
3322
+ //- minicore: try
3307
3323
fn foo() {
3308
3324
loop {
3309
3325
let mut n = 1;
@@ -3315,7 +3331,7 @@ fn foo() {
3315
3331
}
3316
3332
"# ,
3317
3333
r#"
3318
- use std ::ops::ControlFlow;
3334
+ use core ::ops::ControlFlow;
3319
3335
3320
3336
fn foo() {
3321
3337
loop {
@@ -3342,6 +3358,7 @@ fn $0fun_name(n: &mut i32) -> ControlFlow<()> {
3342
3358
check_assist (
3343
3359
extract_function,
3344
3360
r#"
3361
+ //- minicore: try
3345
3362
fn foo() {
3346
3363
loop {
3347
3364
let mut n = 1;
@@ -3354,7 +3371,7 @@ fn foo() {
3354
3371
}
3355
3372
"# ,
3356
3373
r#"
3357
- use std ::ops::ControlFlow;
3374
+ use core ::ops::ControlFlow;
3358
3375
3359
3376
fn foo() {
3360
3377
loop {
0 commit comments