Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58b84bf

Browse files
authoredSep 5, 2019
Rollup merge of rust-lang#63930 - estebank:rustdoc-ice, r=GuillaumeGomez
Account for doc comments coming from proc macros without spans Fix rust-lang#63821.
2 parents 789d9b7 + 7ed542d commit 58b84bf

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed
 

‎src/librustdoc/passes/check_code_block_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
8181
// We couldn't calculate the span of the markdown block that had the error, so our
8282
// diagnostics are going to be a bit lacking.
8383
let mut diag = self.cx.sess().struct_span_warn(
84-
super::span_of_attrs(&item.attrs),
84+
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
8585
"doc comment contains an invalid Rust code block",
8686
);
8787

‎src/librustdoc/passes/collect_intra_doc_links.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn resolution_failure(
465465
}
466466
};
467467
let attrs = &item.attrs;
468-
let sp = span_of_attrs(attrs);
468+
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
469469

470470
let mut diag = cx.tcx.struct_span_lint_hir(
471471
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
@@ -517,7 +517,7 @@ fn ambiguity_error(
517517
}
518518
};
519519
let attrs = &item.attrs;
520-
let sp = span_of_attrs(attrs);
520+
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
521521

522522
let mut msg = format!("`{}` is ", path_str);
523523

‎src/librustdoc/passes/mod.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
#![crate_type = "proc-macro"]
4+
#![crate_name="some_macros"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::TokenStream;
8+
9+
#[proc_macro_attribute]
10+
pub fn first(_attr: TokenStream, item: TokenStream) -> TokenStream {
11+
item // This doesn't erase the spans.
12+
}
13+
14+
#[proc_macro_attribute]
15+
pub fn second(_attr: TokenStream, item: TokenStream) -> TokenStream {
16+
// Make a new `TokenStream` to erase the spans:
17+
let mut out: TokenStream = TokenStream::new();
18+
out.extend(item);
19+
out
20+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// aux-build:through-proc-macro-aux.rs
2+
// build-aux-docs
3+
#![warn(intra_doc_link_resolution_failure)]
4+
extern crate some_macros;
5+
6+
#[some_macros::second]
7+
pub enum Boom {
8+
/// [Oooops]
9+
Bam,
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.