From d2d15fe60ee88a07cc269fe1b25df670a266cc0c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 19 Mar 2023 18:01:52 +0100 Subject: [PATCH 1/2] Remove footnote references from doc summary --- src/librustdoc/html/markdown.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index fe446ae3c16..fd81a21f5a9 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -556,7 +556,15 @@ fn check_if_allowed_tag(t: &Tag<'_>) -> bool { } fn is_forbidden_tag(t: &Tag<'_>) -> bool { - matches!(t, Tag::CodeBlock(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell) + matches!( + t, + Tag::CodeBlock(_) + | Tag::Table(_) + | Tag::TableHead + | Tag::TableRow + | Tag::TableCell + | Tag::FootnoteDefinition(_) + ) } impl<'a, I: Iterator>> Iterator for SummaryLine<'a, I> { @@ -589,6 +597,10 @@ impl<'a, I: Iterator>> Iterator for SummaryLine<'a, I> { is_start = false; check_if_allowed_tag(c) } + Event::FootnoteReference(_) => { + self.skipped_tags += 1; + false + } _ => true, }; if !is_allowed_tag { From 5a752cd2ca4378cf86831292fdf601636167554c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 19 Mar 2023 18:02:11 +0100 Subject: [PATCH 2/2] Add test for footnote references in doc summary --- tests/rustdoc/footnote-in-summary.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/rustdoc/footnote-in-summary.rs diff --git a/tests/rustdoc/footnote-in-summary.rs b/tests/rustdoc/footnote-in-summary.rs new file mode 100644 index 00000000000..e6ff5a7fd51 --- /dev/null +++ b/tests/rustdoc/footnote-in-summary.rs @@ -0,0 +1,17 @@ +// This test ensures that no footnote reference is generated inside +// summary doc. + +#![crate_name = "foo"] + +// @has 'foo/index.html' +// @has - '//*[@class="desc docblock-short"]' 'hello bla' +// @!has - '//*[@class="desc docblock-short"]/sup' '1' + +// @has 'foo/struct.S.html' +// @has - '//*[@class="docblock"]//sup' '1' +// @has - '//*[@class="docblock"]' 'hello 1 bla' + +/// hello [^foot] bla +/// +/// [^foot]: blabla +pub struct S;