@@ -22,7 +22,7 @@ use crate::tokenizer;
22
22
use crate :: tokenizer:: states as tok_state;
23
23
use crate :: tokenizer:: { Doctype , EndTag , StartTag , Tag , TokenSink , TokenSinkResult } ;
24
24
25
- use std:: borrow:: Cow :: Borrowed ;
25
+ use std:: borrow:: Cow :: { self , Borrowed } ;
26
26
use std:: cell:: { Cell , Ref , RefCell } ;
27
27
use std:: collections:: VecDeque ;
28
28
use std:: iter:: { Enumerate , Rev } ;
@@ -32,7 +32,6 @@ use crate::tokenizer::states::RawKind;
32
32
use crate :: tree_builder:: tag_sets:: * ;
33
33
use crate :: util:: str:: to_escaped_string;
34
34
use log:: { debug, log_enabled, warn, Level } ;
35
- use mac:: format_if;
36
35
use markup5ever:: { expanded_name, local_name, namespace_prefix, ns} ;
37
36
38
37
#[ macro_use]
@@ -488,12 +487,11 @@ where
488
487
if self . mode . get ( ) == InsertionMode :: Initial {
489
488
let ( err, quirk) = data:: doctype_error_and_quirks ( & dt, self . opts . iframe_srcdoc ) ;
490
489
if err {
491
- self . sink . parse_error ( format_if ! (
492
- self . opts. exact_errors,
493
- "Bad DOCTYPE" ,
494
- "Bad DOCTYPE: {:?}" ,
495
- dt
496
- ) ) ;
490
+ self . sink . parse_error ( if self . opts . exact_errors {
491
+ Cow :: from ( format ! ( "Bad DOCTYPE: {dt:?}" ) )
492
+ } else {
493
+ Cow :: from ( "Bad DOCTYPE" )
494
+ } ) ;
497
495
}
498
496
let Doctype {
499
497
name,
@@ -513,12 +511,11 @@ where
513
511
self . mode . set ( InsertionMode :: BeforeHtml ) ;
514
512
return tokenizer:: TokenSinkResult :: Continue ;
515
513
} else {
516
- self . sink . parse_error ( format_if ! (
517
- self . opts. exact_errors,
518
- "DOCTYPE in body" ,
519
- "DOCTYPE in insertion mode {:?}" ,
520
- self . mode. get( )
521
- ) ) ;
514
+ self . sink . parse_error ( if self . opts . exact_errors {
515
+ Cow :: from ( format ! ( "DOCTYPE in insertion mode {:?}" , self . mode. get( ) ) )
516
+ } else {
517
+ Cow :: from ( "DOCTYPE in body" )
518
+ } ) ;
522
519
return tokenizer:: TokenSinkResult :: Continue ;
523
520
}
524
521
} ,
@@ -618,13 +615,15 @@ where
618
615
Sink : TreeSink < Handle = Handle > ,
619
616
{
620
617
fn unexpected < T : fmt:: Debug > ( & self , _thing : & T ) -> ProcessResult < Handle > {
621
- self . sink . parse_error ( format_if ! (
622
- self . opts. exact_errors,
623
- "Unexpected token" ,
624
- "Unexpected token {} in insertion mode {:?}" ,
625
- to_escaped_string( _thing) ,
626
- self . mode. get( )
627
- ) ) ;
618
+ self . sink . parse_error ( if self . opts . exact_errors {
619
+ Cow :: from ( format ! (
620
+ "Unexpected token {} in insertion mode {:?}" ,
621
+ to_escaped_string( _thing) ,
622
+ self . mode. get( )
623
+ ) )
624
+ } else {
625
+ Cow :: from ( "Unexpected token" )
626
+ } ) ;
628
627
ProcessResult :: Done
629
628
}
630
629
@@ -1053,20 +1052,19 @@ where
1053
1052
"thead" "tr" "body" "html" ) ;
1054
1053
1055
1054
for elem in self . open_elems . borrow ( ) . iter ( ) {
1056
- let error;
1057
- {
1055
+ let error = {
1058
1056
let elem_name = self . sink . elem_name ( elem) ;
1059
1057
let name = elem_name. expanded ( ) ;
1060
1058
if body_end_ok ( name) {
1061
1059
continue ;
1062
1060
}
1063
- error = format_if ! (
1064
- self . opts. exact_errors,
1065
- "Unexpected open tag at end of body" ,
1066
- "Unexpected open tag {:?} at end of body" ,
1067
- name
1068
- ) ;
1069
- }
1061
+
1062
+ if self . opts . exact_errors {
1063
+ Cow :: from ( format ! ( "Unexpected open tag {name:?} at end of body" ) )
1064
+ } else {
1065
+ Cow :: from ( "Unexpected open tag at end of body" )
1066
+ }
1067
+ } ;
1070
1068
self . sink . parse_error ( error) ;
1071
1069
// FIXME: Do we keep checking after finding one bad tag?
1072
1070
// The spec suggests not.
@@ -1193,12 +1191,11 @@ where
1193
1191
/// Signal an error if it was not the first one.
1194
1192
fn expect_to_close ( & self , name : LocalName ) {
1195
1193
if self . pop_until_named ( name. clone ( ) ) != 1 {
1196
- self . sink . parse_error ( format_if ! (
1197
- self . opts. exact_errors,
1198
- "Unexpected open element" ,
1199
- "Unexpected open element while closing {:?}" ,
1200
- name
1201
- ) ) ;
1194
+ self . sink . parse_error ( if self . opts . exact_errors {
1195
+ Cow :: from ( format ! ( "Unexpected open element while closing {name:?}" ) )
1196
+ } else {
1197
+ Cow :: from ( "Unexpected open element" )
1198
+ } ) ;
1202
1199
}
1203
1200
}
1204
1201
@@ -1242,12 +1239,14 @@ where
1242
1239
self . orig_mode . set ( Some ( self . mode . get ( ) ) ) ;
1243
1240
ProcessResult :: Reprocess ( InsertionMode :: InTableText , token)
1244
1241
} else {
1245
- self . sink . parse_error ( format_if ! (
1246
- self . opts. exact_errors,
1247
- "Unexpected characters in table" ,
1248
- "Unexpected characters {} in table" ,
1249
- to_escaped_string( & token)
1250
- ) ) ;
1242
+ self . sink . parse_error ( if self . opts . exact_errors {
1243
+ Cow :: from ( format ! (
1244
+ "Unexpected characters {} in table" ,
1245
+ to_escaped_string( & token)
1246
+ ) )
1247
+ } else {
1248
+ Cow :: from ( "Unexpected characters in table" )
1249
+ } ) ;
1251
1250
self . foster_parent_in_body ( token)
1252
1251
}
1253
1252
}
@@ -1553,15 +1552,11 @@ where
1553
1552
}
1554
1553
}
1555
1554
1556
- // Can't use unwrap_or_return!() due to rust-lang/rust#16617.
1557
- let match_idx = match match_idx {
1558
- None => {
1559
- // I believe this is impossible, because the root
1560
- // <html> element is in special_tag.
1561
- self . unexpected ( & tag) ;
1562
- return ;
1563
- } ,
1564
- Some ( x) => x,
1555
+ let Some ( match_idx) = match_idx else {
1556
+ // I believe this is impossible, because the root
1557
+ // <html> element is in special_tag.
1558
+ self . unexpected ( & tag) ;
1559
+ return ;
1565
1560
} ;
1566
1561
1567
1562
self . generate_implied_end_except ( tag. name . clone ( ) ) ;
0 commit comments