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
2122/// Error code markdown is restricted to 80 columns because they can be
@@ -41,6 +42,19 @@ C++ code used llvm_unreachable, which triggers undefined behavior
4142when executed when assertions are disabled.
4243Use llvm::report_fatal_error for increased robustness." ;
4344
45+ const ANNOTATIONS_TO_IGNORE : & [ & str ] = & [
46+ "// @!has" ,
47+ "// @has" ,
48+ "// @matches" ,
49+ "// CHECK" ,
50+ "// EMIT_MIR" ,
51+ "// compile-flags" ,
52+ "// error-pattern" ,
53+ "// gdb" ,
54+ "// lldb" ,
55+ "// normalize-stderr-test" ,
56+ ] ;
57+
4458/// Parser states for `line_is_url`.
4559#[ derive( Clone , Copy , PartialEq ) ]
4660#[ allow( non_camel_case_types) ]
@@ -92,12 +106,20 @@ fn line_is_url(is_error_code: bool, columns: usize, line: &str) -> bool {
92106 state == EXP_END
93107}
94108
109+ /// Returns `true` if `line` can be ignored. This is the case when it contains
110+ /// an annotation that is explicitly ignored.
111+ fn should_ignore ( line : & str ) -> bool {
112+ // Matches test annotations like `//~ ERROR text`.
113+ // This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
114+ // update both if either are changed.
115+ let re = Regex :: new ( "\\ s*//(\\ [.*\\ ])?~.*" ) . unwrap ( ) ;
116+ re. is_match ( line) || ANNOTATIONS_TO_IGNORE . iter ( ) . any ( |a| line. contains ( a) )
117+ }
118+
95119/// Returns `true` if `line` is allowed to be longer than the normal limit.
96- /// Currently there is only one exception, for long URLs, but more
97- /// may be added in the future.
98120fn long_line_is_ok ( extension : & str , is_error_code : bool , max_columns : usize , line : & str ) -> bool {
99121 if extension != "md" || is_error_code {
100- if line_is_url ( is_error_code, max_columns, line) {
122+ if line_is_url ( is_error_code, max_columns, line) || should_ignore ( line ) {
101123 return true ;
102124 }
103125 } else if extension == "md" {
@@ -357,9 +379,11 @@ pub fn check(path: &Path, bad: &mut bool) {
357379 if let Directive :: Ignore ( false ) = skip_tab {
358380 tidy_error ! ( bad, "{}: ignoring tab characters unnecessarily" , file. display( ) ) ;
359381 }
360- if let Directive :: Ignore ( false ) = skip_line_length {
361- tidy_error ! ( bad, "{}: ignoring line length unnecessarily" , file. display( ) ) ;
362- }
382+ // FIXME: Temporarily disabled to simplify landing the ignore-rules for the line
383+ // length check (https://github.com/rust-lang/rust/issues/77548):
384+ //if let Directive::Ignore(false) = skip_line_length {
385+ // tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display());
386+ //}
363387 if let Directive :: Ignore ( false ) = skip_file_length {
364388 tidy_error ! ( bad, "{}: ignoring file length unnecessarily" , file. display( ) ) ;
365389 }
0 commit comments