Skip to content

Commit 8fc4994

Browse files
committed
Temporary change to confirm with code reviewer the next steps
1 parent f29b4e3 commit 8fc4994

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

clippy_lints/src/doc/broken_link.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use clippy_utils::diagnostics::span_lint;
2+
use pulldown_cmark::BrokenLink as PullDownBrokenLink;
23
use rustc_ast::{AttrKind, AttrStyle, Attribute};
34
use rustc_lint::LateContext;
5+
use rustc_resolve::rustdoc::DocFragment;
46
use rustc_span::{BytePos, Span};
57

68
use super::DOC_BROKEN_LINK;
@@ -9,6 +11,19 @@ pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
911
BrokenLinkReporter::warn_if_broken_links(cx, attrs);
1012
}
1113

14+
// NOTE: temporary change to check if we can handle broken links from pulldown_cmark parser.
15+
pub fn check_v2(_cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &String, fragments: &Vec<DocFragment>) {
16+
log(format!("\n ---------------------",).as_str());
17+
log(format!("\n doc={doc:#?}",).as_str());
18+
log(format!("\n fragments={fragments:#?}",).as_str());
19+
20+
log(format!("\n bl={bl:#?}",).as_str());
21+
22+
let text: String = doc[bl.span.clone()].chars().collect();
23+
log(format!("\n text based on 'bl.span' range={text:#?}",).as_str());
24+
log(format!("\n ---------------------",).as_str());
25+
}
26+
1227
/// The reason why a link is considered broken.
1328
// NOTE: We don't check these other cases because
1429
// rustdoc itself will check and warn about it:
@@ -155,3 +170,16 @@ impl BrokenLinkReporter {
155170
}
156171
}
157172
}
173+
174+
// TODO: remove this helper function once all changes are good.
175+
fn log(text: &str) {
176+
use std::fs::OpenOptions;
177+
use std::io::Write;
178+
179+
let filename = "../rust-clippy-debug-test.txt";
180+
let mut file = OpenOptions::new().write(true).append(true).open(filename).unwrap();
181+
182+
if let Err(e) = writeln!(file, "{text}") {
183+
eprintln!("Couldn't write to file: {}", e);
184+
}
185+
}

clippy_lints/src/doc/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,6 @@ struct DocHeaders {
712712
/// back in the various late lint pass methods if they need the final doc headers, like "Safety" or
713713
/// "Panics" sections.
714714
fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[Attribute]) -> Option<DocHeaders> {
715-
/// We don't want the parser to choke on intra doc links. Since we don't
716-
/// actually care about rendering them, just pretend that all broken links
717-
/// point to a fake address.
718-
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
719-
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
720-
Some(("fake".into(), "fake".into()))
721-
}
722-
723715
if suspicious_doc_comments::check(cx, attrs) || empty_line_after::check(cx, attrs) || is_doc_hidden(attrs) {
724716
return None;
725717
}
@@ -757,6 +749,17 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
757749
// Run broken link checker before parsing the document.
758750
broken_link::check(cx, attrs);
759751

752+
// We don't want the parser to choke on intra doc links. Since we don't
753+
// actually care about rendering them, just pretend that all broken links
754+
// point to a fake address.
755+
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
756+
let fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
757+
// NOTE: temporary change to check if we can handle broken links report from
758+
// this function.
759+
broken_link::check_v2(cx, &bl, &doc, &fragments);
760+
Some(("fake".into(), "fake".into()))
761+
};
762+
760763
let mut cb = fake_broken_link_callback;
761764

762765
// disable smart punctuation to pick up ['link'] more easily

0 commit comments

Comments
 (0)