1616//! A number of these checks can be opted-out of with various directives of the form:
1717//! `// ignore-tidy-CHECK-NAME`.
1818
19+ use regex:: Regex ;
1920use std:: path:: Path ;
2021
2122const ERROR_CODE_COLS : usize = 80 ;
@@ -39,6 +40,19 @@ C++ code used llvm_unreachable, which triggers undefined behavior
3940when executed when assertions are disabled.
4041Use llvm::report_fatal_error for increased robustness." ;
4142
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+
4256/// Parser states for `line_is_url`.
4357#[ derive( Clone , Copy , PartialEq ) ]
4458#[ allow( non_camel_case_types) ]
@@ -90,11 +104,21 @@ fn line_is_url(columns: usize, line: &str) -> bool {
90104 state == EXP_END
91105}
92106
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+
93117/// 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 .
96120fn 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 ) {
98122 return true ;
99123 }
100124
0 commit comments