Skip to content

Commit f29cc5d

Browse files
maxcnunesmaxclaus
authored andcommitted
Temporary change to confirm with code reviewer the next steps
1 parent baba9fc commit f29cc5d

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,6 @@ 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-
792784
if suspicious_doc_comments::check(cx, attrs) || is_doc_hidden(attrs) {
793785
return None;
794786
}
@@ -823,8 +815,19 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
823815
return Some(DocHeaders::default());
824816
}
825817

826-
// Run broken link checker before parsing the document.
827-
broken_link::check(cx, attrs);
818+
// // Run broken link checker before parsing the document.
819+
// broken_link::check(cx, attrs);
820+
821+
// We don't want the parser to choke on intra doc links. Since we don't
822+
// actually care about rendering them, just pretend that all broken links
823+
// point to a fake address.
824+
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
825+
let fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
826+
// NOTE: temporary change to check if we can handle broken links report from
827+
// this function.
828+
broken_link::check_v2(cx, &bl, &doc, &fragments);
829+
Some(("fake".into(), "fake".into()))
830+
};
828831

829832
let mut cb = fake_broken_link_callback;
830833

tests/ui/doc_broken_link.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)