@@ -370,32 +370,22 @@ impl<I: IntoIterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
370370/// information can be given when a doctest fails. Sugared doc comments and "raw" doc comments are
371371/// kept separate because of issue #42760.
372372#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
373- pub enum DocFragment {
373+ pub struct DocFragment {
374+ pub line : usize ,
375+ pub span : rustc_span:: Span ,
376+ pub doc : String ,
377+ pub kind : DocFragmentKind ,
378+ }
379+
380+ #[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
381+ pub enum DocFragmentKind {
374382 /// A doc fragment created from a `///` or `//!` doc comment.
375- SugaredDoc ( usize , rustc_span :: Span , String ) ,
383+ SugaredDoc ,
376384 /// A doc fragment created from a "raw" `#[doc=""]` attribute.
377- RawDoc ( usize , rustc_span :: Span , String ) ,
385+ RawDoc ,
378386 /// A doc fragment created from a `#[doc(include="filename")]` attribute. Contains both the
379387 /// given filename and the file contents.
380- Include ( usize , rustc_span:: Span , String , String ) ,
381- }
382-
383- impl DocFragment {
384- pub fn as_str ( & self ) -> & str {
385- match * self {
386- DocFragment :: SugaredDoc ( _, _, ref s) => & s[ ..] ,
387- DocFragment :: RawDoc ( _, _, ref s) => & s[ ..] ,
388- DocFragment :: Include ( _, _, _, ref s) => & s[ ..] ,
389- }
390- }
391-
392- pub fn span ( & self ) -> rustc_span:: Span {
393- match * self {
394- DocFragment :: SugaredDoc ( _, span, _)
395- | DocFragment :: RawDoc ( _, span, _)
396- | DocFragment :: Include ( _, span, _, _) => span,
397- }
398- }
388+ Include { filename : String } ,
399389}
400390
401391impl < ' a > FromIterator < & ' a DocFragment > for String {
@@ -407,12 +397,7 @@ impl<'a> FromIterator<&'a DocFragment> for String {
407397 if !acc. is_empty ( ) {
408398 acc. push ( '\n' ) ;
409399 }
410- match * frag {
411- DocFragment :: SugaredDoc ( _, _, ref docs)
412- | DocFragment :: RawDoc ( _, _, ref docs)
413- | DocFragment :: Include ( _, _, _, ref docs) => acc. push_str ( docs) ,
414- }
415-
400+ acc. push_str ( & frag. doc ) ;
416401 acc
417402 } )
418403 }
@@ -547,15 +532,15 @@ impl Attributes {
547532 . filter_map ( |attr| {
548533 if let Some ( value) = attr. doc_str ( ) {
549534 let value = beautify_doc_string ( value) ;
550- let mk_fragment : fn ( _ , _ , _ ) -> _ = if attr. is_doc_comment ( ) {
551- DocFragment :: SugaredDoc
535+ let kind = if attr. is_doc_comment ( ) {
536+ DocFragmentKind :: SugaredDoc
552537 } else {
553- DocFragment :: RawDoc
538+ DocFragmentKind :: RawDoc
554539 } ;
555540
556541 let line = doc_line;
557542 doc_line += value. lines ( ) . count ( ) ;
558- doc_strings. push ( mk_fragment ( line, attr. span , value) ) ;
543+ doc_strings. push ( DocFragment { line, span : attr. span , doc : value, kind } ) ;
559544
560545 if sp. is_none ( ) {
561546 sp = Some ( attr. span ) ;
@@ -575,9 +560,12 @@ impl Attributes {
575560 {
576561 let line = doc_line;
577562 doc_line += contents. lines ( ) . count ( ) ;
578- doc_strings. push ( DocFragment :: Include (
579- line, attr. span , filename, contents,
580- ) ) ;
563+ doc_strings. push ( DocFragment {
564+ line,
565+ span : attr. span ,
566+ doc : contents,
567+ kind : DocFragmentKind :: Include { filename } ,
568+ } ) ;
581569 }
582570 }
583571 }
@@ -621,7 +609,7 @@ impl Attributes {
621609 /// Finds the `doc` attribute as a NameValue and returns the corresponding
622610 /// value found.
623611 pub fn doc_value ( & self ) -> Option < & str > {
624- self . doc_strings . first ( ) . map ( |s| s. as_str ( ) )
612+ self . doc_strings . first ( ) . map ( |s| s. doc . as_str ( ) )
625613 }
626614
627615 /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
0 commit comments