1
+ #![ feature( once_cell) ]
1
2
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
2
3
#![ warn( rust_2018_idioms, unused_lifetimes) ]
3
4
4
5
use std:: ffi:: OsStr ;
5
6
use std:: path:: PathBuf ;
7
+ use std:: sync:: LazyLock ;
6
8
7
9
use regex:: RegexSet ;
8
10
@@ -14,43 +16,45 @@ struct Message {
14
16
15
17
impl Message {
16
18
fn new ( path : PathBuf ) -> Self {
17
- let content: String = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
18
19
// we don't want the first letter after "error: ", "help: " ... to be capitalized
19
20
// also no punctuation (except for "?" ?) at the end of a line
20
- let regex_set: RegexSet = RegexSet :: new ( & [
21
- r"error: [A-Z]" ,
22
- r"help: [A-Z]" ,
23
- r"warning: [A-Z]" ,
24
- r"note: [A-Z]" ,
25
- r"try this: [A-Z]" ,
26
- r"error: .*[.!]$" ,
27
- r"help: .*[.!]$" ,
28
- r"warning: .*[.!]$" ,
29
- r"note: .*[.!]$" ,
30
- r"try this: .*[.!]$" ,
31
- ] )
32
- . unwrap ( ) ;
21
+ static REGEX_SET : LazyLock < RegexSet > = LazyLock :: new ( || {
22
+ RegexSet :: new ( & [
23
+ r"error: [A-Z]" ,
24
+ r"help: [A-Z]" ,
25
+ r"warning: [A-Z]" ,
26
+ r"note: [A-Z]" ,
27
+ r"try this: [A-Z]" ,
28
+ r"error: .*[.!]$" ,
29
+ r"help: .*[.!]$" ,
30
+ r"warning: .*[.!]$" ,
31
+ r"note: .*[.!]$" ,
32
+ r"try this: .*[.!]$" ,
33
+ ] )
34
+ . unwrap ( )
35
+ } ) ;
33
36
34
37
// sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
35
38
// we want to ask a question ending in "?"
36
- let exceptions_set: RegexSet = RegexSet :: new ( & [
37
- r".*C-like enum variant discriminant is not portable to 32-bit targets" ,
38
- r".*did you mean `unix`?" ,
39
- r".*the arguments may be inverted..." ,
40
- r".*Intel x86 assembly syntax used" ,
41
- r".*AT&T x86 assembly syntax used" ,
42
- r".*remove .*the return type..." ,
43
- r"note: Clippy version: .*" ,
44
- r"the compiler unexpectedly panicked. this is a bug." ,
45
- r"remove the `if let` statement in the for loop and then..." ,
46
- ] )
47
- . unwrap ( ) ;
39
+ static EXCEPTIONS_SET : LazyLock < RegexSet > = LazyLock :: new ( || {
40
+ RegexSet :: new ( & [
41
+ r"\.\.\.$" ,
42
+ r".*C-like enum variant discriminant is not portable to 32-bit targets" ,
43
+ r".*Intel x86 assembly syntax used" ,
44
+ r".*AT&T x86 assembly syntax used" ,
45
+ r"note: Clippy version: .*" ,
46
+ r"the compiler unexpectedly panicked. this is a bug." ,
47
+ ] )
48
+ . unwrap ( )
49
+ } ) ;
50
+
51
+ let content: String = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
48
52
49
53
let bad_lines = content
50
54
. lines ( )
51
- . filter ( |line| regex_set . matches ( line) . matched_any ( ) )
55
+ . filter ( |line| REGEX_SET . matches ( line) . matched_any ( ) )
52
56
// ignore exceptions
53
- . filter ( |line| !exceptions_set . matches ( line) . matched_any ( ) )
57
+ . filter ( |line| !EXCEPTIONS_SET . matches ( line) . matched_any ( ) )
54
58
. map ( ToOwned :: to_owned)
55
59
. collect :: < Vec < String > > ( ) ;
56
60
0 commit comments