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
/// 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
41
42
when executed when assertions are disabled.
42
43
Use llvm::report_fatal_error for increased robustness." ;
43
44
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
+
44
58
/// Parser states for `line_is_url`.
45
59
#[ derive( Clone , Copy , PartialEq ) ]
46
60
#[ allow( non_camel_case_types) ]
@@ -92,12 +106,20 @@ fn line_is_url(is_error_code: bool, columns: usize, line: &str) -> bool {
92
106
state == EXP_END
93
107
}
94
108
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
+
95
119
/// 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.
98
120
fn long_line_is_ok ( extension : & str , is_error_code : bool , max_columns : usize , line : & str ) -> bool {
99
121
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 ) {
101
123
return true ;
102
124
}
103
125
} else if extension == "md" {
@@ -357,9 +379,11 @@ pub fn check(path: &Path, bad: &mut bool) {
357
379
if let Directive :: Ignore ( false ) = skip_tab {
358
380
tidy_error ! ( bad, "{}: ignoring tab characters unnecessarily" , file. display( ) ) ;
359
381
}
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
+ //}
363
387
if let Directive :: Ignore ( false ) = skip_file_length {
364
388
tidy_error ! ( bad, "{}: ignoring file length unnecessarily" , file. display( ) ) ;
365
389
}
0 commit comments