@@ -202,6 +202,8 @@ pub struct CommentParser<T> {
202
202
errors : Vec < Error > ,
203
203
/// The available commands and their parsing logic
204
204
commands : HashMap < & ' static str , CommandParserFunc > ,
205
+ /// The symbol(s) that signify the start of a comment.
206
+ comment_start : & ' static str ,
205
207
}
206
208
207
209
pub type CommandParserFunc =
@@ -312,6 +314,7 @@ impl CommentParser<Comments> {
312
314
comments : config. comment_defaults . clone ( ) ,
313
315
errors : vec ! [ ] ,
314
316
commands : Self :: commands ( ) ,
317
+ comment_start : config. comment_start ,
315
318
} ;
316
319
this. commands
317
320
. extend ( config. custom_comments . iter ( ) . map ( |( & k, & v) | ( k, v) ) ) ;
@@ -468,15 +471,27 @@ impl CommentParser<Comments> {
468
471
line : Spanned < & [ u8 ] > ,
469
472
) -> std:: result:: Result < ParsePatternResult , Spanned < Utf8Error > > {
470
473
let mut res = ParsePatternResult :: Other ;
471
- if let Some ( command) = line. strip_prefix ( b"//@" ) {
472
- self . parse_command ( command. to_str ( ) ?. trim ( ) )
473
- } else if let Some ( ( _, pattern) ) = line. split_once_str ( "//~" ) {
474
- let ( revisions, pattern) = self . parse_revisions ( pattern. to_str ( ) ?) ;
475
- self . revisioned ( revisions, |this| {
476
- res = this. parse_pattern ( pattern, fallthrough_to, current_line) ;
477
- } )
474
+
475
+ if let Some ( ( _, comment) ) =
476
+ line. split_once_str ( self . comment_start )
477
+ . filter ( |( pre, c) | match c[ 0 ] {
478
+ b'@' => pre. is_empty ( ) ,
479
+ b'~' => true ,
480
+ _ => false ,
481
+ } )
482
+ {
483
+ if let Some ( command) = comment. strip_prefix ( b"@" ) {
484
+ self . parse_command ( command. to_str ( ) ?. trim ( ) )
485
+ } else if let Some ( pattern) = comment. strip_prefix ( b"~" ) {
486
+ let ( revisions, pattern) = self . parse_revisions ( pattern. to_str ( ) ?) ;
487
+ self . revisioned ( revisions, |this| {
488
+ res = this. parse_pattern ( pattern, fallthrough_to, current_line) ;
489
+ } )
490
+ } else {
491
+ unreachable ! ( )
492
+ }
478
493
} else {
479
- for pos in line. clone ( ) . find_iter ( "//" ) {
494
+ for pos in line. clone ( ) . find_iter ( self . comment_start ) {
480
495
let ( _, rest) = line. clone ( ) . to_str ( ) ?. split_at ( pos + 2 ) ;
481
496
for rest in std:: iter:: once ( rest. clone ( ) ) . chain ( rest. strip_prefix ( " " ) ) {
482
497
let c = rest. chars ( ) . next ( ) ;
@@ -489,25 +504,29 @@ impl CommentParser<Comments> {
489
504
span,
490
505
format ! (
491
506
"comment looks suspiciously like a test suite command: `{}`\n \
492
- All `// @` test suite commands must be at the start of the line.\n \
493
- The `// ` must be directly followed by `@` or `~`.",
494
- * rest,
507
+ All `{} @` test suite commands must be at the start of the line.\n \
508
+ The `{} ` must be directly followed by `@` or `~`.",
509
+ * rest, self . comment_start , self . comment_start ,
495
510
) ,
496
511
) ;
497
512
} else {
498
513
let mut parser = Self {
499
514
errors : vec ! [ ] ,
500
515
comments : Comments :: default ( ) ,
501
516
commands : std:: mem:: take ( & mut self . commands ) ,
517
+ comment_start : self . comment_start ,
502
518
} ;
503
519
let span = rest. span ( ) ;
504
520
parser. parse_command ( rest) ;
505
521
if parser. errors . is_empty ( ) {
506
522
self . error (
507
523
span,
508
- "a compiletest-rs style comment was detected.\n \
524
+ format ! (
525
+ "a compiletest-rs style comment was detected.\n \
509
526
Please use text that could not also be interpreted as a command,\n \
510
- and prefix all actual commands with `//@`",
527
+ and prefix all actual commands with `{}@`",
528
+ self . comment_start
529
+ ) ,
511
530
) ;
512
531
}
513
532
self . commands = parser. commands ;
@@ -596,6 +615,7 @@ impl CommentParser<Comments> {
596
615
span,
597
616
} = revisions;
598
617
let mut this = CommentParser {
618
+ comment_start : self . comment_start ,
599
619
errors : std:: mem:: take ( & mut self . errors ) ,
600
620
commands : std:: mem:: take ( & mut self . commands ) ,
601
621
comments : self
@@ -909,7 +929,8 @@ impl CommentParser<&mut Revisioned> {
909
929
}
910
930
_ => {
911
931
self . error ( pattern. span ( ) , format ! (
912
- "//~^ pattern is trying to refer to {} lines above, but there are only {} lines above" ,
932
+ "{}~^ pattern is trying to refer to {} lines above, but there are only {} lines above" ,
933
+ self . comment_start,
913
934
offset,
914
935
current_line. get( ) - 1 ,
915
936
) ) ;
@@ -940,7 +961,8 @@ impl CommentParser<&mut Revisioned> {
940
961
// The line count of the file is not yet known so we can only check
941
962
// if the resulting line is in the range of a usize.
942
963
self . error ( pattern. span ( ) , format ! (
943
- "//~v pattern is trying to refer to {} lines below, which is more than ui_test can count" ,
964
+ "{}~v pattern is trying to refer to {} lines below, which is more than ui_test can count" ,
965
+ self . comment_start,
944
966
offset,
945
967
) ) ;
946
968
return ParsePatternResult :: ErrorBelow {
0 commit comments