From 741553e55a6d44c4d86e6cd4bea3b82c92f04848 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 1 Mar 2022 12:06:52 +0100 Subject: [PATCH 1/2] Fix panic when intra-doc link comes from a generated doc comment --- src/librustdoc/passes/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 2c2bf2b8c0f19..5db2d0747c83b 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -178,7 +178,7 @@ crate fn source_span_for_markdown_range( 'outer: for (line_no, md_line) in md_lines.enumerate() { loop { - let source_line = src_lines.next().expect("could not find markdown in source"); + let source_line = src_lines.next()?; match source_line.find(md_line) { Some(offset) => { if line_no == starting_line { From 885e80854063e8ad4736aeb100c42230c9ef0a70 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 1 Mar 2022 12:07:17 +0100 Subject: [PATCH 2/2] Add test to ensure it does not panic when an intra-doc link is generated from a macro --- .../rustdoc-ui/auxiliary/module_macro_doc.rs | 1 + src/test/rustdoc-ui/macro-docs.rs | 12 +++++++++++ src/test/rustdoc-ui/macro-docs.stderr | 20 +++++++++++++++++++ src/test/rustdoc-ui/macro-docs.stdout | 0 4 files changed, 33 insertions(+) create mode 100644 src/test/rustdoc-ui/auxiliary/module_macro_doc.rs create mode 100644 src/test/rustdoc-ui/macro-docs.rs create mode 100644 src/test/rustdoc-ui/macro-docs.stderr create mode 100644 src/test/rustdoc-ui/macro-docs.stdout diff --git a/src/test/rustdoc-ui/auxiliary/module_macro_doc.rs b/src/test/rustdoc-ui/auxiliary/module_macro_doc.rs new file mode 100644 index 0000000000000..9d6b52b95a7ab --- /dev/null +++ b/src/test/rustdoc-ui/auxiliary/module_macro_doc.rs @@ -0,0 +1 @@ +//! [`long_cat`] is really long diff --git a/src/test/rustdoc-ui/macro-docs.rs b/src/test/rustdoc-ui/macro-docs.rs new file mode 100644 index 0000000000000..0e8472eb24270 --- /dev/null +++ b/src/test/rustdoc-ui/macro-docs.rs @@ -0,0 +1,12 @@ +// check-pass + +macro_rules! m { + () => { + /// A + //~^ WARNING + #[path = "auxiliary/module_macro_doc.rs"] + pub mod mymodule; + } +} + +m!(); diff --git a/src/test/rustdoc-ui/macro-docs.stderr b/src/test/rustdoc-ui/macro-docs.stderr new file mode 100644 index 0000000000000..e3cc1731146db --- /dev/null +++ b/src/test/rustdoc-ui/macro-docs.stderr @@ -0,0 +1,20 @@ +warning: unresolved link to `long_cat` + --> $DIR/macro-docs.rs:5:9 + | +LL | /// A + | ^^^^^ +... +LL | m!(); + | ---- in this macro invocation + | + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default + = note: the link appears in this line: + + [`long_cat`] is really long + ^^^^^^^^^^ + = note: no item named `long_cat` in scope + = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` + = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) + +warning: 1 warning emitted + diff --git a/src/test/rustdoc-ui/macro-docs.stdout b/src/test/rustdoc-ui/macro-docs.stdout new file mode 100644 index 0000000000000..e69de29bb2d1d