Repository: servo/html5ever (language: python)

Issue:
Some statements can be simplified for readability
We can replace lines like

```rust
println!("Move children from {} to {}", node, new_parent);
```

with

```rust
println!("Move children from {node} to {new_parent}");
```

to improve code readability and maintainability.


Discussion / hints:

Fix patch:
diff --git a/html5ever/benches/html5ever.rs b/html5ever/benches/html5ever.rs
index 7d3b0a2a..0df9a69c 100644
--- a/html5ever/benches/html5ever.rs
+++ b/html5ever/benches/html5ever.rs
@@ -49,7 +49,7 @@ fn run_bench(c: &mut Criterion, name: &str) {
         total += sz;
     }
 
-    let test_name = format!("html tokenizing {}", name);
+    let test_name = format!("html tokenizing {name}");
 
     c.bench_function(&test_name, move |b| {
         b.iter(|| {
diff --git a/html5ever/examples/print-tree-actions.rs b/html5ever/examples/print-tree-actions.rs
index cae76cfc..dfa0aedd 100644
--- a/html5ever/examples/print-tree-actions.rs
+++ b/html5ever/examples/print-tree-actions.rs
@@ -44,7 +44,7 @@ impl TreeSink for Sink {
     }
 
     fn parse_error(&self, msg: Cow<'static, str>) {
-        println!("Parse error: {}", msg);
+        println!("Parse error: {msg}");
     }
 
     fn get_document(&self) -> usize {
@@ -62,7 +62,7 @@ impl TreeSink for Sink {
     }
 
     fn set_quirks_mode(&self, mode: QuirksMode) {
-        println!("Set quirks mode to {:?}", mode);
+        println!("Set quirks mode to {mode:?}");
     }
 
     fn same_node(&self, x: &usize, y: &usize) -> bool {
@@ -77,7 +77,7 @@ impl TreeSink for Sink {
 
     fn create_element(&self, name: QualName, _: Vec<Attribute>, _: ElementFlags) -> usize {
         let id = self.get_id();
-        println!("Created {:?} as {}", name, id);
+        println!("Created {name:?} as {id}");
         // N.B. We intentionally leak memory here to minimize the implementation complexity
         //      of this example code. A real implementation would either want to use a real
         //      real DOM tree implentation, or else use an arena as the backing store for
@@ -101,14 +101,14 @@ impl TreeSink for Sink {
 
     fn append(&self, parent: &usize, child: NodeOrText<usize>) {
         match child {
-            AppendNode(n) => println!("Append node {} to {}", n, parent),
+            AppendNode(n) => println!("Append node {n} to {parent}"),
             AppendText(t) => println!("Append text to {}: \"{}\"", parent, t.escape_default()),
         }
     }
 
     fn append_before_sibling(&self, sibling: &usize, new_node: NodeOrText<usize>) {
         match new_node {
-            AppendNode(n) => println!("Append node {} before {}", n, sibling),
+            AppendNode(n) => println!("Append node {n} before {sibling}"),
             AppendText(t) => println!("Append text before {}: \"{}\"", sibling, t.escape_default()),
         }
     }
@@ -128,12 +128,12 @@ impl TreeSink for Sink {
         public_id: StrTendril,
         system_id: StrTendril,
     ) {
-        println!("Append doctype: {} {} {}", name, public_id, system_id);
+        println!("Append doctype: {name} {public_id} {system_id}");
     }
 
     fn add_attrs_if_missing(&self, target: &usize, attrs: Vec<Attribute>) {
         assert!(self.names.borrow().contains_key(target), "not an element");
-        println!("Add missing attributes to {}:", target);
+        println!("Add missing attributes to {target}:");
         for attr in attrs.into_iter() {
             println!("    {:?} = {}", attr.name, attr.value);
         }
@@ -149,23 +149,23 @@ impl TreeSink for Sink {
     }
 
     fn remove_from_parent(&self, target: &usize) {
-        println!("Remove {} from parent", target);
+        println!("Remove {target} from parent");
     }
 
     fn reparent_children(&self, node: &usize, new_parent: &usize) {
-        println!("Move children from {} to {}", node, new_parent);
+        println!("Move children from {node} to {new_parent}");
     }
 
     fn mark_script_already_started(&self, node: &usize) {
-        println!("Mark script {} as already started", node);
+        println!("Mark script {node} as already started");
     }
 
     fn set_current_line(&self, line_number: u64) {
-        println!("Set current line to {}", line_number);
+        println!("Set current line to {line_number}");
     }
 
     fn pop(&self, elem: &usize) {
-        println!("Popped element {}", elem);
+        println!("Popped element {elem}");
     }
 }
 
diff --git a/html5ever/examples/tokenize.rs b/html5ever/examples/tokenize.rs
index 912a6ce6..ba984d8f 100644
--- a/html5ever/examples/tokenize.rs
+++ b/html5ever/examples/tokenize.rs
@@ -71,11 +71,11 @@ impl TokenSink for TokenPrinter {
             },
             ParseError(err) => {
                 self.is_char(false);
-                println!("ERROR: {}", err);
+                println!("ERROR: {err}");
             },
             _ => {
                 self.is_char(false);
-                println!("OTHER: {:?}", token);
+                println!("OTHER: {token:?}");
             },
         }
         TokenSinkResult::Continue
diff --git a/html5ever/macros/match_token.rs b/html5ever/macros/match_token.rs
index 4157ddf4..2eb64fee 100644
--- a/html5ever/macros/match_token.rs
+++ b/html5ever/macros/match_token.rs
@@ -290,10 +290,7 @@ fn expand_match_token_macro(match_token: MatchToken) -> TokenStream {
             // ordinary pattern => expression
             (Lhs::Pattern(pat), Rhs::Expression(expr)) => {
                 if !wildcards_patterns.is_empty() {
-                    panic!(
-                        "ordinary patterns may not appear after wildcard tags {:?} {:?}",
-                        pat, expr
-                    );
+                    panic!("ordinary patterns may not appear after wildcard tags {pat:?} {expr:?}");
                 }
                 arms_code.push(quote!(#binding #pat => #expr,))
             },
diff --git a/html5ever/src/serialize/mod.rs b/html5ever/src/serialize/mod.rs
index 2620c195..710066a2 100644
--- a/html5ever/src/serialize/mod.rs
+++ b/html5ever/src/serialize/mod.rs
@@ -109,7 +109,7 @@ impl<Wr: Write> HtmlSerializer<Wr> {
                 '"' if attr_mode => self.writer.write_all(b"&quot;"),
                 '<' if !attr_mode => self.writer.write_all(b"&lt;"),
                 '>' if !attr_mode => self.writer.write_all(b"&gt;"),
-                c => self.writer.write_fmt(format_args!("{}", c)),
+                c => self.writer.write_fmt(format_args!("{c}")),
             }?;
         }
         Ok(())
diff --git a/html5ever/src/tokenizer/mod.rs b/html5ever/src/tokenizer/mod.rs
index 0a632875..9edeccb7 100644
--- a/html5ever/src/tokenizer/mod.rs
+++ b/html5ever/src/tokenizer/mod.rs
@@ -273,7 +273,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
                 _ => false,
             }
         {
-            let msg = format!("Bad character {}", c);
+            let msg = format!("Bad character {c}");
             self.emit_error(Cow::Owned(msg));
         }
 
@@ -1483,11 +1483,11 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
             "\n{:12}         total in token sink",
             self.time_in_sink.get()
         );
-        println!("\n{:12}         total in tokenizer", total);
+        println!("\n{total:12}         total in tokenizer");
 
         for (k, v) in results.into_iter() {
             let pct = 100.0 * (v as f64) / (total as f64);
-            println!("{:12}  {:4.1}%  {:?}", v, pct, k);
+            println!("{v:12}  {pct:4.1}%  {k:?}");
         }
     }
 
diff --git a/html5ever/src/tree_builder/mod.rs b/html5ever/src/tree_builder/mod.rs
index 348c211d..736f4d9f 100644
--- a/html5ever/src/tree_builder/mod.rs
+++ b/html5ever/src/tree_builder/mod.rs
@@ -296,7 +296,7 @@ where
 
     #[allow(dead_code)]
     fn dump_state(&self, label: String) {
-        println!("dump_state on {}", label);
+        println!("dump_state on {label}");
         print!("    open_elems:");
         for node in self.open_elems.borrow().iter() {
             let name = self.sink.elem_name(node);
diff --git a/html5ever/src/util/str.rs b/html5ever/src/util/str.rs
index 4520ecc4..2c0ec3e2 100644
--- a/html5ever/src/util/str.rs
+++ b/html5ever/src/util/str.rs
@@ -11,7 +11,7 @@ use std::fmt;
 
 pub(crate) fn to_escaped_string<T: fmt::Debug>(x: &T) -> String {
     // FIXME: don't allocate twice
-    let string = format!("{:?}", x);
+    let string = format!("{x:?}");
     string.chars().flat_map(|c| c.escape_default()).collect()
 }
 
diff --git a/markup5ever/build.rs b/markup5ever/build.rs
index 354c7ec5..ad23dedb 100644
--- a/markup5ever/build.rs
+++ b/markup5ever/build.rs
@@ -73,12 +73,7 @@ fn main() {
     )
     .unwrap();
     for &(prefix, url) in NAMESPACES {
-        writeln!(
-            generated,
-            "({}) => {{ namespace_url!({:?}) }};",
-            prefix, url
-        )
-        .unwrap();
+        writeln!(generated, "({prefix}) => {{ namespace_url!({url:?}) }};").unwrap();
     }
     writeln!(generated, "}}").unwrap();
 }
@@ -102,7 +97,7 @@ fn named_entities_to_phf(to: &Path) {
 
     let mut phf_map = phf_codegen::Map::new();
     for (key, value) in entities {
-        phf_map.entry(key, &format!("{:?}", value));
+        phf_map.entry(key, &format!("{value:?}"));
     }
 
     let mut file = File::create(to).unwrap();
diff --git a/rcdom/examples/hello_xml.rs b/rcdom/examples/hello_xml.rs
index 792e4d96..d0cc40cb 100644
--- a/rcdom/examples/hello_xml.rs
+++ b/rcdom/examples/hello_xml.rs
@@ -33,5 +33,5 @@ fn main() {
         xml.push_str(&contents.borrow());
     }
 
-    println!("{:?} {:?}!", hello_tag, xml);
+    println!("{hello_tag:?} {xml:?}!");
 }
diff --git a/rcdom/examples/print-rcdom.rs b/rcdom/examples/print-rcdom.rs
index 8a9bfb2c..e1d8fc68 100644
--- a/rcdom/examples/print-rcdom.rs
+++ b/rcdom/examples/print-rcdom.rs
@@ -31,7 +31,7 @@ fn walk(indent: usize, handle: &Handle) {
             ref name,
             ref public_id,
             ref system_id,
-        } => println!("<!DOCTYPE {} \"{}\" \"{}\">", name, public_id, system_id),
+        } => println!("<!DOCTYPE {name} \"{public_id}\" \"{system_id}\">"),
 
         NodeData::Text { ref contents } => {
             println!("#text: {}", contents.borrow().escape_default())
@@ -72,7 +72,7 @@ fn main() {
     if !dom.errors.borrow().is_empty() {
         println!("\nParse errors:");
         for err in dom.errors.borrow().iter() {
-            println!("    {}", err);
+            println!("    {err}");
         }
     }
 }
diff --git a/rcdom/examples/xml_tree_printer.rs b/rcdom/examples/xml_tree_printer.rs
index b55289cf..4cd53575 100644
--- a/rcdom/examples/xml_tree_printer.rs
+++ b/rcdom/examples/xml_tree_printer.rs
@@ -20,7 +20,7 @@ use xml5ever::tendril::TendrilSink;
 fn walk(prefix: &str, handle: &Handle) {
     let node = handle;
 
-    print!("{}", prefix);
+    print!("{prefix}");
     match node.data {
         NodeData::Document => println!("#document"),
 
diff --git a/xml5ever/benches/xml5ever.rs b/xml5ever/benches/xml5ever.rs
index 74ce3a15..f909486e 100644
--- a/xml5ever/benches/xml5ever.rs
+++ b/xml5ever/benches/xml5ever.rs
@@ -48,7 +48,7 @@ fn run_bench(c: &mut Criterion, name: &str) {
         total += sz;
     }
 
-    let test_name = format!("xml tokenizing {}", name);
+    let test_name = format!("xml tokenizing {name}");
 
     c.bench_function(&test_name, move |b| {
         b.iter(|| {
diff --git a/xml5ever/examples/simple_xml_tokenizer.rs b/xml5ever/examples/simple_xml_tokenizer.rs
index fc4b7b1a..8cc930dd 100644
--- a/xml5ever/examples/simple_xml_tokenizer.rs
+++ b/xml5ever/examples/simple_xml_tokenizer.rs
@@ -34,16 +34,16 @@ impl TokenSink for SimpleTokenPrinter {
                 println!("{:?} {} ", tag.kind, &*tag.name.local);
             },
             ParseError(err) => {
-                println!("ERROR: {}", err);
+                println!("ERROR: {err}");
             },
             PIToken(Pi {
                 ref target,
                 ref data,
             }) => {
-                println!("PI : <?{} {}?>", target, data);
+                println!("PI : <?{target} {data}?>");
             },
             CommentToken(ref comment) => {
-                println!("<!--{:?}-->", comment);
+                println!("<!--{comment:?}-->");
             },
             EOFToken => {
                 println!("EOF");
@@ -53,7 +53,7 @@ impl TokenSink for SimpleTokenPrinter {
                 ref public_id,
                 ..
             }) => {
-                println!("<!DOCTYPE {:?} {:?}>", name, public_id);
+                println!("<!DOCTYPE {name:?} {public_id:?}>");
             },
         }
     }
diff --git a/xml5ever/examples/xml_tokenizer.rs b/xml5ever/examples/xml_tokenizer.rs
index 2776ed50..a9115811 100644
--- a/xml5ever/examples/xml_tokenizer.rs
+++ b/xml5ever/examples/xml_tokenizer.rs
@@ -74,15 +74,15 @@ impl TokenSink for TokenPrinter {
             },
             ParseError(err) => {
                 self.is_char(false);
-                println!("ERROR: {}", err);
+                println!("ERROR: {err}");
             },
             PIToken(Pi { target, data }) => {
                 self.is_char(false);
-                println!("PI : <?{:?} {:?}?>", target, data);
+                println!("PI : <?{target:?} {data:?}?>");
             },
             _ => {
                 self.is_char(false);
-                println!("OTHER: {:?}", token);
+                println!("OTHER: {token:?}");
             },
         }
     }
diff --git a/xml5ever/src/serialize/mod.rs b/xml5ever/src/serialize/mod.rs
index cbc4cbd2..d39e0599 100644
--- a/xml5ever/src/serialize/mod.rs
+++ b/xml5ever/src/serialize/mod.rs
@@ -80,7 +80,7 @@ fn write_to_buf_escaped<W: Write>(writer: &mut W, text: &str, attr_mode: bool) -
             '"' if attr_mode => writer.write_all(b"&quot;"),
             '<' if !attr_mode => writer.write_all(b"&lt;"),
             '>' if !attr_mode => writer.write_all(b"&gt;"),
-            c => writer.write_fmt(format_args!("{}", c)),
+            c => writer.write_fmt(format_args!("{c}")),
         }?;
     }
     Ok(())
diff --git a/xml5ever/src/tokenizer/mod.rs b/xml5ever/src/tokenizer/mod.rs
index 84f296ec..ff70879a 100644
--- a/xml5ever/src/tokenizer/mod.rs
+++ b/xml5ever/src/tokenizer/mod.rs
@@ -256,7 +256,7 @@ impl<Sink: TokenSink> XmlTokenizer<Sink> {
                 _ => false,
             }
         {
-            let msg = format!("Bad character {}", c);
+            let msg = format!("Bad character {c}");
             self.emit_error(Cow::Owned(msg));
         }
 
diff --git a/xml5ever/src/tree_builder/mod.rs b/xml5ever/src/tree_builder/mod.rs
index 19427277..4c4e0c49 100644
--- a/xml5ever/src/tree_builder/mod.rs
+++ b/xml5ever/src/tree_builder/mod.rs
@@ -70,7 +70,7 @@ impl Debug for NamespaceMap {
     fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
         write!(f, "\nNamespaceMap[")?;
         for (key, value) in &self.scope {
-            writeln!(f, "   {:?} : {:?}", key, value)?;
+            writeln!(f, "   {key:?} : {value:?}")?;
         }
         write!(f, "]")
     }


Test patch:
diff --git a/rcdom/tests/html-tokenizer.rs b/rcdom/tests/html-tokenizer.rs
index 1e4bfcdc..87e0b366 100644
--- a/rcdom/tests/html-tokenizer.rs
+++ b/rcdom/tests/html-tokenizer.rs
@@ -260,7 +260,7 @@ fn json_to_token(js: &Value) -> Token {
 
         // We don't need to produce NullCharacterToken because
         // the TokenLogger will convert them to CharacterTokens.
-        _ => panic!("don't understand token {:?}", parts),
+        _ => panic!("don't understand token {parts:?}"),
     }
 }
 
@@ -355,10 +355,7 @@ fn mk_test(
                 let output = tokenize(input.clone(), opts.clone());
                 let expect_toks = json_to_tokens(&expect, &expect_errors, opts.exact_errors);
                 if output != expect_toks {
-                    panic!(
-                        "\ninput: {:?}\ngot: {:?}\nexpected: {:?}",
-                        input, output, expect_toks
-                    );
+                    panic!("\ninput: {input:?}\ngot: {output:?}\nexpected: {expect_toks:?}");
                 }
             }
         }),
@@ -404,7 +401,7 @@ fn mk_tests(tests: &mut Vec<Test>, filename: &str, js: &Value) {
                     "Script data state" => RawData(ScriptData),
                     "CDATA section state" => CdataSection,
                     "Data state" => Data,
-                    s => panic!("don't know state {}", s),
+                    s => panic!("don't know state {s}"),
                 })
             })
             .collect(),
@@ -417,10 +414,10 @@ fn mk_tests(tests: &mut Vec<Test>, filename: &str, js: &Value) {
         for &exact_errors in [false, true].iter() {
             let mut newdesc = desc.clone();
             if let Some(s) = state {
-                newdesc = format!("{} (in state {:?})", newdesc, s)
+                newdesc = format!("{newdesc} (in state {s:?})")
             };
             if exact_errors {
-                newdesc = format!("{} (exact errors)", newdesc);
+                newdesc = format!("{newdesc} (exact errors)");
             }
 
             tests.push(mk_test(
diff --git a/rcdom/tests/html-tree-builder.rs b/rcdom/tests/html-tree-builder.rs
index 58b1bc6b..2cd8d0b6 100644
--- a/rcdom/tests/html-tree-builder.rs
+++ b/rcdom/tests/html-tree-builder.rs
@@ -90,7 +90,7 @@ fn serialize(buf: &mut String, indent: usize, handle: Handle) {
             buf.push_str("<!DOCTYPE ");
             buf.push_str(name);
             if !public_id.is_empty() || !system_id.is_empty() {
-                buf.push_str(&format!(" \"{}\" \"{}\"", public_id, system_id));
+                buf.push_str(&format!(" \"{public_id}\" \"{system_id}\""));
             }
             buf.push_str(">\n");
         },
@@ -176,7 +176,7 @@ fn make_test(
     } else {
         &scripting_flags[0..2]
     };
-    let name = format!("tb: {}-{}", filename, idx);
+    let name = format!("tb: {filename}-{idx}");
     for scripting_enabled in scripting_flags {
         let test = make_test_desc_with_scripting_flag(ignores, &name, &fields, *scripting_enabled);
         tests.push(test);
@@ -240,10 +240,7 @@ fn make_test_desc_with_scripting_flag(
             result.truncate(len - 1); // drop the trailing newline
 
             if result != expected {
-                panic!(
-                    "\ninput: {}\ngot:\n{}\nexpected:\n{}\n",
-                    data, result, expected
-                );
+                panic!("\ninput: {data}\ngot:\n{result}\nexpected:\n{expected}\n");
             }
         }),
     }
diff --git a/rcdom/tests/xml-tokenizer.rs b/rcdom/tests/xml-tokenizer.rs
index d15d9f3d..5c33f2e8 100644
--- a/rcdom/tests/xml-tokenizer.rs
+++ b/rcdom/tests/xml-tokenizer.rs
@@ -262,7 +262,7 @@ fn json_to_token(js: &Value) -> Token {
 
         // We don't need to produce NullCharacterToken because
         // the TokenLogger will convert them to CharacterTokens.
-        _ => panic!("don't understand token {:?}", parts),
+        _ => panic!("don't understand token {parts:?}"),
     }
 }
 
@@ -297,10 +297,7 @@ fn mk_xml_test(name: String, input: String, expect: Value, opts: XmlTokenizerOpt
                 let output = tokenize_xml(input.clone(), opts);
                 let expect = json_to_tokens(&expect, opts.exact_errors);
                 if output != expect {
-                    panic!(
-                        "\ninput: {:?}\ngot: {:?}\nexpected: {:?}",
-                        input, output, expect
-                    );
+                    panic!("\ninput: {input:?}\ngot: {output:?}\nexpected: {expect:?}");
                 }
             }
         }),
@@ -320,10 +317,10 @@ fn mk_xml_tests(tests: &mut Vec<Test>, filename: &str, js: &Value) {
         for &exact_errors in [false, true].iter() {
             let mut newdesc = desc.clone();
             if let Some(s) = state {
-                newdesc = format!("{} (in state {:?})", newdesc, s)
+                newdesc = format!("{newdesc} (in state {s:?})")
             };
             if exact_errors {
-                newdesc = format!("{} (exact errors)", newdesc);
+                newdesc = format!("{newdesc} (exact errors)");
             }
 
             tests.push(mk_xml_test(
diff --git a/rcdom/tests/xml-tree-builder.rs b/rcdom/tests/xml-tree-builder.rs
index 5985551c..b5362f9f 100644
--- a/rcdom/tests/xml-tree-builder.rs
+++ b/rcdom/tests/xml-tree-builder.rs
@@ -84,7 +84,7 @@ fn serialize(buf: &mut String, indent: usize, handle: Handle) {
             buf.push_str("<!DOCTYPE ");
             buf.push_str(name);
             if !public_id.is_empty() || !system_id.is_empty() {
-                buf.push_str(&format!(" \"{}\" \"{}\"", public_id, system_id));
+                buf.push_str(&format!(" \"{public_id}\" \"{system_id}\""));
             }
             buf.push_str(">\n");
         },
@@ -172,7 +172,7 @@ fn make_xml_test(
 
     let data = get_field("data");
     let expected = get_field("document");
-    let name = format!("tb: {}-{}", filename, idx);
+    let name = format!("tb: {filename}-{idx}");
     let skip = ignores.contains(&name) || IGNORE_SUBSTRS.iter().any(|&ig| data.contains(ig));
 
     tests.push(Test {
@@ -190,10 +190,7 @@ fn make_xml_test(
             result.truncate(len - 1); // drop the trailing newline
 
             if result != expected {
-                panic!(
-                    "\ninput: {}\ngot:\n{}\nexpected:\n{}\n",
-                    data, result, expected
-                );
+                panic!("\ninput: {data}\ngot:\n{result}\nexpected:\n{expected}\n");
             }
         }),
     });