@@ -8,57 +8,51 @@ use std::sync::LazyLock;
8
8
use pulldown_cmark:: { Event , Parser , Tag } ;
9
9
use regex:: Regex ;
10
10
use rustc_errors:: Applicability ;
11
+ use rustc_hir:: HirId ;
11
12
use rustc_resolve:: rustdoc:: source_span_for_markdown_range;
12
13
use tracing:: trace;
13
14
14
15
use crate :: clean:: * ;
15
16
use crate :: core:: DocContext ;
16
17
use crate :: html:: markdown:: main_body_opts;
17
18
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
+ } ) ;
22
35
} ;
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
- } ;
41
36
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 ( ) ;
43
38
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 ;
57
50
}
51
+ _ => { }
58
52
}
59
53
}
60
- _ => { }
61
54
}
55
+ _ => { }
62
56
}
63
57
}
64
58
}
0 commit comments