@@ -339,7 +339,7 @@ pub fn look_for_tests<'tcx>(
339339 find_testable_code ( & dox, & mut tests, ErrorCodes :: No ) ;
340340
341341 if check_missing_code == true && tests. found_tests == 0 {
342- let sp = span_of_attrs ( & item. attrs ) . substitute_dummy ( item. source . span ( ) ) ;
342+ let sp = span_of_attrs ( & item. attrs ) . unwrap_or ( item. source . span ( ) ) ;
343343 let mut diag = cx. tcx . struct_span_lint_hir (
344344 lint:: builtin:: MISSING_DOC_CODE_EXAMPLES ,
345345 hir_id,
@@ -352,20 +352,23 @@ pub fn look_for_tests<'tcx>(
352352 let mut diag = cx. tcx . struct_span_lint_hir (
353353 lint:: builtin:: PRIVATE_DOC_TESTS ,
354354 hir_id,
355- span_of_attrs ( & item. attrs ) ,
355+ span_of_attrs ( & item. attrs ) . unwrap_or ( item . source . span ( ) ) ,
356356 "Documentation test in private item" ) ;
357357 diag. emit ( ) ;
358358 }
359359}
360360
361361/// Returns a span encompassing all the given attributes.
362- crate fn span_of_attrs ( attrs : & clean:: Attributes ) -> Span {
362+ crate fn span_of_attrs ( attrs : & clean:: Attributes ) -> Option < Span > {
363363 if attrs. doc_strings . is_empty ( ) {
364- return DUMMY_SP ;
364+ return None ;
365365 }
366366 let start = attrs. doc_strings [ 0 ] . span ( ) ;
367+ if start == DUMMY_SP {
368+ return None ;
369+ }
367370 let end = attrs. doc_strings . last ( ) . expect ( "No doc strings provided" ) . span ( ) ;
368- start. to ( end)
371+ Some ( start. to ( end) )
369372}
370373
371374/// Attempts to match a range of bytes from parsed markdown to a `Span` in the source code.
@@ -391,7 +394,7 @@ crate fn source_span_for_markdown_range(
391394 let snippet = cx
392395 . sess ( )
393396 . source_map ( )
394- . span_to_snippet ( span_of_attrs ( attrs) )
397+ . span_to_snippet ( span_of_attrs ( attrs) ? )
395398 . ok ( ) ?;
396399
397400 let starting_line = markdown[ ..md_range. start ] . matches ( '\n' ) . count ( ) ;
@@ -441,10 +444,8 @@ crate fn source_span_for_markdown_range(
441444 }
442445 }
443446
444- let sp = span_of_attrs ( attrs) . from_inner ( InnerSpan :: new (
447+ Some ( span_of_attrs ( attrs) ? . from_inner ( InnerSpan :: new (
445448 md_range. start + start_bytes,
446449 md_range. end + start_bytes + end_bytes,
447- ) ) ;
448-
449- Some ( sp)
450+ ) ) )
450451}
0 commit comments