@@ -20,7 +20,6 @@ use syntax::{
20
20
HasGenericParams , HasName , HasTypeBounds , HasVisibility as astHasVisibility, Path ,
21
21
WherePred ,
22
22
edit:: { self , AstNodeEdit } ,
23
- edit_in_place:: AttrsOwnerEdit ,
24
23
make,
25
24
} ,
26
25
ted:: { self , Position } ,
@@ -266,6 +265,7 @@ fn generate_impl(
266
265
let bound_params = bound_def. generic_param_list ( ) ;
267
266
268
267
let delegate = make:: impl_trait (
268
+ None ,
269
269
delegee. is_unsafe ( db) ,
270
270
bound_params. clone ( ) ,
271
271
bound_params. map ( |params| params. to_generic_args ( ) ) ,
@@ -379,6 +379,7 @@ fn generate_impl(
379
379
let path_type = transform_impl ( ctx, ast_strukt, & old_impl, & transform_args, path_type) ?;
380
380
// 3) Generate delegate trait impl
381
381
let delegate = make:: impl_trait (
382
+ None ,
382
383
trait_. is_unsafe ( db) ,
383
384
trait_gen_params,
384
385
trait_gen_args,
@@ -652,8 +653,7 @@ fn process_assoc_item(
652
653
qual_path_ty : ast:: Path ,
653
654
base_name : & str ,
654
655
) -> Option < ast:: AssocItem > {
655
- let attrs = item. attrs ( ) ;
656
- let assoc = match item {
656
+ match item {
657
657
AssocItem :: Const ( c) => const_assoc_item ( c, qual_path_ty) ,
658
658
AssocItem :: Fn ( f) => func_assoc_item ( f, qual_path_ty, base_name) ,
659
659
AssocItem :: MacroCall ( _) => {
@@ -662,18 +662,7 @@ fn process_assoc_item(
662
662
None
663
663
}
664
664
AssocItem :: TypeAlias ( ta) => ty_assoc_item ( ta, qual_path_ty) ,
665
- } ;
666
- if let Some ( assoc) = & assoc {
667
- attrs. for_each ( |attr| {
668
- assoc. add_attr ( attr. clone ( ) ) ;
669
- // fix indentations
670
- if let Some ( tok) = attr. syntax ( ) . next_sibling_or_token ( ) {
671
- let pos = Position :: after ( tok) ;
672
- ted:: insert ( pos, make:: tokens:: whitespace ( " " ) ) ;
673
- }
674
- } )
675
665
}
676
- assoc
677
666
}
678
667
679
668
fn const_assoc_item ( item : syntax:: ast:: Const , qual_path_ty : ast:: Path ) -> Option < AssocItem > {
@@ -687,6 +676,7 @@ fn const_assoc_item(item: syntax::ast::Const, qual_path_ty: ast::Path) -> Option
687
676
// make::path_qualified(qual_path_ty, path_expr_segment.as_single_segment().unwrap());
688
677
let qualified_path = qualified_path ( qual_path_ty, path_expr_segment) ;
689
678
let inner = make:: item_const (
679
+ item. attrs ( ) ,
690
680
item. visibility ( ) ,
691
681
item. name ( ) ?,
692
682
item. ty ( ) ?,
@@ -755,6 +745,7 @@ fn func_assoc_item(
755
745
756
746
let body = make:: block_expr ( vec ! [ ] , Some ( call. into ( ) ) ) . clone_for_update ( ) ;
757
747
let func = make:: fn_ (
748
+ item. attrs ( ) ,
758
749
item. visibility ( ) ,
759
750
item. name ( ) ?,
760
751
item. generic_param_list ( ) ,
@@ -779,13 +770,14 @@ fn ty_assoc_item(item: syntax::ast::TypeAlias, qual_path_ty: Path) -> Option<Ass
779
770
let ident = item. name ( ) ?. to_string ( ) ;
780
771
781
772
let alias = make:: ty_alias (
773
+ item. attrs ( ) ,
782
774
ident. as_str ( ) ,
783
775
item. generic_param_list ( ) ,
784
776
None ,
785
777
item. where_clause ( ) ,
786
778
Some ( ( ty, None ) ) ,
787
779
)
788
- . clone_for_update ( ) ;
780
+ . indent ( edit :: IndentLevel ( 1 ) ) ;
789
781
790
782
Some ( AssocItem :: TypeAlias ( alias) )
791
783
}
@@ -1813,6 +1805,63 @@ impl T for B {
1813
1805
) ;
1814
1806
}
1815
1807
1808
+ #[ test]
1809
+ fn test_ty_alias_attrs ( ) {
1810
+ check_assist (
1811
+ generate_delegate_trait,
1812
+ r#"
1813
+ struct A;
1814
+
1815
+ trait T {
1816
+ #[cfg(test)]
1817
+ type t;
1818
+ #[cfg(not(test))]
1819
+ type t;
1820
+ }
1821
+
1822
+ impl T for A {
1823
+ #[cfg(test)]
1824
+ type t = u32;
1825
+ #[cfg(not(test))]
1826
+ type t = bool;
1827
+ }
1828
+
1829
+ struct B {
1830
+ a$0: A,
1831
+ }
1832
+ "# ,
1833
+ r#"
1834
+ struct A;
1835
+
1836
+ trait T {
1837
+ #[cfg(test)]
1838
+ type t;
1839
+ #[cfg(not(test))]
1840
+ type t;
1841
+ }
1842
+
1843
+ impl T for A {
1844
+ #[cfg(test)]
1845
+ type t = u32;
1846
+ #[cfg(not(test))]
1847
+ type t = bool;
1848
+ }
1849
+
1850
+ struct B {
1851
+ a: A,
1852
+ }
1853
+
1854
+ impl T for B {
1855
+ #[cfg(test)]
1856
+ type t = <A as T>::t;
1857
+
1858
+ #[cfg(not(test))]
1859
+ type t = <A as T>::t;
1860
+ }
1861
+ "# ,
1862
+ ) ;
1863
+ }
1864
+
1816
1865
#[ test]
1817
1866
fn assoc_items_attributes_mutably_cloned ( ) {
1818
1867
check_assist (
0 commit comments