@@ -10,6 +10,7 @@ use pulldown_cmark::{
1010use rustc_ast as ast;
1111use rustc_ast:: attr:: AttributeExt ;
1212use rustc_ast:: join_path_syms;
13+ use rustc_ast:: token:: DocFragmentKind ;
1314use rustc_ast:: util:: comments:: beautify_doc_string;
1415use rustc_data_structures:: fx:: FxIndexMap ;
1516use rustc_data_structures:: unord:: UnordSet ;
@@ -23,14 +24,6 @@ use tracing::{debug, trace};
2324#[ cfg( test) ]
2425mod tests;
2526
26- #[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
27- pub enum DocFragmentKind {
28- /// A doc fragment created from a `///` or `//!` doc comment.
29- SugaredDoc ,
30- /// A doc fragment created from a "raw" `#[doc=""]` attribute.
31- RawDoc ,
32- }
33-
3427/// A portion of documentation, extracted from a `#[doc]` attribute.
3528///
3629/// Each variant contains the line number within the complete doc-comment where the fragment
@@ -125,7 +118,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
125118 //
126119 // In this case, you want "hello! another" and not "hello! another".
127120 let add = if docs. windows ( 2 ) . any ( |arr| arr[ 0 ] . kind != arr[ 1 ] . kind )
128- && docs. iter ( ) . any ( |d| d. kind == DocFragmentKind :: SugaredDoc )
121+ && docs. iter ( ) . any ( |d| d. kind . is_sugared ( ) )
129122 {
130123 // In case we have a mix of sugared doc comments and "raw" ones, we want the sugared one to
131124 // "decide" how much the minimum indent will be.
@@ -155,8 +148,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
155148 // Compare against either space or tab, ignoring whether they are
156149 // mixed or not.
157150 let whitespace = line. chars ( ) . take_while ( |c| * c == ' ' || * c == '\t' ) . count ( ) ;
158- whitespace
159- + ( if fragment. kind == DocFragmentKind :: SugaredDoc { 0 } else { add } )
151+ whitespace + ( if fragment. kind . is_sugared ( ) { 0 } else { add } )
160152 } )
161153 . min ( )
162154 . unwrap_or ( usize:: MAX )
@@ -171,7 +163,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
171163 continue ;
172164 }
173165
174- let indent = if fragment. kind != DocFragmentKind :: SugaredDoc && min_indent > 0 {
166+ let indent = if ! fragment. kind . is_sugared ( ) && min_indent > 0 {
175167 min_indent - add
176168 } else {
177169 min_indent
@@ -214,19 +206,17 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
214206 let mut doc_fragments = Vec :: with_capacity ( size_hint) ;
215207 let mut other_attrs = ThinVec :: < A > :: with_capacity ( if doc_only { 0 } else { size_hint } ) ;
216208 for ( attr, item_id) in attrs {
217- if let Some ( ( doc_str, comment_kind) ) = attr. doc_str_and_comment_kind ( ) {
218- let doc = beautify_doc_string ( doc_str, comment_kind) ;
219- let ( span, kind, from_expansion) = if let Some ( span) = attr. is_doc_comment ( ) {
220- ( span, DocFragmentKind :: SugaredDoc , span. from_expansion ( ) )
221- } else {
222- let attr_span = attr. span ( ) ;
223- let ( span, from_expansion) = match attr. value_span ( ) {
224- Some ( sp) => ( sp. with_ctxt ( attr_span. ctxt ( ) ) , sp. from_expansion ( ) ) ,
225- None => ( attr_span, attr_span. from_expansion ( ) ) ,
226- } ;
227- ( span, DocFragmentKind :: RawDoc , from_expansion)
209+ if let Some ( ( doc_str, fragment_kind) ) = attr. doc_str_and_fragment_kind ( ) {
210+ let doc = beautify_doc_string ( doc_str, fragment_kind. comment_kind ( ) ) ;
211+ let attr_span = attr. span ( ) ;
212+ let ( span, from_expansion) = match fragment_kind {
213+ DocFragmentKind :: Sugared ( _) => ( attr_span, attr_span. from_expansion ( ) ) ,
214+ DocFragmentKind :: Raw ( value_span) => {
215+ ( value_span. with_ctxt ( attr_span. ctxt ( ) ) , value_span. from_expansion ( ) )
216+ }
228217 } ;
229- let fragment = DocFragment { span, doc, kind, item_id, indent : 0 , from_expansion } ;
218+ let fragment =
219+ DocFragment { span, doc, kind : fragment_kind, item_id, indent : 0 , from_expansion } ;
230220 doc_fragments. push ( fragment) ;
231221 } else if !doc_only {
232222 other_attrs. push ( attr. clone ( ) ) ;
@@ -571,7 +561,7 @@ pub fn source_span_for_markdown_range_inner(
571561 use rustc_span:: BytePos ;
572562
573563 if let & [ fragment] = & fragments
574- && fragment. kind == DocFragmentKind :: RawDoc
564+ && ! fragment. kind . is_sugared ( )
575565 && let Ok ( snippet) = map. span_to_snippet ( fragment. span )
576566 && snippet. trim_end ( ) == markdown. trim_end ( )
577567 && let Ok ( md_range_lo) = u32:: try_from ( md_range. start )
@@ -589,7 +579,7 @@ pub fn source_span_for_markdown_range_inner(
589579 ) ) ;
590580 }
591581
592- let is_all_sugared_doc = fragments. iter ( ) . all ( |frag| frag. kind == DocFragmentKind :: SugaredDoc ) ;
582+ let is_all_sugared_doc = fragments. iter ( ) . all ( |frag| frag. kind . is_sugared ( ) ) ;
593583
594584 if !is_all_sugared_doc {
595585 // This case ignores the markdown outside of the range so that it can
0 commit comments