@@ -6,7 +6,7 @@ use std::mem;
66use std:: sync:: LazyLock ;
77
88use regex:: Regex ;
9- use rustc_errors:: Applicability ;
9+ use rustc_errors:: { Applicability , DiagDecorator } ;
1010use rustc_hir:: HirId ;
1111use rustc_resolve:: rustdoc:: pulldown_cmark:: { Event , Parser , Tag } ;
1212use rustc_resolve:: rustdoc:: source_span_for_markdown_range;
@@ -24,30 +24,35 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &
2424 let maybe_sp = source_span_for_markdown_range ( cx. tcx , dox, & range, & item. attrs . doc_strings )
2525 . map ( |( sp, _) | sp) ;
2626 let sp = maybe_sp. unwrap_or_else ( || item. attr_span ( cx. tcx ) ) ;
27- cx. tcx . node_span_lint ( crate :: lint:: BARE_URLS , hir_id, sp, |lint| {
28- lint. primary_message ( msg)
29- . note ( "bare URLs are not automatically turned into clickable links" ) ;
30- // The fallback of using the attribute span is suitable for
31- // highlighting where the error is, but not for placing the < and >
32- if let Some ( sp) = maybe_sp {
33- if let Some ( without_brackets) = without_brackets {
34- lint. multipart_suggestion (
35- "use an automatic link instead" ,
36- vec ! [ ( sp, format!( "<{without_brackets}>" ) ) ] ,
37- Applicability :: MachineApplicable ,
38- ) ;
39- } else {
40- lint. multipart_suggestion (
41- "use an automatic link instead" ,
42- vec ! [
43- ( sp. shrink_to_lo( ) , "<" . to_string( ) ) ,
44- ( sp. shrink_to_hi( ) , ">" . to_string( ) ) ,
45- ] ,
46- Applicability :: MachineApplicable ,
47- ) ;
27+ cx. tcx . emit_node_span_lint (
28+ crate :: lint:: BARE_URLS ,
29+ hir_id,
30+ sp,
31+ DiagDecorator ( |lint| {
32+ lint. primary_message ( msg)
33+ . note ( "bare URLs are not automatically turned into clickable links" ) ;
34+ // The fallback of using the attribute span is suitable for
35+ // highlighting where the error is, but not for placing the < and >
36+ if let Some ( sp) = maybe_sp {
37+ if let Some ( without_brackets) = without_brackets {
38+ lint. multipart_suggestion (
39+ "use an automatic link instead" ,
40+ vec ! [ ( sp, format!( "<{without_brackets}>" ) ) ] ,
41+ Applicability :: MachineApplicable ,
42+ ) ;
43+ } else {
44+ lint. multipart_suggestion (
45+ "use an automatic link instead" ,
46+ vec ! [
47+ ( sp. shrink_to_lo( ) , "<" . to_string( ) ) ,
48+ ( sp. shrink_to_hi( ) , ">" . to_string( ) ) ,
49+ ] ,
50+ Applicability :: MachineApplicable ,
51+ ) ;
52+ }
4853 }
49- }
50- } ) ;
54+ } ) ,
55+ ) ;
5156 } ;
5257
5358 let mut p = Parser :: new_ext ( dox, main_body_opts ( ) ) . into_offset_iter ( ) ;
0 commit comments