Skip to content

Commit 1bd4a0c

Browse files
Add new rustdoc broken_footnote lint
1 parent ac91805 commit 1bd4a0c

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/librustdoc/lint.rs

+8
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ declare_rustdoc_lint! {
204204
"detects markdown that is interpreted differently in different parser"
205205
}
206206

207+
declare_rustdoc_lint! {
208+
/// This lint checks for uses of footnote references without definition.
209+
BROKEN_FOOTNOTE,
210+
Warn,
211+
"footnote reference with no associated definition"
212+
}
213+
207214
pub(crate) static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
208215
vec![
209216
BROKEN_INTRA_DOC_LINKS,
@@ -218,6 +225,7 @@ pub(crate) static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
218225
UNESCAPED_BACKTICKS,
219226
REDUNDANT_EXPLICIT_LINKS,
220227
UNPORTABLE_MARKDOWN,
228+
BROKEN_FOOTNOTE,
221229
]
222230
});
223231

src/librustdoc/passes/lint/unportable_markdown.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,33 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &
117117
.map(|span| (span, true))
118118
.unwrap_or_else(|| (item.attr_span(tcx), false));
119119

120-
tcx.node_span_lint(crate::lint::UNPORTABLE_MARKDOWN, hir_id, ref_span, |lint| {
121-
lint.primary_message("unportable markdown");
122-
if precise {
120+
if precise {
121+
tcx.node_span_lint(crate::lint::BROKEN_FOOTNOTE, hir_id, ref_span, |lint| {
122+
lint.primary_message("no footnote definition matching this footnote");
123123
lint.span_suggestion(
124124
ref_span.shrink_to_lo(),
125125
"if it should not be a footnote, escape it",
126126
"\\",
127127
Applicability::MaybeIncorrect,
128128
);
129-
}
130-
if dox.as_bytes().get(span.end) == Some(&b'[') {
131-
lint.help("confusing footnote reference and link");
132-
if precise {
133-
lint.span_suggestion(
134-
ref_span.shrink_to_hi(),
135-
"if the footnote is intended, add a space",
136-
" ",
137-
Applicability::MaybeIncorrect,
138-
);
139-
} else {
140-
lint.help("there should be a space between the link and the footnote");
129+
});
130+
} else {
131+
tcx.node_span_lint(crate::lint::UNPORTABLE_MARKDOWN, hir_id, ref_span, |lint| {
132+
lint.primary_message("unportable markdown");
133+
if dox.as_bytes().get(span.end) == Some(&b'[') {
134+
lint.help("confusing footnote reference and link");
135+
if precise {
136+
lint.span_suggestion(
137+
ref_span.shrink_to_hi(),
138+
"if the footnote is intended, add a space",
139+
" ",
140+
Applicability::MaybeIncorrect,
141+
);
142+
} else {
143+
lint.help("there should be a space between the link and the footnote");
144+
}
141145
}
142-
}
143-
});
146+
});
147+
}
144148
}
145149
}

0 commit comments

Comments
 (0)