@@ -49,7 +49,7 @@ pub struct DocFragment {
4949 pub doc : Symbol ,
5050 pub kind : DocFragmentKind ,
5151 pub indent : usize ,
52- /// Because we temper with the spans context, this information cannot be correctly retrieved
52+ /// Because we tamper with the spans context, this information cannot be correctly retrieved
5353 /// later on. So instead, we compute it and store it here.
5454 pub from_expansion : bool ,
5555}
@@ -504,16 +504,20 @@ fn collect_link_data<'input, F: BrokenLinkCallback<'input>>(
504504 display_text. map ( String :: into_boxed_str)
505505}
506506
507- /// Returns a span encompassing all the document fragments.
507+ /// Returns a tuple containing a span encompassing all the document fragments and a boolean that is
508+ /// `true` if the fragments are from a macro expansion.
508509pub fn span_of_fragments_with_expansion ( fragments : & [ DocFragment ] ) -> Option < ( Span , bool ) > {
509- let Some ( first_fragment) = fragments. first ( ) else { return None } ;
510+ let ( first_fragment, last_fragment) = match fragments {
511+ [ ] => return None ,
512+ [ first, .., last] => ( first, last) ,
513+ [ first] => ( first, first) ,
514+ } ;
510515 if first_fragment. span == DUMMY_SP {
511516 return None ;
512517 }
513- let last_fragment = fragments. last ( ) . expect ( "no doc strings provided" ) ;
514518 Some ( (
515519 first_fragment. span . to ( last_fragment. span ) ,
516- first_fragment . from_expansion || last_fragment . from_expansion ,
520+ fragments . iter ( ) . any ( |frag| frag . from_expansion ) ,
517521 ) )
518522}
519523
@@ -533,12 +537,16 @@ pub fn span_of_fragments(fragments: &[DocFragment]) -> Option<Span> {
533537/// This method will return `Some` only if one of the following is true:
534538///
535539/// - The doc is made entirely from sugared doc comments, which cannot contain escapes
536- /// - The doc is entirely from a single doc fragment with a string literal exactly equal to `markdown`.
540+ /// - The doc is entirely from a single doc fragment with a string literal exactly equal to
541+ /// `markdown`.
537542/// - The doc comes from `include_str!`
538- /// - The doc includes exactly one substring matching `markdown[md_range]` which is contained in a single doc fragment.
543+ /// - The doc includes exactly one substring matching `markdown[md_range]` which is contained in a
544+ /// single doc fragment.
545+ ///
546+ /// This function is defined in the compiler so it can be used by both `rustdoc` and `clippy`.
539547///
540- /// This function is defined in the compiler so it can be used by
541- /// both `rustdoc` and `clippy` .
548+ /// It returns a tuple containing a span encompassing all the document fragments and a boolean that
549+ /// is `true` if the fragments are from a macro expansion .
542550pub fn source_span_for_markdown_range (
543551 tcx : TyCtxt < ' _ > ,
544552 markdown : & str ,
0 commit comments