1+ #![ feature( once_cell) ]
12#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
23#![ warn( rust_2018_idioms, unused_lifetimes) ]
34
45use std:: ffi:: OsStr ;
56use std:: path:: PathBuf ;
7+ use std:: sync:: LazyLock ;
68
79use regex:: RegexSet ;
810
@@ -14,43 +16,45 @@ struct Message {
1416
1517impl Message {
1618 fn new ( path : PathBuf ) -> Self {
17- let content: String = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
1819 // we don't want the first letter after "error: ", "help: " ... to be capitalized
1920 // 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+ } ) ;
3336
3437 // sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
3538 // 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 ( ) ;
4852
4953 let bad_lines = content
5054 . lines ( )
51- . filter ( |line| regex_set . matches ( line) . matched_any ( ) )
55+ . filter ( |line| REGEX_SET . matches ( line) . matched_any ( ) )
5256 // ignore exceptions
53- . filter ( |line| !exceptions_set . matches ( line) . matched_any ( ) )
57+ . filter ( |line| !EXCEPTIONS_SET . matches ( line) . matched_any ( ) )
5458 . map ( ToOwned :: to_owned)
5559 . collect :: < Vec < String > > ( ) ;
5660
0 commit comments