Skip to content

Commit 1fbabc6

Browse files
committed
Include the line number in tidy's iter_header
1 parent ee9a9f8 commit 1fbabc6

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/tools/tidy/src/iter_header.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const COMMENT: &str = "//@";
33
/// A header line, like `//@name: value` consists of the prefix `//@` and the directive
44
/// `name: value`. It is also possibly revisioned, e.g. `//@[revision] name: value`.
55
pub(crate) struct HeaderLine<'ln> {
6+
pub(crate) line_number: usize,
67
pub(crate) revision: Option<&'ln str>,
78
pub(crate) directive: &'ln str,
89
}
@@ -11,7 +12,7 @@ pub(crate) struct HeaderLine<'ln> {
1112
///
1213
/// Adjusted from compiletest/src/header.rs.
1314
pub(crate) fn iter_header<'ln>(contents: &'ln str, it: &mut dyn FnMut(HeaderLine<'ln>)) {
14-
for ln in contents.lines() {
15+
for (line_number, ln) in (1..).zip(contents.lines()) {
1516
let ln = ln.trim();
1617

1718
// We're left with potentially `[rev]name: value`.
@@ -24,9 +25,9 @@ pub(crate) fn iter_header<'ln>(contents: &'ln str, it: &mut dyn FnMut(HeaderLine
2425
panic!("malformed revision directive: expected `//@[rev]`, found `{ln}`");
2526
};
2627
// We trimmed off the `[rev]` portion, left with `name: value`.
27-
it(HeaderLine { revision: Some(revision), directive: remainder.trim() });
28+
it(HeaderLine { line_number, revision: Some(revision), directive: remainder.trim() });
2829
} else {
29-
it(HeaderLine { revision: None, directive: remainder.trim() });
30+
it(HeaderLine { line_number, revision: None, directive: remainder.trim() });
3031
}
3132
}
3233
}

src/tools/tidy/src/target_specific_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn check(path: &Path, bad: &mut bool) {
2020
crate::walk::walk(path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
2121
let file = entry.path().display();
2222
let mut header_map = BTreeMap::new();
23-
iter_header(content, &mut |HeaderLine { revision, directive }| {
23+
iter_header(content, &mut |HeaderLine { revision, directive, .. }| {
2424
if let Some(value) = directive.strip_prefix(LLVM_COMPONENTS_HEADER) {
2525
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
2626
let comp_vec = info.llvm_components.get_or_insert(Vec::new());

src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) {
6161
let contents = std::fs::read_to_string(test).unwrap();
6262

6363
// Collect directives.
64-
iter_header(&contents, &mut |HeaderLine { revision, directive }| {
64+
iter_header(&contents, &mut |HeaderLine { revision, directive, .. }| {
6565
// We're trying to *find* `//@ revision: xxx` directives themselves, not revisioned
6666
// directives.
6767
if revision.is_some() {

0 commit comments

Comments
 (0)