@@ -160,7 +160,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
160
160
parent : None ,
161
161
children : vec ! [ ] ,
162
162
decl_id : None ,
163
- docs : docs_for_attrs ( & item. attrs ) ,
163
+ docs : self . docs_for_attrs ( & item. attrs ) ,
164
164
sig : sig:: foreign_item_signature ( item, self ) ,
165
165
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
166
166
} ) )
@@ -183,7 +183,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
183
183
parent : None ,
184
184
children : vec ! [ ] ,
185
185
decl_id : None ,
186
- docs : docs_for_attrs ( & item. attrs ) ,
186
+ docs : self . docs_for_attrs ( & item. attrs ) ,
187
187
sig : sig:: foreign_item_signature ( item, self ) ,
188
188
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
189
189
} ) )
@@ -207,7 +207,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
207
207
parent : None ,
208
208
children : vec ! [ ] ,
209
209
decl_id : None ,
210
- docs : docs_for_attrs ( & item. attrs ) ,
210
+ docs : self . docs_for_attrs ( & item. attrs ) ,
211
211
sig : sig:: item_signature ( item, self ) ,
212
212
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
213
213
} ) )
@@ -236,7 +236,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
236
236
parent : None ,
237
237
children : vec ! [ ] ,
238
238
decl_id : None ,
239
- docs : docs_for_attrs ( & item. attrs ) ,
239
+ docs : self . docs_for_attrs ( & item. attrs ) ,
240
240
sig : sig:: item_signature ( item, self ) ,
241
241
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
242
242
} ) )
@@ -259,7 +259,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
259
259
parent : None ,
260
260
children : vec ! [ ] ,
261
261
decl_id : None ,
262
- docs : docs_for_attrs ( & item. attrs ) ,
262
+ docs : self . docs_for_attrs ( & item. attrs ) ,
263
263
sig : sig:: item_signature ( item, self ) ,
264
264
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
265
265
} ) )
@@ -283,7 +283,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
283
283
parent : None ,
284
284
children : m. items . iter ( ) . map ( |i| id_from_node_id ( i. id , self ) ) . collect ( ) ,
285
285
decl_id : None ,
286
- docs : docs_for_attrs ( & item. attrs ) ,
286
+ docs : self . docs_for_attrs ( & item. attrs ) ,
287
287
sig : sig:: item_signature ( item, self ) ,
288
288
attributes : lower_attributes ( item. attrs . clone ( ) , self ) ,
289
289
} ) )
@@ -311,7 +311,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
311
311
. map ( |v| id_from_node_id ( v. node . data . id ( ) , self ) )
312
312
. collect ( ) ,
313
313
decl_id : None ,
314
- docs : docs_for_attrs ( & item. attrs ) ,
314
+ docs : self . docs_for_attrs ( & item. attrs ) ,
315
315
sig : sig:: item_signature ( item, self ) ,
316
316
attributes : lower_attributes ( item. attrs . to_owned ( ) , self ) ,
317
317
} ) )
@@ -372,7 +372,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
372
372
parent : Some ( id_from_node_id ( scope, self ) ) ,
373
373
children : vec ! [ ] ,
374
374
decl_id : None ,
375
- docs : docs_for_attrs ( & field. attrs ) ,
375
+ docs : self . docs_for_attrs ( & field. attrs ) ,
376
376
sig : sig:: field_signature ( field, self ) ,
377
377
attributes : lower_attributes ( field. attrs . clone ( ) , self ) ,
378
378
} )
@@ -417,7 +417,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
417
417
result. push_str ( ">" ) ;
418
418
419
419
( result, trait_id, decl_id,
420
- docs_for_attrs ( & item. attrs ) ,
420
+ self . docs_for_attrs ( & item. attrs ) ,
421
421
item. attrs . to_vec ( ) )
422
422
}
423
423
_ => {
@@ -442,7 +442,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
442
442
Some ( Node :: NodeItem ( item) ) => {
443
443
( format ! ( "::{}" , self . tcx. item_path_str( def_id) ) ,
444
444
Some ( def_id) , None ,
445
- docs_for_attrs ( & item. attrs ) ,
445
+ self . docs_for_attrs ( & item. attrs ) ,
446
446
item. attrs . to_vec ( ) )
447
447
}
448
448
r => {
@@ -771,6 +771,31 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
771
771
pub fn enclosing_scope ( & self , id : NodeId ) -> NodeId {
772
772
self . tcx . hir . get_enclosing_scope ( id) . unwrap_or ( CRATE_NODE_ID )
773
773
}
774
+
775
+ fn docs_for_attrs ( & self , attrs : & [ Attribute ] ) -> String {
776
+ let mut result = String :: new ( ) ;
777
+
778
+ for attr in attrs {
779
+ if attr. check_name ( "doc" ) {
780
+ if let Some ( val) = attr. value_str ( ) {
781
+ if attr. is_sugared_doc {
782
+ result. push_str ( & strip_doc_comment_decoration ( & val. as_str ( ) ) ) ;
783
+ } else {
784
+ result. push_str ( & val. as_str ( ) ) ;
785
+ }
786
+ result. push ( '\n' ) ;
787
+ }
788
+ }
789
+ }
790
+
791
+ if !self . config . full_docs {
792
+ if let Some ( index) = result. find ( "\n \n " ) {
793
+ result. truncate ( index) ;
794
+ }
795
+ }
796
+
797
+ result
798
+ }
774
799
}
775
800
776
801
fn make_signature ( decl : & ast:: FnDecl , generics : & ast:: Generics ) -> String {
@@ -847,25 +872,6 @@ impl<'a> Visitor<'a> for PathCollector {
847
872
}
848
873
}
849
874
850
- fn docs_for_attrs ( attrs : & [ Attribute ] ) -> String {
851
- let mut result = String :: new ( ) ;
852
-
853
- for attr in attrs {
854
- if attr. check_name ( "doc" ) {
855
- if let Some ( val) = attr. value_str ( ) {
856
- if attr. is_sugared_doc {
857
- result. push_str ( & strip_doc_comment_decoration ( & val. as_str ( ) ) ) ;
858
- } else {
859
- result. push_str ( & val. as_str ( ) ) ;
860
- }
861
- result. push ( '\n' ) ;
862
- }
863
- }
864
- }
865
-
866
- result
867
- }
868
-
869
875
#[ derive( Clone , Copy , Debug , RustcEncodable ) ]
870
876
pub enum Format {
871
877
Json ,
0 commit comments