@@ -650,27 +650,22 @@ impl TestProps {
650
650
/// See [`HeaderLine`] for a diagram.
651
651
pub fn line_directive < ' line > (
652
652
comment : & str ,
653
- ln : & ' line str ,
653
+ original_line : & ' line str ,
654
654
) -> Option < ( Option < & ' line str > , & ' line str ) > {
655
- let ln = ln. trim_start ( ) ;
656
- if ln. starts_with ( comment) {
657
- let ln = ln[ comment. len ( ) ..] . trim_start ( ) ;
658
- if ln. starts_with ( '[' ) {
659
- // A comment like `//[foo]` is specific to revision `foo`
660
- let Some ( close_brace) = ln. find ( ']' ) else {
661
- panic ! (
662
- "malformed condition directive: expected `{}[foo]`, found `{}`" ,
663
- comment, ln
664
- ) ;
665
- } ;
655
+ // Ignore lines that don't start with the comment prefix.
656
+ let after_comment = original_line. trim_start ( ) . strip_prefix ( comment) ?. trim_start ( ) ;
657
+
658
+ if let Some ( after_open_bracket) = after_comment. strip_prefix ( '[' ) {
659
+ // A comment like `//@[foo]` only applies to revision `foo`.
660
+ let Some ( ( line_revision, directive) ) = after_open_bracket. split_once ( ']' ) else {
661
+ panic ! (
662
+ "malformed condition directive: expected `{comment}[foo]`, found `{original_line}`"
663
+ )
664
+ } ;
666
665
667
- let line_revision = & ln[ 1 ..close_brace] ;
668
- Some ( ( Some ( line_revision) , ln[ ( close_brace + 1 ) ..] . trim_start ( ) ) )
669
- } else {
670
- Some ( ( None , ln) )
671
- }
666
+ Some ( ( Some ( line_revision) , directive. trim_start ( ) ) )
672
667
} else {
673
- None
668
+ Some ( ( None , after_comment ) )
674
669
}
675
670
}
676
671
0 commit comments