Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5ae41d1

Browse files
committedFeb 17, 2024
Wrap iter_header callback arguments in a documentable struct
1 parent ba824a2 commit 5ae41d1

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
@@ -54,7 +54,7 @@ impl EarlyProps {
5454
&mut poisoned,
5555
testfile,
5656
rdr,
57-
&mut |_, _, ln, _| {
57+
&mut |HeaderLine { directive: ln, .. }| {
5858
config.push_name_value_directive(ln, directives::AUX_BUILD, &mut props.aux, |r| {
5959
r.trim().to_string()
6060
});
@@ -329,8 +329,8 @@ impl TestProps {
329329
&mut poisoned,
330330
testfile,
331331
file,
332-
&mut |revision, _, ln, _| {
333-
if revision.is_some() && revision != cfg {
332+
&mut |HeaderLine { header_revision, directive: ln, .. }| {
333+
if header_revision.is_some() && header_revision != cfg {
334334
return;
335335
}
336336

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

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

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

849861
// First try to accept `ui_test` style comments
850-
} else if let Some((lncfg, ln)) = line_directive(comment, ln) {
851-
it(lncfg, orig_ln, ln, line_number);
862+
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
863+
it(HeaderLine { header_revision, original_line, directive, line_number });
852864
} else if mode == Mode::Ui && suite == "ui" && !revision_magic_comment.is_match(ln) {
853865
let Some((_, rest)) = line_directive("//", ln) else {
854866
continue;
@@ -1177,8 +1189,8 @@ pub fn make_test_description<R: Read>(
11771189
path,
11781190
src,
11791191
extra_directives,
1180-
&mut |revision, og_ln, ln, line_number| {
1181-
if revision.is_some() && revision != cfg {
1192+
&mut |HeaderLine { header_revision, original_line, directive: ln, line_number }| {
1193+
if header_revision.is_some() && header_revision != cfg {
11821194
return;
11831195
}
11841196

@@ -1202,7 +1214,7 @@ pub fn make_test_description<R: Read>(
12021214
};
12031215
}
12041216

1205-
if let Some((_, post)) = og_ln.trim_start().split_once("//") {
1217+
if let Some((_, post)) = original_line.trim_start().split_once("//") {
12061218
let post = post.trim_start();
12071219
if post.starts_with("ignore-tidy")
12081220
&& config.mode == Mode::Ui

0 commit comments

Comments
 (0)
Please sign in to comment.