From d0e6a4a80abcca245aaa0960c779c5d6b0a6d521 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 10 Sep 2025 13:12:22 -0400 Subject: De-box DuplicateKey error It's probably okay for Error to be a whopping 72 bytes big. --- src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5f4a991..e30d7d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ pub enum Error { /// Key contains invalid characters. /// /// The valid characters are anything outside of ASCII, - /// as well as `a`–`z`, `A`–`Z`, `0`-`9`, and each of `/.-*_`. + /// as well as `a`–`z`, `A`–`Z`, `0`–`9`, and each of `/.-*_`. InvalidKey(Location, Box), /// Value contains a null character. /// @@ -116,7 +116,7 @@ pub enum Error { /// Invalid escape sequence appears in a quoted value. InvalidEscapeSequence(Location, Box), /// Key is defined twice in a file - DuplicateKey(Box<(Box, Location, Location)>), + DuplicateKey(Box, Location, Location), /// Used when there is more than one error in a file. /// /// None of the errors in the array will be [`Error::Multiple`]'s, @@ -165,8 +165,7 @@ impl fmt::Display for Error { f, "{location}: invalid escape sequence {sequence:?} (try using \\\\ instead of \\ maybe?)", ), - Self::DuplicateKey(info) => { - let (key, loc1, loc2) = info.as_ref(); + Self::DuplicateKey(key, loc1, loc2) => { write!(f, "{loc2}: key {key} was already defined at {loc1}") } Self::Multiple(errs) => { @@ -661,11 +660,11 @@ impl Parser { for window in items.windows(2) { if window[0].0 == window[1].0 { // duplicate key - self.nonfatal_errors.push(Error::DuplicateKey(Box::new(( + self.nonfatal_errors.push(Error::DuplicateKey( window[0].0.clone(), window[0].1.defined_at.clone(), window[1].1.defined_at.clone(), - )))); + )); } } check_error_vec(take(&mut self.nonfatal_errors))?; -- cgit v1.2.3