Include the line number in tidy's iter_header
This commit is contained in:
parent
ee9a9f84c5
commit
1fbabc622f
@ -3,6 +3,7 @@
|
||||
/// A header line, like `//@name: value` consists of the prefix `//@` and the directive
|
||||
/// `name: value`. It is also possibly revisioned, e.g. `//@[revision] name: value`.
|
||||
pub(crate) struct HeaderLine<'ln> {
|
||||
pub(crate) line_number: usize,
|
||||
pub(crate) revision: Option<&'ln str>,
|
||||
pub(crate) directive: &'ln str,
|
||||
}
|
||||
@ -11,7 +12,7 @@ pub(crate) struct HeaderLine<'ln> {
|
||||
///
|
||||
/// Adjusted from compiletest/src/header.rs.
|
||||
pub(crate) fn iter_header<'ln>(contents: &'ln str, it: &mut dyn FnMut(HeaderLine<'ln>)) {
|
||||
for ln in contents.lines() {
|
||||
for (line_number, ln) in (1..).zip(contents.lines()) {
|
||||
let ln = ln.trim();
|
||||
|
||||
// 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
|
||||
panic!("malformed revision directive: expected `//@[rev]`, found `{ln}`");
|
||||
};
|
||||
// We trimmed off the `[rev]` portion, left with `name: value`.
|
||||
it(HeaderLine { revision: Some(revision), directive: remainder.trim() });
|
||||
it(HeaderLine { line_number, revision: Some(revision), directive: remainder.trim() });
|
||||
} else {
|
||||
it(HeaderLine { revision: None, directive: remainder.trim() });
|
||||
it(HeaderLine { line_number, revision: None, directive: remainder.trim() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
crate::walk::walk(path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
|
||||
let file = entry.path().display();
|
||||
let mut header_map = BTreeMap::new();
|
||||
iter_header(content, &mut |HeaderLine { revision, directive }| {
|
||||
iter_header(content, &mut |HeaderLine { revision, directive, .. }| {
|
||||
if let Some(value) = directive.strip_prefix(LLVM_COMPONENTS_HEADER) {
|
||||
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
|
||||
let comp_vec = info.llvm_components.get_or_insert(Vec::new());
|
||||
|
@ -61,7 +61,7 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) {
|
||||
let contents = std::fs::read_to_string(test).unwrap();
|
||||
|
||||
// Collect directives.
|
||||
iter_header(&contents, &mut |HeaderLine { revision, directive }| {
|
||||
iter_header(&contents, &mut |HeaderLine { revision, directive, .. }| {
|
||||
// We're trying to *find* `//@ revision: xxx` directives themselves, not revisioned
|
||||
// directives.
|
||||
if revision.is_some() {
|
||||
|
Loading…
Reference in New Issue
Block a user