@@ -8,57 +8,51 @@ use std::sync::LazyLock;
88use pulldown_cmark:: { Event , Parser , Tag } ;
99use regex:: Regex ;
1010use rustc_errors:: Applicability ;
11+ use rustc_hir:: HirId ;
1112use rustc_resolve:: rustdoc:: source_span_for_markdown_range;
1213use tracing:: trace;
1314
1415use crate :: clean:: * ;
1516use crate :: core:: DocContext ;
1617use crate :: html:: markdown:: main_body_opts;
1718
18- pub ( super ) fn visit_item ( cx : & DocContext < ' _ > , item : & Item ) {
19- let Some ( hir_id) = DocContext :: as_local_hir_id ( cx. tcx , item. item_id ) else {
20- // If non-local, no need to check anything.
21- return ;
19+ pub ( super ) fn visit_item ( cx : & DocContext < ' _ > , item : & Item , hir_id : HirId , dox : & str ) {
20+ let report_diag = |cx : & DocContext < ' _ > , msg : & ' static str , range : Range < usize > | {
21+ let sp = source_span_for_markdown_range ( cx. tcx , & dox, & range, & item. attrs . doc_strings )
22+ . unwrap_or_else ( || item. attr_span ( cx. tcx ) ) ;
23+ cx. tcx . node_span_lint ( crate :: lint:: BARE_URLS , hir_id, sp, |lint| {
24+ lint. primary_message ( msg)
25+ . note ( "bare URLs are not automatically turned into clickable links" )
26+ . multipart_suggestion (
27+ "use an automatic link instead" ,
28+ vec ! [
29+ ( sp. shrink_to_lo( ) , "<" . to_string( ) ) ,
30+ ( sp. shrink_to_hi( ) , ">" . to_string( ) ) ,
31+ ] ,
32+ Applicability :: MachineApplicable ,
33+ ) ;
34+ } ) ;
2235 } ;
23- let dox = item. doc_value ( ) ;
24- if !dox. is_empty ( ) {
25- let report_diag = |cx : & DocContext < ' _ > , msg : & ' static str , range : Range < usize > | {
26- let sp = source_span_for_markdown_range ( cx. tcx , & dox, & range, & item. attrs . doc_strings )
27- . unwrap_or_else ( || item. attr_span ( cx. tcx ) ) ;
28- cx. tcx . node_span_lint ( crate :: lint:: BARE_URLS , hir_id, sp, |lint| {
29- lint. primary_message ( msg)
30- . note ( "bare URLs are not automatically turned into clickable links" )
31- . multipart_suggestion (
32- "use an automatic link instead" ,
33- vec ! [
34- ( sp. shrink_to_lo( ) , "<" . to_string( ) ) ,
35- ( sp. shrink_to_hi( ) , ">" . to_string( ) ) ,
36- ] ,
37- Applicability :: MachineApplicable ,
38- ) ;
39- } ) ;
40- } ;
4136
42- let mut p = Parser :: new_ext ( & dox, main_body_opts ( ) ) . into_offset_iter ( ) ;
37+ let mut p = Parser :: new_ext ( & dox, main_body_opts ( ) ) . into_offset_iter ( ) ;
4338
44- while let Some ( ( event, range) ) = p. next ( ) {
45- match event {
46- Event :: Text ( s) => find_raw_urls ( cx, & s, range, & report_diag) ,
47- // We don't want to check the text inside code blocks or links.
48- Event :: Start ( tag @ ( Tag :: CodeBlock ( _) | Tag :: Link { .. } ) ) => {
49- while let Some ( ( event, _) ) = p. next ( ) {
50- match event {
51- Event :: End ( end)
52- if mem:: discriminant ( & end) == mem:: discriminant ( & tag. to_end ( ) ) =>
53- {
54- break ;
55- }
56- _ => { }
39+ while let Some ( ( event, range) ) = p. next ( ) {
40+ match event {
41+ Event :: Text ( s) => find_raw_urls ( cx, & s, range, & report_diag) ,
42+ // We don't want to check the text inside code blocks or links.
43+ Event :: Start ( tag @ ( Tag :: CodeBlock ( _) | Tag :: Link { .. } ) ) => {
44+ while let Some ( ( event, _) ) = p. next ( ) {
45+ match event {
46+ Event :: End ( end)
47+ if mem:: discriminant ( & end) == mem:: discriminant ( & tag. to_end ( ) ) =>
48+ {
49+ break ;
5750 }
51+ _ => { }
5852 }
5953 }
60- _ => { }
6154 }
55+ _ => { }
6256 }
6357 }
6458}
0 commit comments