@@ -55,12 +55,39 @@ pub(crate) fn try_inline(
55
55
let mut ret = Vec :: new ( ) ;
56
56
57
57
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
+ } ;
59
86
60
87
let kind = match res {
61
88
Res :: Def ( DefKind :: Trait , did) => {
62
89
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) ;
64
91
clean:: TraitItem ( Box :: new ( build_external_trait ( cx, did) ) )
65
92
}
66
93
Res :: Def ( DefKind :: Fn , did) => {
@@ -69,27 +96,27 @@ pub(crate) fn try_inline(
69
96
}
70
97
Res :: Def ( DefKind :: Struct , did) => {
71
98
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) ;
73
100
clean:: StructItem ( build_struct ( cx, did) )
74
101
}
75
102
Res :: Def ( DefKind :: Union , did) => {
76
103
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) ;
78
105
clean:: UnionItem ( build_union ( cx, did) )
79
106
}
80
107
Res :: Def ( DefKind :: TyAlias , did) => {
81
108
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) ;
83
110
clean:: TypedefItem ( build_type_alias ( cx, did) )
84
111
}
85
112
Res :: Def ( DefKind :: Enum , did) => {
86
113
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) ;
88
115
clean:: EnumItem ( build_enum ( cx, did) )
89
116
}
90
117
Res :: Def ( DefKind :: ForeignTy , did) => {
91
118
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) ;
93
120
clean:: ForeignTypeItem
94
121
}
95
122
// Never inline enum variants but leave them shown as re-exports.
@@ -123,7 +150,7 @@ pub(crate) fn try_inline(
123
150
_ => return None ,
124
151
} ;
125
152
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 ) ;
127
154
cx. inlined . insert ( did. into ( ) ) ;
128
155
let mut item = clean:: Item :: from_def_id_and_attrs_and_parts (
129
156
did,
0 commit comments