@@ -13,7 +13,7 @@ use ide_db::{
13
13
use itertools:: { izip, Itertools } ;
14
14
use syntax:: {
15
15
ast:: { self , edit_in_place:: Indent , HasArgList , PathExpr } ,
16
- ted, AstNode ,
16
+ ted, AstNode , SyntaxKind ,
17
17
} ;
18
18
19
19
use crate :: {
@@ -311,6 +311,16 @@ fn inline(
311
311
} else {
312
312
fn_body. clone_for_update ( )
313
313
} ;
314
+ // TODO: use if-let chains - https://github.com/rust-lang/rust/pull/94927
315
+ if let Some ( i) = body. syntax ( ) . ancestors ( ) . find_map ( ast:: Impl :: cast) {
316
+ if let Some ( st) = i. self_ty ( ) {
317
+ for tok in body. syntax ( ) . descendants_with_tokens ( ) . filter_map ( |t| t. into_token ( ) ) {
318
+ if tok. kind ( ) == SyntaxKind :: SELF_TYPE_KW {
319
+ ted:: replace ( tok, st. syntax ( ) ) ;
320
+ }
321
+ }
322
+ }
323
+ }
314
324
let usages_for_locals = |local| {
315
325
Definition :: Local ( local)
316
326
. usages ( sema)
@@ -345,6 +355,7 @@ fn inline(
345
355
}
346
356
} )
347
357
. collect ( ) ;
358
+
348
359
if function. self_param ( sema. db ) . is_some ( ) {
349
360
let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) ;
350
361
if let Some ( self_local) = params[ 0 ] . 2 . as_local ( sema. db ) {
@@ -1188,6 +1199,31 @@ fn bar() -> u32 {
1188
1199
x
1189
1200
}
1190
1201
}
1202
+ "# ,
1203
+ )
1204
+ }
1205
+
1206
+ #[ test]
1207
+ fn inline_call_with_self_type ( ) {
1208
+ check_assist (
1209
+ inline_call,
1210
+ r#"
1211
+ struct A(u32);
1212
+ impl A {
1213
+ fn f() -> Self { Self(114514) }
1214
+ }
1215
+ fn main() {
1216
+ A::f$0();
1217
+ }
1218
+ "# ,
1219
+ r#"
1220
+ struct A(u32);
1221
+ impl A {
1222
+ fn f() -> Self { Self(114514) }
1223
+ }
1224
+ fn main() {
1225
+ A(114514);
1226
+ }
1191
1227
"# ,
1192
1228
)
1193
1229
}
0 commit comments