@@ -262,22 +262,18 @@ pub(crate) struct ErrorMatch {
262
262
}
263
263
264
264
impl Condition {
265
- fn parse ( c : & str ) -> std:: result:: Result < Self , String > {
266
- if c == "on-host" {
267
- Ok ( Condition :: OnHost )
268
- } else if let Some ( bits) = c. strip_suffix ( "bit" ) {
269
- let bits: u8 = bits. parse ( ) . map_err ( |_err| {
270
- format ! ( "invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith" )
271
- } ) ?;
272
- Ok ( Condition :: Bitwidth ( bits) )
273
- } else if let Some ( triple_substr) = c. strip_prefix ( "target-" ) {
274
- Ok ( Condition :: Target ( triple_substr. to_owned ( ) ) )
275
- } else if let Some ( triple_substr) = c. strip_prefix ( "host-" ) {
276
- Ok ( Condition :: Host ( triple_substr. to_owned ( ) ) )
277
- } else {
278
- Err ( format ! (
279
- "`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/"
280
- ) )
265
+ fn parse ( c : & str , args : & str ) -> std:: result:: Result < Self , String > {
266
+ match c {
267
+ "on-host" => Ok ( Condition :: OnHost ) ,
268
+ "bitwidth" => {
269
+ let bits: u8 = args. parse ( ) . map_err ( |_err| {
270
+ format ! ( "invalid ignore/only filter ending in 'bit': {c:?} is not a valid bitwdith" )
271
+ } ) ?;
272
+ Ok ( Condition :: Bitwidth ( bits) )
273
+ }
274
+ "target" => Ok ( Condition :: Target ( args. to_owned ( ) ) ) ,
275
+ "host" => Ok ( Condition :: Host ( args. to_owned ( ) ) ) ,
276
+ _ => Err ( format ! ( "`{c}` is not a valid condition, expected `on-host`, /[0-9]+bit/, /host-.*/, or /target-.*/" ) ) ,
281
277
}
282
278
}
283
279
}
@@ -769,17 +765,20 @@ impl CommentParser<&mut Revisioned> {
769
765
fn parse_command ( & mut self , command : Spanned < & str > , args : Spanned < & str > ) {
770
766
if let Some ( command_handler) = self . commands . get ( * command) {
771
767
command_handler ( self , args, command. span ( ) ) ;
772
- } else if let Some ( s) = command. strip_prefix ( "ignore-" ) {
773
- // args are ignored (can be used as comment)
774
- match Condition :: parse ( * s) {
775
- Ok ( cond) => self . ignore . push ( cond) ,
776
- Err ( msg) => self . error ( s. span ( ) , msg) ,
777
- }
778
- } else if let Some ( s) = command. strip_prefix ( "only-" ) {
768
+ } else if let Some ( rest) = command
769
+ . strip_prefix ( "ignore-" )
770
+ . or_else ( || command. strip_prefix ( "only-" ) )
771
+ {
779
772
// args are ignored (can be used as comment)
780
- match Condition :: parse ( * s) {
781
- Ok ( cond) => self . only . push ( cond) ,
782
- Err ( msg) => self . error ( s. span ( ) , msg) ,
773
+ match Condition :: parse ( * rest, * args) {
774
+ Ok ( cond) => {
775
+ if command. starts_with ( "ignore" ) {
776
+ self . ignore . push ( cond)
777
+ } else {
778
+ self . only . push ( cond)
779
+ }
780
+ }
781
+ Err ( msg) => self . error ( rest. span ( ) , msg) ,
783
782
}
784
783
} else {
785
784
let best_match = self
0 commit comments