11use std:: fmt;
22
3+ use camino:: Utf8Path ;
4+
35const COMPILETEST_DIRECTIVE_PREFIX : & str = "//@" ;
46
57/// If the given line begins with the appropriate comment prefix for a directive,
68/// returns a struct containing various parts of the directive.
7- pub ( crate ) fn line_directive < ' line > (
9+ pub ( crate ) fn line_directive < ' a > (
10+ file_path : & ' a Utf8Path ,
811 line_number : usize ,
9- original_line : & ' line str ,
10- ) -> Option < DirectiveLine < ' line > > {
12+ original_line : & ' a str ,
13+ ) -> Option < DirectiveLine < ' a > > {
1114 // Ignore lines that don't start with the comment prefix.
1215 let after_comment =
1316 original_line. trim_start ( ) . strip_prefix ( COMPILETEST_DIRECTIVE_PREFIX ) ?. trim_start ( ) ;
@@ -33,7 +36,7 @@ pub(crate) fn line_directive<'line>(
3336 // The directive name ends at the first occurrence of colon, space, or end-of-string.
3437 let name = raw_directive. split ( [ ':' , ' ' ] ) . next ( ) . expect ( "split is never empty" ) ;
3538
36- Some ( DirectiveLine { line_number, revision, raw_directive, name } )
39+ Some ( DirectiveLine { file_path , line_number, revision, raw_directive, name } )
3740}
3841
3942/// The (partly) broken-down contents of a line containing a test directive,
@@ -51,25 +54,30 @@ pub(crate) fn line_directive<'line>(
5154/// ^^^^^^^^^^^^^^^^^ raw_directive
5255/// ^^^^^^^^^^^^^ name
5356/// ```
54- pub ( crate ) struct DirectiveLine < ' ln > {
57+ pub ( crate ) struct DirectiveLine < ' a > {
58+ /// Path of the file containing this line.
59+ ///
60+ /// Mostly used for diagnostics, but some directives (e.g. `//@ pp-exact`)
61+ /// also use it to compute a value based on the filename.
62+ pub ( crate ) file_path : & ' a Utf8Path ,
5563 pub ( crate ) line_number : usize ,
5664
5765 /// Some test directives start with a revision name in square brackets
5866 /// (e.g. `[foo]`), and only apply to that revision of the test.
5967 /// If present, this field contains the revision name (e.g. `foo`).
60- pub ( crate ) revision : Option < & ' ln str > ,
68+ pub ( crate ) revision : Option < & ' a str > ,
6169
6270 /// The main part of the directive, after removing the comment prefix
6371 /// and the optional revision specifier.
6472 ///
6573 /// This is "raw" because the directive's name and colon-separated value
6674 /// (if present) have not yet been extracted or checked.
67- raw_directive : & ' ln str ,
75+ raw_directive : & ' a str ,
6876
6977 /// Name of the directive.
7078 ///
7179 /// Invariant: `self.raw_directive.starts_with(self.name)`
72- pub ( crate ) name : & ' ln str ,
80+ pub ( crate ) name : & ' a str ,
7381}
7482
7583impl < ' ln > DirectiveLine < ' ln > {
0 commit comments