@@ -49,7 +49,7 @@ use syntax::{
49
49
// };
50
50
// }
51
51
//
52
- // trait ${0:NewTrait }<const N: usize> {
52
+ // trait ${0:Create }<const N: usize> {
53
53
// // Used as an associated constant.
54
54
// const CONST_ASSOC: usize = N * 4;
55
55
//
@@ -58,7 +58,7 @@ use syntax::{
58
58
// const_maker! {i32, 7}
59
59
// }
60
60
//
61
- // impl<const N: usize> ${0:NewTrait }<N> for Foo<N> {
61
+ // impl<const N: usize> ${0:Create }<N> for Foo<N> {
62
62
// // Used as an associated constant.
63
63
// const CONST_ASSOC: usize = N * 4;
64
64
//
@@ -115,7 +115,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
115
115
116
116
let trait_ast = make:: trait_ (
117
117
false ,
118
- "NewTrait" ,
118
+ & trait_name ( & impl_items ) . text ( ) ,
119
119
impl_ast. generic_param_list ( ) ,
120
120
impl_ast. where_clause ( ) ,
121
121
trait_items,
@@ -161,6 +161,14 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
161
161
Some ( ( ) )
162
162
}
163
163
164
+ fn trait_name ( items : & ast:: AssocItemList ) -> ast:: Name {
165
+ items
166
+ . assoc_items ( )
167
+ . find_map ( |x| if let ast:: AssocItem :: Fn ( f) = x { f. name ( ) } else { None } )
168
+ . map ( |name| make:: name ( & stdx:: to_camel_case ( & name. text ( ) ) ) )
169
+ . unwrap_or_else ( || make:: name ( "NewTrait" ) )
170
+ }
171
+
164
172
/// `E0449` Trait items always share the visibility of their trait
165
173
fn remove_items_visibility ( item : & ast:: AssocItem ) {
166
174
if let Some ( has_vis) = ast:: AnyHasVisibility :: cast ( item. syntax ( ) . clone ( ) ) {
@@ -219,11 +227,11 @@ impl F$0oo {
219
227
r#"
220
228
struct Foo(f64);
221
229
222
- trait NewTrait {
230
+ trait Add {
223
231
fn add(&mut self, x: f64);
224
232
}
225
233
226
- impl NewTrait for Foo {
234
+ impl Add for Foo {
227
235
fn add(&mut self, x: f64) {
228
236
self.0 += x;
229
237
}
@@ -332,11 +340,11 @@ impl F$0oo {
332
340
r#"
333
341
struct Foo;
334
342
335
- trait NewTrait {
343
+ trait AFunc {
336
344
fn a_func() -> Option<()>;
337
345
}
338
346
339
- impl NewTrait for Foo {
347
+ impl AFunc for Foo {
340
348
fn a_func() -> Option<()> {
341
349
Some(())
342
350
}
@@ -366,11 +374,11 @@ mod a {
366
374
}"# ,
367
375
r#"
368
376
mod a {
369
- trait NewTrait {
377
+ trait Foo {
370
378
fn foo();
371
379
}
372
380
373
- impl NewTrait for S {
381
+ impl Foo for S {
374
382
fn foo() {}
375
383
}
376
384
}"# ,
0 commit comments