@@ -10,9 +10,9 @@ use rustc_errors::Applicability;
10
10
use rustc_feature:: UnstableFeatures ;
11
11
use rustc_session:: lint;
12
12
13
- pub const CHECK_URL_IMPROVEMENTS : Pass = Pass {
14
- name : "check-url-improvements " ,
15
- run : check_url_improvements ,
13
+ pub const CHECK_NON_AUTOLINKS : Pass = Pass {
14
+ name : "check-non-autolinks " ,
15
+ run : check_non_autolinks ,
16
16
description : "detects URLS that could be written using angle brackets" ,
17
17
} ;
18
18
@@ -23,14 +23,14 @@ const URL_REGEX: &str = concat!(
23
23
r"\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)" // optional query or url fragments
24
24
) ;
25
25
26
- struct UrlImprovementsLinter < ' a , ' tcx > {
26
+ struct NonAutolinksLinter < ' a , ' tcx > {
27
27
cx : & ' a DocContext < ' tcx > ,
28
28
regex : Regex ,
29
29
}
30
30
31
- impl < ' a , ' tcx > UrlImprovementsLinter < ' a , ' tcx > {
31
+ impl < ' a , ' tcx > NonAutolinksLinter < ' a , ' tcx > {
32
32
fn new ( cx : & ' a DocContext < ' tcx > ) -> Self {
33
- UrlImprovementsLinter { cx, regex : Regex :: new ( URL_REGEX ) . expect ( "failed to build regex" ) }
33
+ Self { cx, regex : Regex :: new ( URL_REGEX ) . expect ( "failed to build regex" ) }
34
34
}
35
35
36
36
fn find_raw_urls (
@@ -53,17 +53,17 @@ impl<'a, 'tcx> UrlImprovementsLinter<'a, 'tcx> {
53
53
}
54
54
}
55
55
56
- pub fn check_url_improvements ( krate : Crate , cx : & DocContext < ' _ > ) -> Crate {
56
+ pub fn check_non_autolinks ( krate : Crate , cx : & DocContext < ' _ > ) -> Crate {
57
57
if !UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) {
58
58
krate
59
59
} else {
60
- let mut coll = UrlImprovementsLinter :: new ( cx) ;
60
+ let mut coll = NonAutolinksLinter :: new ( cx) ;
61
61
62
62
coll. fold_crate ( krate)
63
63
}
64
64
}
65
65
66
- impl < ' a , ' tcx > DocFolder for UrlImprovementsLinter < ' a , ' tcx > {
66
+ impl < ' a , ' tcx > DocFolder for NonAutolinksLinter < ' a , ' tcx > {
67
67
fn fold_item ( & mut self , item : Item ) -> Option < Item > {
68
68
let hir_id = match self . cx . as_local_hir_id ( item. def_id ) {
69
69
Some ( hir_id) => hir_id,
@@ -78,7 +78,7 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
78
78
let sp = super :: source_span_for_markdown_range ( cx, & dox, & range, & item. attrs )
79
79
. or_else ( || span_of_attrs ( & item. attrs ) )
80
80
. unwrap_or ( item. source . span ( ) ) ;
81
- cx. tcx . struct_span_lint_hir ( lint:: builtin:: URL_IMPROVEMENTS , hir_id, sp, |lint| {
81
+ cx. tcx . struct_span_lint_hir ( lint:: builtin:: NON_AUTOLINKS , hir_id, sp, |lint| {
82
82
lint. build ( msg)
83
83
. span_suggestion (
84
84
sp,
@@ -103,7 +103,8 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
103
103
Event :: End ( Tag :: Link ( _, url, _) ) => {
104
104
// NOTE: links cannot be nested, so we don't need to
105
105
// check `kind`
106
- if url. as_ref ( ) == title && !ignore && self . regex . matches ( url) {
106
+ if url. as_ref ( ) == title && !ignore && self . regex . is_match ( & url)
107
+ {
107
108
report_diag (
108
109
self . cx ,
109
110
"unneeded long form for URL" ,
0 commit comments