Rollup merge of #63930 - estebank:rustdoc-ice, r=GuillaumeGomez
Account for doc comments coming from proc macros without spans Fix https://github.com/rust-lang/rust/issues/63821.
This commit is contained in:
commit
d855bde457
5 changed files with 46 additions and 13 deletions
|
@ -81,7 +81,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
|
|||
// We couldn't calculate the span of the markdown block that had the error, so our
|
||||
// diagnostics are going to be a bit lacking.
|
||||
let mut diag = self.cx.sess().struct_span_warn(
|
||||
super::span_of_attrs(&item.attrs),
|
||||
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
|
||||
"doc comment contains an invalid Rust code block",
|
||||
);
|
||||
|
||||
|
|
|
@ -465,7 +465,7 @@ fn resolution_failure(
|
|||
}
|
||||
};
|
||||
let attrs = &item.attrs;
|
||||
let sp = span_of_attrs(attrs);
|
||||
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
|
||||
|
||||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
|
||||
|
@ -517,7 +517,7 @@ fn ambiguity_error(
|
|||
}
|
||||
};
|
||||
let attrs = &item.attrs;
|
||||
let sp = span_of_attrs(attrs);
|
||||
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
|
||||
|
||||
let mut msg = format!("`{}` is ", path_str);
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ pub fn look_for_tests<'tcx>(
|
|||
find_testable_code(&dox, &mut tests, ErrorCodes::No);
|
||||
|
||||
if check_missing_code == true && tests.found_tests == 0 {
|
||||
let sp = span_of_attrs(&item.attrs).substitute_dummy(item.source.span());
|
||||
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
|
||||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
|
||||
hir_id,
|
||||
|
@ -352,20 +352,23 @@ pub fn look_for_tests<'tcx>(
|
|||
let mut diag = cx.tcx.struct_span_lint_hir(
|
||||
lint::builtin::PRIVATE_DOC_TESTS,
|
||||
hir_id,
|
||||
span_of_attrs(&item.attrs),
|
||||
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
|
||||
"Documentation test in private item");
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a span encompassing all the given attributes.
|
||||
crate fn span_of_attrs(attrs: &clean::Attributes) -> Span {
|
||||
crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> {
|
||||
if attrs.doc_strings.is_empty() {
|
||||
return DUMMY_SP;
|
||||
return None;
|
||||
}
|
||||
let start = attrs.doc_strings[0].span();
|
||||
if start == DUMMY_SP {
|
||||
return None;
|
||||
}
|
||||
let end = attrs.doc_strings.last().expect("No doc strings provided").span();
|
||||
start.to(end)
|
||||
Some(start.to(end))
|
||||
}
|
||||
|
||||
/// 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(
|
|||
let snippet = cx
|
||||
.sess()
|
||||
.source_map()
|
||||
.span_to_snippet(span_of_attrs(attrs))
|
||||
.span_to_snippet(span_of_attrs(attrs)?)
|
||||
.ok()?;
|
||||
|
||||
let starting_line = markdown[..md_range.start].matches('\n').count();
|
||||
|
@ -441,10 +444,8 @@ crate fn source_span_for_markdown_range(
|
|||
}
|
||||
}
|
||||
|
||||
let sp = span_of_attrs(attrs).from_inner(InnerSpan::new(
|
||||
Some(span_of_attrs(attrs)?.from_inner(InnerSpan::new(
|
||||
md_range.start + start_bytes,
|
||||
md_range.end + start_bytes + end_bytes,
|
||||
));
|
||||
|
||||
Some(sp)
|
||||
)))
|
||||
}
|
||||
|
|
20
src/test/rustdoc/auxiliary/through-proc-macro-aux.rs
Normal file
20
src/test/rustdoc/auxiliary/through-proc-macro-aux.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// force-host
|
||||
// no-prefer-dynamic
|
||||
#![crate_type = "proc-macro"]
|
||||
#![crate_name="some_macros"]
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn first(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
item // This doesn't erase the spans.
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn second(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
// Make a new `TokenStream` to erase the spans:
|
||||
let mut out: TokenStream = TokenStream::new();
|
||||
out.extend(item);
|
||||
out
|
||||
}
|
12
src/test/rustdoc/through-proc-macro.rs
Normal file
12
src/test/rustdoc/through-proc-macro.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
// aux-build:through-proc-macro-aux.rs
|
||||
// build-aux-docs
|
||||
#![warn(intra_doc_link_resolution_failure)]
|
||||
extern crate some_macros;
|
||||
|
||||
#[some_macros::second]
|
||||
pub enum Boom {
|
||||
/// [Oooops]
|
||||
Bam,
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue