@@ -49,7 +49,7 @@ pub struct DocFragment {
49
49
pub doc : Symbol ,
50
50
pub kind : DocFragmentKind ,
51
51
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
53
53
/// later on. So instead, we compute it and store it here.
54
54
pub from_expansion : bool ,
55
55
}
@@ -504,16 +504,20 @@ fn collect_link_data<'input, F: BrokenLinkCallback<'input>>(
504
504
display_text. map ( String :: into_boxed_str)
505
505
}
506
506
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.
508
509
pub 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
+ } ;
510
515
if first_fragment. span == DUMMY_SP {
511
516
return None ;
512
517
}
513
- let last_fragment = fragments. last ( ) . expect ( "no doc strings provided" ) ;
514
518
Some ( (
515
519
first_fragment. span . to ( last_fragment. span ) ,
516
- first_fragment . from_expansion || last_fragment . from_expansion ,
520
+ fragments . iter ( ) . any ( |frag| frag . from_expansion ) ,
517
521
) )
518
522
}
519
523
@@ -533,12 +537,16 @@ pub fn span_of_fragments(fragments: &[DocFragment]) -> Option<Span> {
533
537
/// This method will return `Some` only if one of the following is true:
534
538
///
535
539
/// - 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`.
537
542
/// - 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`.
539
547
///
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 .
542
550
pub fn source_span_for_markdown_range (
543
551
tcx : TyCtxt < ' _ > ,
544
552
markdown : & str ,
0 commit comments