@@ -55,12 +55,39 @@ pub(crate) fn try_inline(
5555 let mut ret = Vec :: new ( ) ;
5656
5757 debug ! ( "attrs={:?}" , attrs) ;
58- let attrs_clone = attrs;
58+
59+ let attrs_without_docs = attrs. map ( |attrs| {
60+ attrs. into_iter ( ) . filter ( |a| a. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( )
61+ } ) ;
62+ // We need this ugly code because:
63+ //
64+ // ```
65+ // attrs_without_docs.map(|a| a.as_slice())
66+ // ```
67+ //
68+ // will fail because it returns a temporary slice and:
69+ //
70+ // ```
71+ // attrs_without_docs.map(|s| {
72+ // vec = s.as_slice();
73+ // vec
74+ // })
75+ // ```
76+ //
77+ // will fail because we're moving an uninitialized variable into a closure.
78+ let vec;
79+ let attrs_without_docs = match attrs_without_docs {
80+ Some ( s) => {
81+ vec = s;
82+ Some ( vec. as_slice ( ) )
83+ }
84+ None => None ,
85+ } ;
5986
6087 let kind = match res {
6188 Res :: Def ( DefKind :: Trait , did) => {
6289 record_extern_fqn ( cx, did, ItemType :: Trait ) ;
63- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
90+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
6491 clean:: TraitItem ( Box :: new ( build_external_trait ( cx, did) ) )
6592 }
6693 Res :: Def ( DefKind :: Fn , did) => {
@@ -69,27 +96,27 @@ pub(crate) fn try_inline(
6996 }
7097 Res :: Def ( DefKind :: Struct , did) => {
7198 record_extern_fqn ( cx, did, ItemType :: Struct ) ;
72- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
99+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
73100 clean:: StructItem ( build_struct ( cx, did) )
74101 }
75102 Res :: Def ( DefKind :: Union , did) => {
76103 record_extern_fqn ( cx, did, ItemType :: Union ) ;
77- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
104+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
78105 clean:: UnionItem ( build_union ( cx, did) )
79106 }
80107 Res :: Def ( DefKind :: TyAlias , did) => {
81108 record_extern_fqn ( cx, did, ItemType :: Typedef ) ;
82- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
109+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
83110 clean:: TypedefItem ( build_type_alias ( cx, did) )
84111 }
85112 Res :: Def ( DefKind :: Enum , did) => {
86113 record_extern_fqn ( cx, did, ItemType :: Enum ) ;
87- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
114+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
88115 clean:: EnumItem ( build_enum ( cx, did) )
89116 }
90117 Res :: Def ( DefKind :: ForeignTy , did) => {
91118 record_extern_fqn ( cx, did, ItemType :: ForeignType ) ;
92- build_impls ( cx, Some ( parent_module) , did, attrs , & mut ret) ;
119+ build_impls ( cx, Some ( parent_module) , did, attrs_without_docs , & mut ret) ;
93120 clean:: ForeignTypeItem
94121 }
95122 // Never inline enum variants but leave them shown as re-exports.
@@ -123,7 +150,7 @@ pub(crate) fn try_inline(
123150 _ => return None ,
124151 } ;
125152
126- let ( attrs, cfg) = merge_attrs ( cx, Some ( parent_module) , load_attrs ( cx, did) , attrs_clone ) ;
153+ let ( attrs, cfg) = merge_attrs ( cx, Some ( parent_module) , load_attrs ( cx, did) , attrs ) ;
127154 cx. inlined . insert ( did. into ( ) ) ;
128155 let mut item = clean:: Item :: from_def_id_and_attrs_and_parts (
129156 did,
0 commit comments