16
16
//! A number of these checks can be opted-out of with various directives of the form:
17
17
//! `// ignore-tidy-CHECK-NAME`.
18
18
19
+ use regex:: Regex ;
19
20
use std:: path:: Path ;
20
21
21
22
const ERROR_CODE_COLS : usize = 80 ;
@@ -39,6 +40,19 @@ C++ code used llvm_unreachable, which triggers undefined behavior
39
40
when executed when assertions are disabled.
40
41
Use llvm::report_fatal_error for increased robustness." ;
41
42
43
+ const ANNOTATIONS_TO_IGNORE : & [ & str ] = & [
44
+ "// @!has" ,
45
+ "// @has" ,
46
+ "// @matches" ,
47
+ "// CHECK" ,
48
+ "// EMIT_MIR" ,
49
+ "// compile-flags" ,
50
+ "// error-pattern" ,
51
+ "// gdb" ,
52
+ "// lldb" ,
53
+ "// normalize-stderr-test" ,
54
+ ] ;
55
+
42
56
/// Parser states for `line_is_url`.
43
57
#[ derive( Clone , Copy , PartialEq ) ]
44
58
#[ allow( non_camel_case_types) ]
@@ -90,11 +104,21 @@ fn line_is_url(columns: usize, line: &str) -> bool {
90
104
state == EXP_END
91
105
}
92
106
107
+ /// Returns `true` if `line` can be ignored. This is the case when it contains
108
+ /// an annotation that is explicitly ignored.
109
+ fn should_ignore ( line : & str ) -> bool {
110
+ // Matches test annotations like `//~ ERROR text`.
111
+ // This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
112
+ // update both if either are changed.
113
+ let re = Regex :: new ( "\\ s*//(\\ [.*\\ ])?~.*" ) . unwrap ( ) ;
114
+ re. is_match ( line) || ANNOTATIONS_TO_IGNORE . iter ( ) . any ( |a| line. contains ( a) )
115
+ }
116
+
93
117
/// Returns `true` if `line` is allowed to be longer than the normal limit.
94
- /// Currently there is only one exception, for long URLs, but more
95
- /// may be added in the future .
118
+ /// This is the case when the `line` is a long URL, or it contains an
119
+ /// annotation that is explicitly ignored .
96
120
fn long_line_is_ok ( max_columns : usize , line : & str ) -> bool {
97
- if line_is_url ( max_columns, line) {
121
+ if line_is_url ( max_columns, line) || should_ignore ( line ) {
98
122
return true ;
99
123
}
100
124
0 commit comments