@@ -339,7 +339,7 @@ pub fn look_for_tests<'tcx>(
339
339
find_testable_code ( & dox, & mut tests, ErrorCodes :: No ) ;
340
340
341
341
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 ( ) ) ;
343
343
let mut diag = cx. tcx . struct_span_lint_hir (
344
344
lint:: builtin:: MISSING_DOC_CODE_EXAMPLES ,
345
345
hir_id,
@@ -352,20 +352,23 @@ pub fn look_for_tests<'tcx>(
352
352
let mut diag = cx. tcx . struct_span_lint_hir (
353
353
lint:: builtin:: PRIVATE_DOC_TESTS ,
354
354
hir_id,
355
- span_of_attrs ( & item. attrs ) ,
355
+ span_of_attrs ( & item. attrs ) . unwrap_or ( item . source . span ( ) ) ,
356
356
"Documentation test in private item" ) ;
357
357
diag. emit ( ) ;
358
358
}
359
359
}
360
360
361
361
/// 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 > {
363
363
if attrs. doc_strings . is_empty ( ) {
364
- return DUMMY_SP ;
364
+ return None ;
365
365
}
366
366
let start = attrs. doc_strings [ 0 ] . span ( ) ;
367
+ if start == DUMMY_SP {
368
+ return None ;
369
+ }
367
370
let end = attrs. doc_strings . last ( ) . expect ( "No doc strings provided" ) . span ( ) ;
368
- start. to ( end)
371
+ Some ( start. to ( end) )
369
372
}
370
373
371
374
/// 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(
391
394
let snippet = cx
392
395
. sess ( )
393
396
. source_map ( )
394
- . span_to_snippet ( span_of_attrs ( attrs) )
397
+ . span_to_snippet ( span_of_attrs ( attrs) ? )
395
398
. ok ( ) ?;
396
399
397
400
let starting_line = markdown[ ..md_range. start ] . matches ( '\n' ) . count ( ) ;
@@ -441,10 +444,8 @@ crate fn source_span_for_markdown_range(
441
444
}
442
445
}
443
446
444
- let sp = span_of_attrs ( attrs) . from_inner ( InnerSpan :: new (
447
+ Some ( span_of_attrs ( attrs) ? . from_inner ( InnerSpan :: new (
445
448
md_range. start + start_bytes,
446
449
md_range. end + start_bytes + end_bytes,
447
- ) ) ;
448
-
449
- Some ( sp)
450
+ ) ) )
450
451
}
0 commit comments