Skip to content

Commit 064796a

Browse files
committed
Tidy should not check line lengths
1 parent 4cbda82 commit 064796a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,8 @@ impl<'test> TestCx<'test> {
35343534

35353535
// Remove test annotations like `//~ ERROR text` from the output,
35363536
// since they duplicate actual errors and make the output hard to read.
3537+
// This mirrors the regex in src/tools/tidy/src/style.rs, please update
3538+
// both if either are changed.
35373539
normalized =
35383540
Regex::new("\\s*//(\\[.*\\])?~.*").unwrap().replace_all(&normalized, "").into_owned();
35393541

src/tools/tidy/src/style.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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;
1920
use std::path::Path;
2021

2122
const ERROR_CODE_COLS: usize = 80;
@@ -39,6 +40,19 @@ C++ code used llvm_unreachable, which triggers undefined behavior
3940
when executed when assertions are disabled.
4041
Use 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.
96120
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) {
98122
return true;
99123
}
100124

0 commit comments

Comments
 (0)