@@ -13,7 +13,7 @@ use ide_db::{
1313use itertools:: { izip, Itertools } ;
1414use syntax:: {
1515 ast:: { self , edit_in_place:: Indent , HasArgList , PathExpr } ,
16- ted, AstNode ,
16+ ted, AstNode , SyntaxKind ,
1717} ;
1818
1919use crate :: {
@@ -311,6 +311,16 @@ fn inline(
311311 } else {
312312 fn_body. clone_for_update ( )
313313 } ;
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+ }
314324 let usages_for_locals = |local| {
315325 Definition :: Local ( local)
316326 . usages ( sema)
@@ -345,6 +355,7 @@ fn inline(
345355 }
346356 } )
347357 . collect ( ) ;
358+
348359 if function. self_param ( sema. db ) . is_some ( ) {
349360 let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) ;
350361 if let Some ( self_local) = params[ 0 ] . 2 . as_local ( sema. db ) {
@@ -1188,6 +1199,31 @@ fn bar() -> u32 {
11881199 x
11891200 }
11901201}
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+ }
11911227"# ,
11921228 )
11931229 }
0 commit comments