@@ -650,27 +650,22 @@ impl TestProps {
650650/// See [`HeaderLine`] for a diagram.
651651pub fn line_directive < ' line > (
652652 comment : & str ,
653- ln : & ' line str ,
653+ original_line : & ' line str ,
654654) -> 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+ } ;
666665
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 ( ) ) )
672667 } else {
673- None
668+ Some ( ( None , after_comment ) )
674669 }
675670}
676671
0 commit comments