Skip to content

Commit ee892ad

Browse files
committed
Change tabstop to self_ty
1 parent f4db374 commit ee892ad

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_blanket_trait_impl.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use syntax::{
4242
// }
4343
// }
4444
//
45-
// $0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
45+
// impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
4646
// where
4747
// Self::Owned: Default,
4848
// {
@@ -128,7 +128,9 @@ pub(crate) fn generate_blanket_trait_impl(
128128
);
129129

130130
if let Some(cap) = ctx.config.snippet_cap {
131-
builder.add_tabstop_before_token(cap, impl_.impl_token().unwrap());
131+
if let Some(self_ty) = impl_.self_ty() {
132+
builder.add_tabstop_before(cap, self_ty);
133+
}
132134
}
133135

134136
builder.add_file_edits(ctx.vfs_file_id(), edit);
@@ -314,7 +316,7 @@ where
314316
}
315317
}
316318
317-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
319+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
318320
where
319321
Self::Owned: Default,
320322
{
@@ -344,7 +346,7 @@ trait Foo: Iterator + Sized {
344346
}
345347
}
346348
347-
$0impl<I: Iterator> Foo for I {}
349+
impl<I: Iterator> Foo for $0I {}
348350
"#,
349351
);
350352

@@ -360,7 +362,7 @@ trait Foo: Iterator {
360362
fn foo(self) -> Self::Item;
361363
}
362364
363-
$0impl<I: Iterator> Foo for I {
365+
impl<I: Iterator> Foo for $0I {
364366
fn foo(self) -> Self::Item {
365367
todo!()
366368
}
@@ -380,7 +382,7 @@ trait Foo {
380382
fn foo(&self) -> Self;
381383
}
382384
383-
$0impl<T> Foo for T {
385+
impl<T> Foo for $0T {
384386
fn foo(&self) -> Self {
385387
todo!()
386388
}
@@ -403,7 +405,7 @@ trait Foo: Iterator {
403405
fn foo(&self) -> Self::Item;
404406
}
405407
406-
$0impl<I: Iterator + ?Sized> Foo for I {
408+
impl<I: Iterator + ?Sized> Foo for $0I {
407409
fn foo(&self) -> Self::Item {
408410
todo!()
409411
}
@@ -426,7 +428,7 @@ trait Foo: Iterator {
426428
fn each(self) where Self: Sized;
427429
}
428430
429-
$0impl<I: Iterator + ?Sized> Foo for I {
431+
impl<I: Iterator + ?Sized> Foo for $0I {
430432
fn foo(&self) -> Self::Item {
431433
todo!()
432434
}
@@ -453,7 +455,7 @@ trait Foo: Iterator {
453455
fn each(&self) -> Self where Self: Sized;
454456
}
455457
456-
$0impl<I: Iterator + ?Sized> Foo for I {
458+
impl<I: Iterator + ?Sized> Foo for $0I {
457459
fn foo(&self) -> Self::Item {
458460
todo!()
459461
}
@@ -497,7 +499,7 @@ mod foo {
497499
}
498500
}
499501
500-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
502+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
501503
where
502504
Self::Owned: Default,
503505
{
@@ -539,7 +541,7 @@ mod foo {
539541
}
540542
}
541543
542-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
544+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
543545
where
544546
Self::Owned: Default,
545547
Self: Send,
@@ -585,7 +587,7 @@ mod foo {
585587
}
586588
}
587589
588-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
590+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
589591
where
590592
Self::Owned: Default,
591593
Self: Send,
@@ -621,7 +623,7 @@ mod foo {
621623
}
622624
}
623625
624-
$0impl<T: ?Sized> Foo for T {
626+
impl<T: ?Sized> Foo for $0T {
625627
fn foo(&self) -> i32 {
626628
todo!()
627629
}
@@ -655,7 +657,7 @@ mod foo {
655657
}
656658
}
657659
658-
$0impl<T: ?Sized> Foo for T {
660+
impl<T: ?Sized> Foo for $0T {
659661
fn foo(&self) -> i32 {
660662
todo!()
661663
}
@@ -693,7 +695,7 @@ mod foo {
693695
}
694696
695697
#[cfg(test)]
696-
$0impl<T: ?Sized> Foo for T {
698+
impl<T: ?Sized> Foo for $0T {
697699
fn foo(&self) -> i32 {
698700
todo!()
699701
}
@@ -736,7 +738,7 @@ where
736738
}
737739
}
738740
739-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
741+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
740742
where
741743
Self::Owned: Default,
742744
{
@@ -780,7 +782,7 @@ where
780782
}
781783
}
782784
783-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
785+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
784786
where
785787
Self::Owned: Default,
786788
{
@@ -826,7 +828,7 @@ where
826828
}
827829
}
828830
829-
$0impl<T: Send, This: ?Sized> Foo<T> for This
831+
impl<T: Send, This: ?Sized> Foo<T> for $0This
830832
where
831833
Self: ToOwned,
832834
Self::Owned: Default,
@@ -865,7 +867,7 @@ trait Foo<T: Send> {
865867
}
866868
}
867869
868-
$0impl<T: Send, This: ?Sized> Foo<T> for This {
870+
impl<T: Send, This: ?Sized> Foo<T> for $0This {
869871
fn foo(&self, x: Self::X) -> T {
870872
todo!()
871873
}
@@ -900,7 +902,7 @@ trait Foo {
900902
}
901903
}
902904
903-
$0impl<T: ?Sized> Foo for T {
905+
impl<T: ?Sized> Foo for $0T {
904906
fn foo(&self, x: Self::X) -> i32 {
905907
todo!()
906908
}
@@ -934,7 +936,7 @@ trait Foo {
934936
}
935937
936938
#[cfg(test)]
937-
$0impl<T: ?Sized> Foo for T {
939+
impl<T: ?Sized> Foo for $0T {
938940
fn foo(&self, x: i32) -> i32 {
939941
todo!()
940942
}
@@ -968,7 +970,7 @@ trait Foo {
968970
}
969971
970972
#[cfg(test)]
971-
$0impl<T: ?Sized> Foo for T {
973+
impl<T: ?Sized> Foo for $0T {
972974
#[cfg(test)]
973975
fn foo(&self, x: i32) -> i32 {
974976
todo!()
@@ -988,7 +990,7 @@ trait $0Foo {}
988990
r#"
989991
trait Foo {}
990992
991-
$0impl<T: ?Sized> Foo for T {}
993+
impl<T: ?Sized> Foo for $0T {}
992994
"#,
993995
);
994996
}
@@ -1003,7 +1005,7 @@ trait $0Foo: Copy {}
10031005
r#"
10041006
trait Foo: Copy {}
10051007
1006-
$0impl<T: Copy + ?Sized> Foo for T {}
1008+
impl<T: Copy + ?Sized> Foo for $0T {}
10071009
"#,
10081010
);
10091011
}
@@ -1018,7 +1020,7 @@ trait $0Foo where Self: Copy {}
10181020
r#"
10191021
trait Foo where Self: Copy {}
10201022
1021-
$0impl<T: ?Sized> Foo for T
1023+
impl<T: ?Sized> Foo for $0T
10221024
where Self: Copy
10231025
{
10241026
}
@@ -1036,7 +1038,7 @@ trait $0Foo where Self: Copy, {}
10361038
r#"
10371039
trait Foo where Self: Copy, {}
10381040
1039-
$0impl<T: ?Sized> Foo for T
1041+
impl<T: ?Sized> Foo for $0T
10401042
where Self: Copy,
10411043
{
10421044
}
@@ -1058,7 +1060,7 @@ trait Foo
10581060
where Self: Copy
10591061
{}
10601062
1061-
$0impl<T: ?Sized> Foo for T
1063+
impl<T: ?Sized> Foo for $0T
10621064
where Self: Copy
10631065
{
10641066
}
@@ -1082,7 +1084,7 @@ where
10821084
Self: Copy
10831085
{}
10841086
1085-
$0impl<T: ?Sized> Foo for T
1087+
impl<T: ?Sized> Foo for $0T
10861088
where
10871089
Self: Copy
10881090
{
@@ -1107,7 +1109,7 @@ where
11071109
Self: Copy,
11081110
{}
11091111
1110-
$0impl<T: ?Sized> Foo for T
1112+
impl<T: ?Sized> Foo for $0T
11111113
where
11121114
Self: Copy,
11131115
{
@@ -1134,7 +1136,7 @@ where
11341136
(): Into<Self>,
11351137
{}
11361138
1137-
$0impl<T: ?Sized> Foo for T
1139+
impl<T: ?Sized> Foo for $0T
11381140
where
11391141
Self: Copy,
11401142
(): Into<Self>,
@@ -1162,7 +1164,7 @@ where
11621164
(): Into<Self>,
11631165
{}
11641166
1165-
$0impl<T: ?Sized> Foo for T
1167+
impl<T: ?Sized> Foo for $0T
11661168
where
11671169
Self: Copy + Sync,
11681170
(): Into<Self>,
@@ -1186,7 +1188,7 @@ trait Foo {
11861188
fn foo(&self) {}
11871189
}
11881190
1189-
$0impl<T: ?Sized> Foo for T {}
1191+
impl<T: ?Sized> Foo for $0T {}
11901192
"#,
11911193
);
11921194
}
@@ -1203,7 +1205,7 @@ trait $0Foo {}
12031205
/// some docs
12041206
trait Foo {}
12051207
1206-
$0impl<T: ?Sized> Foo for T {}
1208+
impl<T: ?Sized> Foo for $0T {}
12071209
"#,
12081210
);
12091211
}
@@ -1224,7 +1226,7 @@ trait Foo {
12241226
fn bar(&self);
12251227
}
12261228
1227-
$0impl<T: ?Sized> Foo for T {
1229+
impl<T: ?Sized> Foo for $0T {
12281230
fn foo(&self) {
12291231
todo!()
12301232
}
@@ -1253,7 +1255,7 @@ trait Foo {
12531255
fn bar<T>(&self, value: i32) -> i32 { todo!() }
12541256
}
12551257
1256-
$0impl<T: ?Sized> Foo for T {
1258+
impl<T: ?Sized> Foo for $0T {
12571259
fn foo<T>(&self, value: i32) -> i32 {
12581260
todo!()
12591261
}
@@ -1276,7 +1278,7 @@ trait Foo<'a> {
12761278
fn foo(&self) -> &'a str;
12771279
}
12781280
1279-
$0impl<'a, T: ?Sized> Foo<'a> for T {
1281+
impl<'a, T: ?Sized> Foo<'a> for $0T {
12801282
fn foo(&self) -> &'a str {
12811283
todo!()
12821284
}
@@ -1299,7 +1301,7 @@ trait Foo<'a: 'static> {
12991301
fn foo(&self) -> &'a str;
13001302
}
13011303
1302-
$0impl<'a: 'static, T: ?Sized> Foo<'a> for T {
1304+
impl<'a: 'static, T: ?Sized> Foo<'a> for $0T {
13031305
fn foo(&self) -> &'a str {
13041306
todo!()
13051307
}
@@ -1322,7 +1324,7 @@ trait Foo<'a>: 'a {
13221324
fn foo(&self) -> &'a str;
13231325
}
13241326
1325-
$0impl<'a, T: 'a + ?Sized> Foo<'a> for T {
1327+
impl<'a, T: 'a + ?Sized> Foo<'a> for $0T {
13261328
fn foo(&self) -> &'a str {
13271329
todo!()
13281330
}
@@ -1345,7 +1347,7 @@ trait Foo<'a, 'b> {
13451347
fn foo(&self) -> &'a &'b str;
13461348
}
13471349
1348-
$0impl<'a, 'b, T: ?Sized> Foo<'a, 'b> for T {
1350+
impl<'a, 'b, T: ?Sized> Foo<'a, 'b> for $0T {
13491351
fn foo(&self) -> &'a &'b str {
13501352
todo!()
13511353
}
@@ -1372,7 +1374,7 @@ where 'a: 'static,
13721374
fn foo(&self) -> &'a str;
13731375
}
13741376
1375-
$0impl<'a, T: ?Sized> Foo<'a> for T
1377+
impl<'a, T: ?Sized> Foo<'a> for $0T
13761378
where 'a: 'static,
13771379
{
13781380
fn foo(&self) -> &'a str {
@@ -1459,7 +1461,7 @@ trait Foo {
14591461
}
14601462
}
14611463
1462-
$0impl<T: ?Sized> Foo for T {
1464+
impl<T: ?Sized> Foo for $0T {
14631465
fn foo(&self) -> i32 {
14641466
todo!()
14651467
}
@@ -1496,7 +1498,7 @@ trait Foo {
14961498
}
14971499
}
14981500
1499-
$0impl<T: ?Sized> Foo for T {
1501+
impl<T: ?Sized> Foo for $0T {
15001502
fn foo(&self) -> i32 {
15011503
todo!()
15021504
}

src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ where
13391339
}
13401340
}
13411341
1342-
$0impl<T: Send, This: ToOwned + ?Sized> Foo<T> for This
1342+
impl<T: Send, This: ToOwned + ?Sized> Foo<T> for $0This
13431343
where
13441344
Self::Owned: Default,
13451345
{

0 commit comments

Comments
 (0)