Skip to content

Commit e134102

Browse files
committed
Improve internal docs for the HeaderLine callback struct
1 parent 7168c13 commit e134102

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ impl TestProps {
646646
}
647647

648648
/// Extract a `(Option<line_config>, directive)` directive from a line if comment is present.
649+
///
650+
/// See [`HeaderLine`] for a diagram.
649651
pub fn line_directive<'line>(
650652
comment: &str,
651653
ln: &'line str,
@@ -790,16 +792,32 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
790792
"unset-rustc-env",
791793
];
792794

793-
/// Arguments passed to the callback in [`iter_header`].
795+
/// The broken-down contents of a line containing a test header directive,
796+
/// which [`iter_header`] passes to its callback function.
797+
///
798+
/// For example:
799+
///
800+
/// ```text
801+
/// //@ compile-flags: -O
802+
/// ^^^^^^^^^^^^^^^^^ directive
803+
/// ^^^^^^^^^^^^^^^^^^^^^ original_line
804+
///
805+
/// //@ [foo] compile-flags: -O
806+
/// ^^^ header_revision
807+
/// ^^^^^^^^^^^^^^^^^ directive
808+
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ original_line
809+
/// ```
794810
struct HeaderLine<'ln> {
795-
/// Contents of the square brackets preceding this header, if present.
796-
header_revision: Option<&'ln str>,
811+
line_number: usize,
797812
/// Raw line from the test file, including comment prefix and any revision.
798813
original_line: &'ln str,
799-
/// Remainder of the directive line, after the initial comment prefix
800-
/// (`//` or `//@` or `#`) and revision (if any) have been stripped.
814+
/// Some header directives start with a revision name in square brackets
815+
/// (e.g. `[foo]`), and only apply to that revision of the test.
816+
/// If present, this field contains the revision name (e.g. `foo`).
817+
header_revision: Option<&'ln str>,
818+
/// The main part of the header directive, after removing the comment prefix
819+
/// and the optional revision specifier.
801820
directive: &'ln str,
802-
line_number: usize,
803821
}
804822

805823
fn iter_header(
@@ -831,7 +849,7 @@ fn iter_header(
831849
];
832850
// Process the extra implied directives, with a dummy line number of 0.
833851
for directive in extra_directives {
834-
it(HeaderLine { header_revision: None, original_line: "", directive, line_number: 0 });
852+
it(HeaderLine { line_number: 0, original_line: "", header_revision: None, directive });
835853
}
836854
}
837855

@@ -865,7 +883,7 @@ fn iter_header(
865883

866884
// First try to accept `ui_test` style comments
867885
} else if let Some((header_revision, directive)) = line_directive(comment, ln) {
868-
it(HeaderLine { header_revision, original_line, directive, line_number });
886+
it(HeaderLine { line_number, original_line, header_revision, directive });
869887
} else if mode == Mode::Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE.is_match(ln) {
870888
let Some((_, rest)) = line_directive("//", ln) else {
871889
continue;

0 commit comments

Comments
 (0)