File tree 1 file changed +35
-6
lines changed
crates/ide-assists/src/handlers
1 file changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -311,12 +311,16 @@ fn inline(
311
311
} else {
312
312
fn_body. clone_for_update ( )
313
313
} ;
314
- if let Some ( t) = body. syntax ( ) . ancestors ( ) . find_map ( ast:: Impl :: cast) . and_then ( |i| i. self_ty ( ) ) {
315
- body. syntax ( )
316
- . descendants_with_tokens ( )
317
- . filter_map ( NodeOrToken :: into_token)
318
- . filter ( |tok| tok. kind ( ) == SyntaxKind :: SELF_TYPE_KW )
319
- . for_each ( |tok| ted:: replace ( tok, t. syntax ( ) ) ) ;
314
+ if let Some ( imp) = body. syntax ( ) . ancestors ( ) . find_map ( ast:: Impl :: cast) {
315
+ if !node. syntax ( ) . ancestors ( ) . any ( |anc| & anc == imp. syntax ( ) ) {
316
+ if let Some ( t) = imp. self_ty ( ) {
317
+ body. syntax ( )
318
+ . descendants_with_tokens ( )
319
+ . filter_map ( NodeOrToken :: into_token)
320
+ . filter ( |tok| tok. kind ( ) == SyntaxKind :: SELF_TYPE_KW )
321
+ . for_each ( |tok| ted:: replace ( tok, t. syntax ( ) ) ) ;
322
+ }
323
+ }
320
324
}
321
325
let usages_for_locals = |local| {
322
326
Definition :: Local ( local)
@@ -1221,6 +1225,31 @@ impl A {
1221
1225
fn main() {
1222
1226
A(114514);
1223
1227
}
1228
+ "# ,
1229
+ )
1230
+ }
1231
+
1232
+ #[ test]
1233
+ fn inline_call_with_self_type_but_within_same_impl ( ) {
1234
+ check_assist (
1235
+ inline_call,
1236
+ r#"
1237
+ struct A(u32);
1238
+ impl A {
1239
+ fn f() -> Self { Self(1919810) }
1240
+ fn main() {
1241
+ Self::f$0();
1242
+ }
1243
+ }
1244
+ "# ,
1245
+ r#"
1246
+ struct A(u32);
1247
+ impl A {
1248
+ fn f() -> Self { Self(1919810) }
1249
+ fn main() {
1250
+ Self(1919810);
1251
+ }
1252
+ }
1224
1253
"# ,
1225
1254
)
1226
1255
}
You can’t perform that action at this time.
0 commit comments