Skip to content

Commit bd214be

Browse files
committed
Fix linter
1 parent f577d71 commit bd214be

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

clippy_lints/src/doc/broken_link.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ use rustc_span::{BytePos, Pos, Span};
77
use super::DOC_BROKEN_LINK;
88

99
/// Scan and report broken link on documents.
10-
/// It ignores false positives detected by pulldown_cmark, and only
10+
/// It ignores false positives detected by `pulldown_cmark`, and only
1111
/// warns users when the broken link is consider a URL.
1212
// NOTE: We don't check these other cases because
1313
// rustdoc itself will check and warn about it:
1414
// - When a link url is broken across multiple lines in the URL path part
1515
// - When a link tag is missing the close parenthesis character at the end.
1616
// - When a link has whitespace within the url link.
17-
pub fn check(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &String, fragments: &Vec<DocFragment>) {
17+
pub fn check(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragments: &[DocFragment]) {
1818
warn_if_broken_link(cx, bl, doc, fragments);
1919
}
2020

21-
fn warn_if_broken_link(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &String, fragments: &Vec<DocFragment>) {
21+
fn warn_if_broken_link(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragments: &[DocFragment]) {
2222
if let Some(span) = source_span_for_markdown_range(cx.tcx, doc, &bl.span, fragments) {
2323
let mut len = 0;
2424

clippy_lints/src/doc/mod.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ struct DocHeaders {
781781
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
782782
/// "Panics" sections.
783783
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
784+
// We don't want the parser to choke on intra doc links. Since we don't
785+
// actually care about rendering them, just pretend that all broken links
786+
// point to a fake address.
787+
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
788+
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
789+
Some(("fake".into(), "fake".into()))
790+
}
791+
784792
if suspicious_doc_comments::check(cx, attrs) || is_doc_hidden(attrs) {
785793
return None;
786794
}
@@ -815,30 +823,12 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
815823
return Some(DocHeaders::default());
816824
}
817825

818-
// We don't want the parser to choke on intra doc links. Since we don't
819-
// actually care about rendering them, just pretend that all broken links
820-
// point to a fake address.
821-
// NOTE: use this full cb version only for the check_doc function.
822-
// Otherwise, using it as callback for more functions will cause,
823-
// duplicated diagnostics for the broken link checker.
824-
// Use the light cb version for the other cases.
825-
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
826-
let mut full_fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
827-
broken_link::check(cx, &bl, &doc, &fragments);
828-
Some(("fake".into(), "fake".into()))
829-
};
830-
831-
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
832-
fn light_fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
833-
Some(("fake".into(), "fake".into()))
834-
}
835-
836826
check_for_code_clusters(
837827
cx,
838828
pulldown_cmark::Parser::new_with_broken_link_callback(
839829
&doc,
840830
main_body_opts() - Options::ENABLE_SMART_PUNCTUATION,
841-
Some(&mut light_fake_broken_link_callback),
831+
Some(&mut fake_broken_link_callback),
842832
)
843833
.into_offset_iter(),
844834
&doc,
@@ -848,6 +838,13 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
848838
},
849839
);
850840

841+
// NOTE: check_doc uses it own cb function,
842+
// to avoid causing duplicated diagnostics for the broken link checker.
843+
let mut full_fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
844+
broken_link::check(cx, &bl, &doc, &fragments);
845+
Some(("fake".into(), "fake".into()))
846+
};
847+
851848
// disable smart punctuation to pick up ['link'] more easily
852849
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
853850
let parser =

0 commit comments

Comments
 (0)