Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Include the line number in tidy's iter_header
  • Loading branch information
Zalathar committed May 9, 2024
commit 1fbabc622f1791dbbddf2ab5cda7c392a21d94ba
7 changes: 4 additions & 3 deletions src/tools/tidy/src/iter_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const COMMENT: &str = "//@";
/// 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,
}
Expand All @@ -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`.
Expand All @@ -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() });
}
}
}
2 changes: 1 addition & 1 deletion src/tools/tidy/src/target_specific_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down