@@ -231,13 +231,11 @@ impl Clean<Item> for doctree::Module<'_> {
231
231
let mut items: Vec < Item > = vec ! [ ] ;
232
232
items. extend ( self . extern_crates . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
233
233
items. extend ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
234
- items. extend ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
235
234
items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
236
235
items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
237
236
items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) . flatten ( ) ) ;
238
237
items. extend ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
239
238
items. extend ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
240
- items. extend ( self . proc_macros . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
241
239
242
240
// determine if we should display the inner contents or
243
241
// the outer `mod` item for the source code.
@@ -871,6 +869,66 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
871
869
}
872
870
}
873
871
872
+ fn clean_fn_or_proc_macro (
873
+ item : & hir:: Item < ' _ > ,
874
+ sig : & ' a hir:: FnSig < ' a > ,
875
+ generics : & ' a hir:: Generics < ' a > ,
876
+ body_id : hir:: BodyId ,
877
+ name : & mut Symbol ,
878
+ cx : & DocContext < ' _ > ,
879
+ ) -> ItemKind {
880
+ let macro_kind = item. attrs . iter ( ) . find_map ( |a| {
881
+ if a. has_name ( sym:: proc_macro) {
882
+ Some ( MacroKind :: Bang )
883
+ } else if a. has_name ( sym:: proc_macro_derive) {
884
+ Some ( MacroKind :: Derive )
885
+ } else if a. has_name ( sym:: proc_macro_attribute) {
886
+ Some ( MacroKind :: Attr )
887
+ } else {
888
+ None
889
+ }
890
+ } ) ;
891
+ match macro_kind {
892
+ Some ( kind) => {
893
+ if kind == MacroKind :: Derive {
894
+ * name = item
895
+ . attrs
896
+ . lists ( sym:: proc_macro_derive)
897
+ . find_map ( |mi| mi. ident ( ) )
898
+ . expect ( "proc-macro derives require a name" )
899
+ . name ;
900
+ }
901
+
902
+ let mut helpers = Vec :: new ( ) ;
903
+ for mi in item. attrs . lists ( sym:: proc_macro_derive) {
904
+ if !mi. has_name ( sym:: attributes) {
905
+ continue ;
906
+ }
907
+
908
+ if let Some ( list) = mi. meta_item_list ( ) {
909
+ for inner_mi in list {
910
+ if let Some ( ident) = inner_mi. ident ( ) {
911
+ helpers. push ( ident. name ) ;
912
+ }
913
+ }
914
+ }
915
+ }
916
+ ProcMacroItem ( ProcMacro { kind, helpers : helpers. clean ( cx) } )
917
+ }
918
+ None => {
919
+ let mut func = ( sig, generics, body_id) . clean ( cx) ;
920
+ let def_id = cx. tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
921
+ func. header . constness =
922
+ if is_const_fn ( cx. tcx , def_id) && is_unstable_const_fn ( cx. tcx , def_id) . is_none ( ) {
923
+ hir:: Constness :: Const
924
+ } else {
925
+ hir:: Constness :: NotConst
926
+ } ;
927
+ FunctionItem ( func)
928
+ }
929
+ }
930
+ }
931
+
874
932
impl < ' a > Clean < Function > for ( & ' a hir:: FnSig < ' a > , & ' a hir:: Generics < ' a > , hir:: BodyId ) {
875
933
fn clean ( & self , cx : & DocContext < ' _ > ) -> Function {
876
934
let ( generics, decl) =
@@ -880,34 +938,6 @@ impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::Bo
880
938
}
881
939
}
882
940
883
- impl Clean < Item > for doctree:: Function < ' _ > {
884
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
885
- let ( generics, decl) =
886
- enter_impl_trait ( cx, || ( self . generics . clean ( cx) , ( self . decl , self . body ) . clean ( cx) ) ) ;
887
-
888
- let did = cx. tcx . hir ( ) . local_def_id ( self . id ) . to_def_id ( ) ;
889
- let constness = if is_const_fn ( cx. tcx , did) && !is_unstable_const_fn ( cx. tcx , did) . is_some ( )
890
- {
891
- hir:: Constness :: Const
892
- } else {
893
- hir:: Constness :: NotConst
894
- } ;
895
- let ( all_types, ret_types) = get_all_types ( & generics, & decl, cx) ;
896
- Item :: from_def_id_and_parts (
897
- did,
898
- Some ( self . name ) ,
899
- FunctionItem ( Function {
900
- decl,
901
- generics,
902
- header : hir:: FnHeader { constness, ..self . header } ,
903
- all_types,
904
- ret_types,
905
- } ) ,
906
- cx,
907
- )
908
- }
909
- }
910
-
911
941
impl < ' a > Clean < Arguments > for ( & ' a [ hir:: Ty < ' a > ] , & ' a [ Ident ] ) {
912
942
fn clean ( & self , cx : & DocContext < ' _ > ) -> Arguments {
913
943
Arguments {
@@ -1927,7 +1957,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
1927
1957
1928
1958
let ( item, renamed) = self ;
1929
1959
let def_id = cx. tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ;
1930
- let name = match renamed {
1960
+ let mut name = match renamed {
1931
1961
Some ( ident) => ident. name ,
1932
1962
None => cx. tcx . hir ( ) . name ( item. hir_id ) ,
1933
1963
} ;
@@ -1977,6 +2007,10 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
1977
2007
fields_stripped : false ,
1978
2008
} ) ,
1979
2009
ItemKind :: Impl { .. } => return clean_impl ( item, cx) ,
2010
+ // proc macros can have a name set by attributes
2011
+ ItemKind :: Fn ( ref sig, ref generics, body_id) => {
2012
+ clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2013
+ }
1980
2014
_ => unreachable ! ( "not yet converted" ) ,
1981
2015
} ;
1982
2016
@@ -2239,17 +2273,6 @@ impl Clean<Item> for doctree::Macro {
2239
2273
}
2240
2274
}
2241
2275
2242
- impl Clean < Item > for doctree:: ProcMacro {
2243
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
2244
- Item :: from_hir_id_and_parts (
2245
- self . id ,
2246
- Some ( self . name ) ,
2247
- ProcMacroItem ( ProcMacro { kind : self . kind , helpers : self . helpers . clean ( cx) } ) ,
2248
- cx,
2249
- )
2250
- }
2251
- }
2252
-
2253
2276
impl Clean < Deprecation > for attr:: Deprecation {
2254
2277
fn clean ( & self , _: & DocContext < ' _ > ) -> Deprecation {
2255
2278
Deprecation {
0 commit comments