Repository: toml-rs/toml
Pull request #795 (2024-09-27 18:29:30)

chore: Update from _rust template


Patch:
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
index 1b000abf..7b55a3d9 100644
--- a/.github/workflows/pre-commit.yml
+++ b/.github/workflows/pre-commit.yml
@@ -24,4 +24,6 @@ jobs:
     steps:
     - uses: actions/checkout@v4
     - uses: actions/setup-python@v5
+      with:
+        python-version: '3.x'
     - uses: pre-commit/action@v3.0.1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 534546e8..caa7e747 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp
 PRs should tell a cohesive story, with test and refactor commits that keep the
 fix or feature commits simple and clear.
 
-Specifically, we would encouage
+Specifically, we would encourage
 - File renames be isolated into their own commit
 - Add tests in a commit before their feature or fix, showing the current behavior.
   The diff for the feature/fix commit will then show how the behavior changed,
diff --git a/Cargo.toml b/Cargo.toml
index 3105492f..0f833983 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -83,6 +83,7 @@ string_lit_as_bytes = "warn"
 string_to_string = "warn"
 todo = "warn"
 trait_duplication_in_bounds = "warn"
+uninlined_format_args = "warn"
 verbose_file_reads = "warn"
 wildcard_imports = "warn"
 zero_sized_map_values = "warn"
diff --git a/crates/benchmarks/benches/linear.rs b/crates/benchmarks/benches/linear.rs
index e11636af..47b47e57 100644
--- a/crates/benchmarks/benches/linear.rs
+++ b/crates/benchmarks/benches/linear.rs
@@ -32,7 +32,7 @@ mod map {
     fn gen(num_entries: usize) -> String {
         let mut s = String::new();
         for i in 0..num_entries {
-            s += &format!("[header_no_{}]\n", i);
+            s += &format!("[header_no_{i}]\n");
             s += "entry = 42\n";
         }
         s
diff --git a/crates/toml/examples/decode.rs b/crates/toml/examples/decode.rs
index 348e9116..f09eec68 100644
--- a/crates/toml/examples/decode.rs
+++ b/crates/toml/examples/decode.rs
@@ -50,5 +50,5 @@ fn main() {
     "#;
 
     let decoded: Config = toml::from_str(toml_str).unwrap();
-    println!("{:#?}", decoded);
+    println!("{decoded:#?}");
 }
diff --git a/crates/toml/examples/enum_external.rs b/crates/toml/examples/enum_external.rs
index edac7d6e..5c95fde1 100644
--- a/crates/toml/examples/enum_external.rs
+++ b/crates/toml/examples/enum_external.rs
@@ -41,5 +41,5 @@ fn main() {
     ]"#;
 
     let decoded: Config = toml::from_str(toml_str).unwrap();
-    println!("{:#?}", decoded);
+    println!("{decoded:#?}");
 }
diff --git a/crates/toml/examples/toml2json.rs b/crates/toml/examples/toml2json.rs
index 56a912c9..2ae96289 100644
--- a/crates/toml/examples/toml2json.rs
+++ b/crates/toml/examples/toml2json.rs
@@ -21,7 +21,7 @@ fn main() {
             let json = convert(toml);
             println!("{}", serde_json::to_string_pretty(&json).unwrap());
         }
-        Err(error) => println!("failed to parse TOML: {}", error),
+        Err(error) => println!("failed to parse TOML: {error}"),
     }
 }
 
diff --git a/crates/toml/src/ser.rs b/crates/toml/src/ser.rs
index b64271a1..955e243b 100644
--- a/crates/toml/src/ser.rs
+++ b/crates/toml/src/ser.rs
@@ -915,7 +915,7 @@ mod internal {
         settings.visit_table_mut(&mut table);
 
         let doc: toml_edit::DocumentMut = table.into();
-        write!(dst, "{}", doc).unwrap();
+        write!(dst, "{doc}").unwrap();
 
         Ok(())
     }
@@ -1067,7 +1067,7 @@ mod internal {
 
         let value = value.map_err(Error::wrap)?;
 
-        write!(dst, "{}", value).unwrap();
+        write!(dst, "{value}").unwrap();
 
         Ok(())
     }
diff --git a/crates/toml/src/value.rs b/crates/toml/src/value.rs
index c689b383..1052fced 100644
--- a/crates/toml/src/value.rs
+++ b/crates/toml/src/value.rs
@@ -530,7 +530,7 @@ impl<'de> de::Deserialize<'de> for Value {
                     if let crate::map::Entry::Vacant(vacant) = map.entry(&key) {
                         vacant.insert(visitor.next_value()?);
                     } else {
-                        let msg = format!("duplicate key: `{}`", key);
+                        let msg = format!("duplicate key: `{key}`");
                         return Err(de::Error::custom(msg));
                     }
                 }
@@ -808,7 +808,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
                 if values.len() == len {
                     de::Deserializer::deserialize_seq(values.into_deserializer(), visitor)
                 } else {
-                    Err(Error::custom(format!("expected tuple with length {}", len)))
+                    Err(Error::custom(format!("expected tuple with length {len}")))
                 }
             }
             Value::Table(values) => {
@@ -818,8 +818,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
                     .map(|(index, (key, value))| match key.parse::<usize>() {
                         Ok(key_index) if key_index == index => Ok(value),
                         Ok(_) | Err(_) => Err(Error::custom(format!(
-                            "expected table key `{}`, but was `{}`",
-                            index, key
+                            "expected table key `{index}`, but was `{key}`"
                         ))),
                     })
                     .collect();
@@ -828,7 +827,7 @@ impl<'de> de::VariantAccess<'de> for MapEnumDeserializer {
                 if tuple_values.len() == len {
                     de::Deserializer::deserialize_seq(tuple_values.into_deserializer(), visitor)
                 } else {
-                    Err(Error::custom(format!("expected tuple with length {}", len)))
+                    Err(Error::custom(format!("expected tuple with length {len}")))
                 }
             }
             e => Err(Error::custom(format!(
diff --git a/crates/toml_datetime/src/datetime.rs b/crates/toml_datetime/src/datetime.rs
index cea13b9f..d4a93615 100644
--- a/crates/toml_datetime/src/datetime.rs
+++ b/crates/toml_datetime/src/datetime.rs
@@ -238,16 +238,16 @@ impl From<Time> for Datetime {
 impl fmt::Display for Datetime {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         if let Some(ref date) = self.date {
-            write!(f, "{}", date)?;
+            write!(f, "{date}")?;
         }
         if let Some(ref time) = self.time {
             if self.date.is_some() {
                 write!(f, "T")?;
             }
-            write!(f, "{}", time)?;
+            write!(f, "{time}")?;
         }
         if let Some(ref offset) = self.offset {
-            write!(f, "{}", offset)?;
+            write!(f, "{offset}")?;
         }
         Ok(())
     }
@@ -282,7 +282,7 @@ impl fmt::Display for Offset {
                 }
                 let hours = minutes / 60;
                 let minutes = minutes % 60;
-                write!(f, "{}{:02}:{:02}", sign, hours, minutes)
+                write!(f, "{sign}{hours:02}:{minutes:02}")
             }
         }
     }
diff --git a/crates/toml_edit/examples/visit.rs b/crates/toml_edit/examples/visit.rs
index 3f523346..8d9156eb 100644
--- a/crates/toml_edit/examples/visit.rs
+++ b/crates/toml_edit/examples/visit.rs
@@ -250,7 +250,7 @@ fn main() {
 
     println!("** visit_mut example");
     visit_mut_example(&mut document);
-    println!("{}", document);
+    println!("{document}");
 }
 
 #[cfg(test)]
@@ -280,5 +280,5 @@ fn visit_mut_correct() {
     let mut document: DocumentMut = INPUT.parse().expect("input is valid TOML");
 
     visit_mut_example(&mut document);
-    assert_eq!(format!("{}", document), VISIT_MUT_OUTPUT);
+    assert_eq!(format!("{document}"), VISIT_MUT_OUTPUT);
 }
diff --git a/crates/toml_edit/src/array.rs b/crates/toml_edit/src/array.rs
index 3e69d5c7..3f1920e7 100644
--- a/crates/toml_edit/src/array.rs
+++ b/crates/toml_edit/src/array.rs
@@ -287,7 +287,7 @@ impl Array {
     pub fn replace_formatted(&mut self, index: usize, v: Value) -> Value {
         match mem::replace(&mut self.values[index], Item::Value(v)) {
             Item::Value(old_value) => old_value,
-            x => panic!("non-value item {:?} in an array", x),
+            x => panic!("non-value item {x:?} in an array"),
         }
     }
 
@@ -307,7 +307,7 @@ impl Array {
         let removed = self.values.remove(index);
         match removed {
             Item::Value(v) => v,
-            x => panic!("non-value item {:?} in an array", x),
+            x => panic!("non-value item {x:?} in an array"),
         }
     }
 
diff --git a/crates/toml_edit/src/de/table_enum.rs b/crates/toml_edit/src/de/table_enum.rs
index 8c3433f4..9a4276de 100644
--- a/crates/toml_edit/src/de/table_enum.rs
+++ b/crates/toml_edit/src/de/table_enum.rs
@@ -74,7 +74,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
                     )
                 } else {
                     Err(Error::custom(
-                        format!("expected tuple with length {}", len),
+                        format!("expected tuple with length {len}"),
                         values_span,
                     ))
                 }
@@ -90,7 +90,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
                     )
                 } else {
                     Err(Error::custom(
-                        format!("expected tuple with length {}", len),
+                        format!("expected tuple with length {len}"),
                         values_span,
                     ))
                 }
@@ -118,7 +118,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
                     )
                 } else {
                     Err(Error::custom(
-                        format!("expected tuple with length {}", len),
+                        format!("expected tuple with length {len}"),
                         values_span,
                     ))
                 }
@@ -146,7 +146,7 @@ impl<'de> serde::de::VariantAccess<'de> for TableEnumDeserializer {
                     )
                 } else {
                     Err(Error::custom(
-                        format!("expected tuple with length {}", len),
+                        format!("expected tuple with length {len}"),
                         values_span,
                     ))
                 }
diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs
index 54319c4a..ea917b10 100644
--- a/crates/toml_edit/src/encode.rs
+++ b/crates/toml_edit/src/encode.rs
@@ -24,7 +24,7 @@ pub(crate) fn encode_key(this: &Key, buf: &mut dyn Write, input: Option<&str>) -
         repr.encode(buf, input)?;
     } else {
         let repr = this.display_repr();
-        write!(buf, "{}", repr)?;
+        write!(buf, "{repr}")?;
     };
 
     Ok(())
@@ -109,7 +109,7 @@ pub(crate) fn encode_formatted<T: ValueRepr>(
         repr.encode(buf, input)?;
     } else {
         let repr = this.display_repr();
-        write!(buf, "{}", repr)?;
+        write!(buf, "{repr}")?;
     };
 
     decor.suffix_encode(buf, input, default_decor.1)?;
@@ -533,9 +533,9 @@ fn to_f64_repr(f: f64) -> Repr {
         (false, false, true) => "0.0".to_owned(),
         (_, false, false) => {
             if f % 1.0 == 0.0 {
-                format!("{}.0", f)
+                format!("{f}.0")
             } else {
-                format!("{}", f)
+                format!("{f}")
             }
         }
     };
diff --git a/crates/toml_edit/src/error.rs b/crates/toml_edit/src/error.rs
index 57c21ef9..e7f94be0 100644
--- a/crates/toml_edit/src/error.rs
+++ b/crates/toml_edit/src/error.rs
@@ -111,11 +111,7 @@ impl Display for TomlError {
             // Allow highlight to go one past the line
             let highlight_len = highlight_len.min(content.len().saturating_sub(column));
 
-            writeln!(
-                f,
-                "TOML parse error at line {}, column {}",
-                line_num, col_num
-            )?;
+            writeln!(f, "TOML parse error at line {line_num}, column {col_num}")?;
             //   |
             for _ in 0..=gutter {
                 write!(f, " ")?;
@@ -123,8 +119,8 @@ impl Display for TomlError {
             writeln!(f, "|")?;
 
             // 1 | 00:32:00.a999999
-            write!(f, "{} | ", line_num)?;
-            writeln!(f, "{}", content)?;
+            write!(f, "{line_num} | ")?;
+            writeln!(f, "{content}")?;
 
             //   |          ^
             for _ in 0..=gutter {
diff --git a/crates/toml_edit/src/parser/error.rs b/crates/toml_edit/src/parser/error.rs
index 22e8e662..bd6cd1ac 100644
--- a/crates/toml_edit/src/parser/error.rs
+++ b/crates/toml_edit/src/parser/error.rs
@@ -63,21 +63,20 @@ impl Display for CustomError {
             CustomError::DuplicateKey { key, table } => {
                 if let Some(table) = table {
                     if table.is_empty() {
-                        write!(f, "duplicate key `{}` in document root", key)
+                        write!(f, "duplicate key `{key}` in document root")
                     } else {
                         let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
-                        write!(f, "duplicate key `{}` in table `{}`", key, path)
+                        write!(f, "duplicate key `{key}` in table `{path}`")
                     }
                 } else {
-                    write!(f, "duplicate key `{}`", key)
+                    write!(f, "duplicate key `{key}`")
                 }
             }
             CustomError::DottedKeyExtendWrongType { key, actual } => {
                 let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
                 write!(
                     f,
-                    "dotted key `{}` attempted to extend non-table type ({})",
-                    path, actual
+                    "dotted key `{path}` attempted to extend non-table type ({actual})"
                 )
             }
             CustomError::OutOfRange => write!(f, "value is out of range"),
diff --git a/crates/toml_edit/src/parser/mod.rs b/crates/toml_edit/src/parser/mod.rs
index 1d5dbcf1..e0d9e4f0 100644
--- a/crates/toml_edit/src/parser/mod.rs
+++ b/crates/toml_edit/src/parser/mod.rs
@@ -226,10 +226,7 @@ key = "value"
             let doc = match parsed {
                 Ok(doc) => doc,
                 Err(err) => {
-                    panic!(
-                        "Parse error: {:?}\nFailed to parse:\n```\n{}\n```",
-                        err, input
-                    )
+                    panic!("Parse error: {err:?}\nFailed to parse:\n```\n{input}\n```")
                 }
             };
 
@@ -251,10 +248,7 @@ authors = []
             match parsed {
                 Ok(_) => (),
                 Err(err) => {
-                    panic!(
-                        "Parse error: {:?}\nFailed to parse:\n```\n{}\n```",
-                        err, input
-                    )
+                    panic!("Parse error: {err:?}\nFailed to parse:\n```\n{input}\n```")
                 }
             }
         }
@@ -267,7 +261,7 @@ $"#];
         for input in invalid_inputs {
             dbg!(input);
             let parsed = parse_document(input).map(|d| d.into_mut());
-            assert!(parsed.is_err(), "Input: {:?}", input);
+            assert!(parsed.is_err(), "Input: {input:?}");
         }
     }
 }
diff --git a/crates/toml_edit/src/parser/numbers.rs b/crates/toml_edit/src/parser/numbers.rs
index 2310f247..e3811e69 100644
--- a/crates/toml_edit/src/parser/numbers.rs
+++ b/crates/toml_edit/src/parser/numbers.rs
@@ -393,7 +393,7 @@ mod test {
 
             let overflow = "9e99999";
             let parsed = float.parse(new_input(overflow));
-            assert!(parsed.is_err(), "{:?}", parsed);
+            assert!(parsed.is_err(), "{parsed:?}");
         }
     }
 }
diff --git a/crates/toml_edit/src/parser/trivia.rs b/crates/toml_edit/src/parser/trivia.rs
index 5630bca9..33486b44 100644
--- a/crates/toml_edit/src/parser/trivia.rs
+++ b/crates/toml_edit/src/parser/trivia.rs
@@ -159,7 +159,7 @@ mod test {
         for input in inputs {
             dbg!(input);
             let parsed = ws_comment_newline.take().parse(new_input(input));
-            assert!(parsed.is_ok(), "{:?}", parsed);
+            assert!(parsed.is_ok(), "{parsed:?}");
             let parsed = parsed.unwrap();
             assert_eq!(parsed, input.as_bytes());
         }
diff --git a/crates/toml_edit/src/raw_string.rs b/crates/toml_edit/src/raw_string.rs
index 0bde3b78..b16594c6 100644
--- a/crates/toml_edit/src/raw_string.rs
+++ b/crates/toml_edit/src/raw_string.rs
@@ -46,9 +46,9 @@ impl RawString {
         match &self.0 {
             RawStringInner::Empty => "",
             RawStringInner::Explicit(s) => s.as_str(),
-            RawStringInner::Spanned(span) => input.get(span.clone()).unwrap_or_else(|| {
-                panic!("span {:?} should be in input:\n```\n{}\n```", span, input)
-            }),
+            RawStringInner::Spanned(span) => input
+                .get(span.clone())
+                .unwrap_or_else(|| panic!("span {span:?} should be in input:\n```\n{input}\n```")),
         }
     }
 
@@ -63,7 +63,7 @@ impl RawString {
             RawStringInner::Spanned(span) => {
                 if let Some(input) = input {
                     input.get(span.clone()).unwrap_or_else(|| {
-                        panic!("span {:?} should be in input:\n```\n{}\n```", span, input)
+                        panic!("span {span:?} should be in input:\n```\n{input}\n```")
                     })
                 } else {
                     default
@@ -78,7 +78,7 @@ impl RawString {
             RawStringInner::Explicit(_) => {}
             RawStringInner::Spanned(span) => {
                 *self = Self::from(input.get(span.clone()).unwrap_or_else(|| {
-                    panic!("span {:?} should be in input:\n```\n{}\n```", span, input)
+                    panic!("span {span:?} should be in input:\n```\n{input}\n```")
                 }));
             }
         }
@@ -88,7 +88,7 @@ impl RawString {
     pub(crate) fn encode(&self, buf: &mut dyn std::fmt::Write, input: &str) -> std::fmt::Result {
         let raw = self.to_str(input);
         for part in raw.split('\r') {
-            write!(buf, "{}", part)?;
+            write!(buf, "{part}")?;
         }
         Ok(())
     }
@@ -102,7 +102,7 @@ impl RawString {
     ) -> std::fmt::Result {
         let raw = self.to_str_with_default(input, default);
         for part in raw.split('\r') {
-            write!(buf, "{}", part)?;
+            write!(buf, "{part}")?;
         }
         Ok(())
     }
@@ -119,8 +119,8 @@ impl std::fmt::Debug for RawString {
     fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
         match &self.0 {
             RawStringInner::Empty => write!(formatter, "empty"),
-            RawStringInner::Explicit(s) => write!(formatter, "{:?}", s),
-            RawStringInner::Spanned(s) => write!(formatter, "{:?}", s),
+            RawStringInner::Explicit(s) => write!(formatter, "{s:?}"),
+            RawStringInner::Spanned(s) => write!(formatter, "{s:?}"),
         }
     }
 }
diff --git a/crates/toml_edit/src/repr.rs b/crates/toml_edit/src/repr.rs
index 80d78c38..cae7cac3 100644
--- a/crates/toml_edit/src/repr.rs
+++ b/crates/toml_edit/src/repr.rs
@@ -215,7 +215,7 @@ impl Decor {
         if let Some(prefix) = self.prefix() {
             prefix.encode_with_default(buf, input, default)
         } else {
-            write!(buf, "{}", default)
+            write!(buf, "{default}")
         }
     }
 
@@ -239,7 +239,7 @@ impl Decor {
         if let Some(suffix) = self.suffix() {
             suffix.encode_with_default(buf, input, default)
         } else {
-            write!(buf, "{}", default)
+            write!(buf, "{default}")
         }
     }
 


Test patch:
diff --git a/crates/toml/tests/testsuite/spanned.rs b/crates/toml/tests/testsuite/spanned.rs
index daf7601b..b5c17d46 100644
--- a/crates/toml/tests/testsuite/spanned.rs
+++ b/crates/toml/tests/testsuite/spanned.rs
@@ -82,7 +82,7 @@ fn test_spanned_field() {
     );
 
     for expected in good_datetimes() {
-        let s = format!("foo = {}", expected);
+        let s = format!("foo = {expected}");
         good::<Datetime>(&s, expected, None);
     }
     // ending at something other than the absolute end
diff --git a/crates/toml_edit/tests/testsuite/datetime.rs b/crates/toml_edit/tests/testsuite/datetime.rs
index dba89ec5..53c87db9 100644
--- a/crates/toml_edit/tests/testsuite/datetime.rs
+++ b/crates/toml_edit/tests/testsuite/datetime.rs
@@ -14,7 +14,7 @@ macro_rules! bad {
 #[test]
 fn times() {
     fn dogood(s: &str, serialized: &str) {
-        let to_parse = format!("foo = {}", s);
+        let to_parse = format!("foo = {s}");
         let document = to_parse.parse::<toml_edit::DocumentMut>().unwrap();
         assert_eq!(
             document["foo"].as_datetime().unwrap().to_string(),
diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs
index 092d3c3d..39e00cfd 100644
--- a/crates/toml_edit/tests/testsuite/parse.rs
+++ b/crates/toml_edit/tests/testsuite/parse.rs
@@ -955,7 +955,7 @@ fn table_names() {
     "
     .parse::<DocumentMut>()
     .unwrap();
-    println!("{:?}", a);
+    println!("{a:?}");
     let _ = &a["a"]["b"];
     let _ = &a["f f"];
     let _ = &a["f.f"];