Skip to content

Commit 10323f8

Browse files
Correctly handle "escaped footnotes"
1 parent 5deff4b commit 10323f8

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎src/librustdoc/passes/lint/footnotes.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &
2323
match event {
2424
Event::Text(text)
2525
if &*text == "["
26-
&& let Some((Event::Text(text), _)) = parser.peek()
27-
&& text.trim_start().starts_with('^')
26+
&& let Some((Event::Text(_), range)) = parser.peek()
27+
// Because the `\` is removed from the range, we need to use the end of the
28+
// previous range to get all the potentially missing characters.
29+
&& let text = &dox[Range { start: span.end, end: range.end }]
30+
&& text.starts_with('^')
2831
&& parser.next().is_some()
2932
&& let Some((Event::Text(text), end_span)) = parser.peek()
33+
// Because the `\` is removed from the range, we need to wait until we have the
34+
// `]` span so we can include all the potentially missing characters.
35+
&& !dox[Range { start: span.end, end: end_span.start }].ends_with('\\')
3036
&& &**text == "]" =>
3137
{
3238
missing_footnote_references.insert(Range { start: span.start, end: end_span.end });

‎tests/rustdoc-ui/lints/broken-footnote.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
//! [^1]: footnote defined
66
//~^^^ ERROR: no footnote definition matching this footnote
77
//~| ERROR: no footnote definition matching this footnote
8+
9+
// Backslash escaped footnotes should not be recognized:
10+
//! [\^4]
11+
//!
12+
//! [^5\]
13+
//!
14+
//! \[^yup]
15+
//!
16+
//! [^foo\
17+
//! bar]

0 commit comments

Comments
 (0)