Skip to content

Commit 488ffaa

Browse files
committed
Wrap iter_header callback arguments in a documentable struct
1 parent 6672c16 commit 488ffaa

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/tools/compiletest/src/header.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl EarlyProps {
5555
&mut poisoned,
5656
testfile,
5757
rdr,
58-
&mut |_, _, ln, _| {
58+
&mut |HeaderLine { directive: ln, .. }| {
5959
config.push_name_value_directive(ln, directives::AUX_BUILD, &mut props.aux, |r| {
6060
r.trim().to_string()
6161
});
@@ -330,8 +330,8 @@ impl TestProps {
330330
&mut poisoned,
331331
testfile,
332332
file,
333-
&mut |revision, _, ln, _| {
334-
if revision.is_some() && revision != cfg {
333+
&mut |HeaderLine { header_revision, directive: ln, .. }| {
334+
if header_revision.is_some() && header_revision != cfg {
335335
return;
336336
}
337337

@@ -678,7 +678,7 @@ fn iter_header<R: Read>(
678678
poisoned: &mut bool,
679679
testfile: &Path,
680680
rdr: R,
681-
it: &mut dyn FnMut(Option<&str>, &str, &str, usize),
681+
it: &mut dyn FnMut(HeaderLine<'_>),
682682
) {
683683
iter_header_extra(mode, suite, poisoned, testfile, rdr, &[], it)
684684
}
@@ -801,14 +801,26 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
801801
"unset-rustc-env",
802802
];
803803

804+
/// Arguments passed to the callback in [`iter_header`].
805+
struct HeaderLine<'ln> {
806+
/// Contents of the square brackets preceding this header, if present.
807+
header_revision: Option<&'ln str>,
808+
/// Raw line from the test file, including comment prefix and any revision.
809+
original_line: &'ln str,
810+
/// Remainder of the directive line, after the initial comment prefix
811+
/// (`//` or `//@` or `#`) and revision (if any) have been stripped.
812+
directive: &'ln str,
813+
line_number: usize,
814+
}
815+
804816
fn iter_header_extra(
805817
mode: Mode,
806818
suite: &str,
807819
poisoned: &mut bool,
808820
testfile: &Path,
809821
rdr: impl Read,
810822
extra_directives: &[&str],
811-
it: &mut dyn FnMut(Option<&str>, &str, &str, usize),
823+
it: &mut dyn FnMut(HeaderLine<'_>),
812824
) {
813825
if testfile.is_dir() {
814826
return;
@@ -817,7 +829,7 @@ fn iter_header_extra(
817829
// Process any extra directives supplied by the caller (e.g. because they
818830
// are implied by the test mode), with a dummy line number of 0.
819831
for directive in extra_directives {
820-
it(None, directive, directive, 0);
832+
it(HeaderLine { header_revision: None, original_line: "", directive, line_number: 0 });
821833
}
822834

823835
let comment = if testfile.extension().is_some_and(|e| e == "rs") {
@@ -843,14 +855,14 @@ fn iter_header_extra(
843855
// Assume that any directives will be found before the first
844856
// module or function. This doesn't seem to be an optimization
845857
// with a warm page cache. Maybe with a cold one.
846-
let orig_ln = &ln;
858+
let original_line = &ln;
847859
let ln = ln.trim();
848860
if ln.starts_with("fn") || ln.starts_with("mod") {
849861
return;
850862

851863
// First try to accept `ui_test` style comments
852-
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
853-
it(lncfg, orig_ln, ln, line_number);
864+
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
865+
it(HeaderLine { header_revision, original_line, directive, line_number });
854866
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
855867
let Some((_, rest)) = line_directive("//", ln) else {
856868
continue;
@@ -1179,8 +1191,8 @@ pub fn make_test_description<R: Read>(
11791191
path,
11801192
src,
11811193
extra_directives,
1182-
&mut |revision, og_ln, ln, line_number| {
1183-
if revision.is_some() && revision != cfg {
1194+
&mut |HeaderLine { header_revision, original_line, directive: ln, line_number }| {
1195+
if header_revision.is_some() && header_revision != cfg {
11841196
return;
11851197
}
11861198

@@ -1204,7 +1216,7 @@ pub fn make_test_description<R: Read>(
12041216
};
12051217
}
12061218

1207-
if let Some((_, post)) = og_ln.trim_start().split_once("//") {
1219+
if let Some((_, post)) = original_line.trim_start().split_once("//") {
12081220
let post = post.trim_start();
12091221
if post.starts_with("ignore-tidy")
12101222
&& config.mode == Mode::Ui

0 commit comments

Comments
 (0)