Skip to content

Commit ccd9975

Browse files
committed
Auto merge of #83549 - sjakobi:no-tidy-line-length-1, r=Mark-Simulacrum
tidy: Add ignore-rules for the line length check This is step 1 towards fixing #77548. This PR contains the `tidy` change from #77675. The "ignoring file length unnecessarily" check is temporarily disabled to simplify landing the ignore-rules. This check will be re-enabled in a follow-up PR.
2 parents 836c317 + c35a36f commit ccd9975

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/tools/compiletest/src/runtest.rs

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

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

src/tools/tidy/src/style.rs

+30-6
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
/// 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
4142
when executed when assertions are disabled.
4243
Use 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.
98120
fn 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

Comments
 (0)