11use clippy_utils:: diagnostics:: span_lint;
2+ use pulldown_cmark:: BrokenLink as PullDownBrokenLink ;
23use rustc_ast:: { AttrKind , AttrStyle , Attribute } ;
34use rustc_lint:: LateContext ;
5+ use rustc_resolve:: rustdoc:: DocFragment ;
46use rustc_span:: { BytePos , Span } ;
57
68use 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+ }
0 commit comments