Skip to content

Commit c4016ea

Browse files
committed
Rename some fields of DirectiveLine
1 parent 1467dee commit c4016ea

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/tools/compiletest/src/header.rs

+27-23
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl EarlyProps {
5757
&mut poisoned,
5858
testfile,
5959
rdr,
60-
&mut |DirectiveLine { directive: ln, .. }| {
60+
&mut |DirectiveLine { raw_directive: ln, .. }| {
6161
parse_and_update_aux(config, ln, &mut props.aux);
6262
config.parse_and_update_revisions(testfile, ln, &mut props.revisions);
6363
},
@@ -344,8 +344,8 @@ impl TestProps {
344344
&mut poisoned,
345345
testfile,
346346
file,
347-
&mut |DirectiveLine { header_revision, directive: ln, .. }| {
348-
if header_revision.is_some() && header_revision != test_revision {
347+
&mut |directive @ DirectiveLine { raw_directive: ln, .. }| {
348+
if !directive.applies_to_test_revision(test_revision) {
349349
return;
350350
}
351351

@@ -730,28 +730,37 @@ const KNOWN_HTMLDOCCK_DIRECTIVE_NAMES: &[&str] = &[
730730
const KNOWN_JSONDOCCK_DIRECTIVE_NAMES: &[&str] =
731731
&["count", "!count", "has", "!has", "is", "!is", "ismany", "!ismany", "set", "!set"];
732732

733-
/// The broken-down contents of a line containing a test header directive,
733+
/// The (partly) broken-down contents of a line containing a test directive,
734734
/// which [`iter_header`] passes to its callback function.
735735
///
736736
/// For example:
737737
///
738738
/// ```text
739739
/// //@ compile-flags: -O
740-
/// ^^^^^^^^^^^^^^^^^ directive
740+
/// ^^^^^^^^^^^^^^^^^ raw_directive
741741
///
742742
/// //@ [foo] compile-flags: -O
743-
/// ^^^ header_revision
744-
/// ^^^^^^^^^^^^^^^^^ directive
743+
/// ^^^ revision
744+
/// ^^^^^^^^^^^^^^^^^ raw_directive
745745
/// ```
746746
struct DirectiveLine<'ln> {
747747
line_number: usize,
748-
/// Some header directives start with a revision name in square brackets
748+
/// Some test directives start with a revision name in square brackets
749749
/// (e.g. `[foo]`), and only apply to that revision of the test.
750750
/// If present, this field contains the revision name (e.g. `foo`).
751-
header_revision: Option<&'ln str>,
752-
/// The main part of the header directive, after removing the comment prefix
751+
revision: Option<&'ln str>,
752+
/// The main part of the directive, after removing the comment prefix
753753
/// and the optional revision specifier.
754-
directive: &'ln str,
754+
///
755+
/// This is "raw" because the directive's name and colon-separated value
756+
/// (if present) have not yet been extracted or checked.
757+
raw_directive: &'ln str,
758+
}
759+
760+
impl<'ln> DirectiveLine<'ln> {
761+
fn applies_to_test_revision(&self, test_revision: Option<&str>) -> bool {
762+
self.revision.is_none() || self.revision == test_revision
763+
}
755764
}
756765

757766
pub(crate) struct CheckDirectiveResult<'ln> {
@@ -819,8 +828,8 @@ fn iter_header(
819828
"ignore-cross-compile",
820829
];
821830
// Process the extra implied directives, with a dummy line number of 0.
822-
for directive in extra_directives {
823-
it(DirectiveLine { line_number: 0, header_revision: None, directive });
831+
for raw_directive in extra_directives {
832+
it(DirectiveLine { line_number: 0, revision: None, raw_directive });
824833
}
825834
}
826835

@@ -847,14 +856,13 @@ fn iter_header(
847856
return;
848857
}
849858

850-
let Some((header_revision, non_revisioned_directive_line)) = line_directive(comment, ln)
851-
else {
859+
let Some((revision, raw_directive)) = line_directive(comment, ln) else {
852860
continue;
853861
};
854862

855863
// Perform unknown directive check on Rust files.
856864
if testfile.extension().map(|e| e == "rs").unwrap_or(false) {
857-
let directive_ln = non_revisioned_directive_line.trim();
865+
let directive_ln = raw_directive.trim();
858866

859867
let CheckDirectiveResult { is_known_directive, trailing_directive } =
860868
check_directive(directive_ln, mode, ln);
@@ -888,11 +896,7 @@ fn iter_header(
888896
}
889897
}
890898

891-
it(DirectiveLine {
892-
line_number,
893-
header_revision,
894-
directive: non_revisioned_directive_line,
895-
});
899+
it(DirectiveLine { line_number, revision, raw_directive });
896900
}
897901
}
898902

@@ -1292,8 +1296,8 @@ pub fn make_test_description<R: Read>(
12921296
&mut local_poisoned,
12931297
path,
12941298
src,
1295-
&mut |DirectiveLine { header_revision, directive: ln, line_number }| {
1296-
if header_revision.is_some() && header_revision != test_revision {
1299+
&mut |directive @ DirectiveLine { line_number, raw_directive: ln, .. }| {
1300+
if !directive.applies_to_test_revision(test_revision) {
12971301
return;
12981302
}
12991303

0 commit comments

Comments
 (0)