From 08cb60e17d78e6f7a860b56d0d54205d5316ca2a Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 10 Jul 2025 08:34:22 +0000 Subject: [PATCH 1/3] make it work with recent rustc: - deny(missing_docs) -> warn - remove #![cfg_attr(not(feature = "std"), feature(alloc))] --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9291fc9..7dcc723 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(not(feature = "std"), feature(alloc))] -#![deny(missing_docs)] +#![warn(missing_docs)] #![doc(html_root_url = "https://docs.rs/throw/0.1.7")] //! Throw! //! ------ From 3b06ff3af7c9b22726b6e91a1d5d30af7bda4438 Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 10 Jul 2025 09:27:10 +0000 Subject: [PATCH 2/3] clippy fixes --- src/lib.rs | 111 +++++++++++++++++++-------------------- tests/exceptions_work.rs | 5 +- 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7dcc723..09c7d26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -262,92 +262,92 @@ pub enum ThrowContextValues { impl fmt::Display for ThrowContextValues { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - ThrowContextValues::Bool(ref x) => write!(f, "{}", x), - ThrowContextValues::Int8(ref x) => write!(f, "{}", x), - ThrowContextValues::Uint8(ref x) => write!(f, "{}", x), - ThrowContextValues::Int16(ref x) => write!(f, "{}", x), - ThrowContextValues::Uint16(ref x) => write!(f, "{}", x), - ThrowContextValues::Int32(ref x) => write!(f, "{}", x), - ThrowContextValues::Uint32(ref x) => write!(f, "{}", x), - ThrowContextValues::Int64(ref x) => write!(f, "{}", x), - ThrowContextValues::Uint64(ref x) => write!(f, "{}", x), - ThrowContextValues::Float32(ref x) => write!(f, "{}", x), - ThrowContextValues::Float64(ref x) => write!(f, "{}", x), - ThrowContextValues::String(ref x) => write!(f, "{}", x), - ThrowContextValues::StaticStr(ref x) => write!(f, "{}", x), + ThrowContextValues::Bool(ref x) => write!(f, "{x}"), + ThrowContextValues::Int8(ref x) => write!(f, "{x}"), + ThrowContextValues::Uint8(ref x) => write!(f, "{x}"), + ThrowContextValues::Int16(ref x) => write!(f, "{x}"), + ThrowContextValues::Uint16(ref x) => write!(f, "{x}"), + ThrowContextValues::Int32(ref x) => write!(f, "{x}"), + ThrowContextValues::Uint32(ref x) => write!(f, "{x}"), + ThrowContextValues::Int64(ref x) => write!(f, "{x}"), + ThrowContextValues::Uint64(ref x) => write!(f, "{x}"), + ThrowContextValues::Float32(ref x) => write!(f, "{x}"), + ThrowContextValues::Float64(ref x) => write!(f, "{x}"), + ThrowContextValues::String(ref x) => write!(f, "{x}"), + ThrowContextValues::StaticStr(ref x) => write!(f, "{x}"), } } } -impl Into for u8 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Uint8(self) +impl From for ThrowContextValues { + fn from(val: u8) -> Self { + ThrowContextValues::Uint8(val) } } -impl Into for i8 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Int8(self) +impl From for ThrowContextValues { + fn from(val: i8) -> Self { + ThrowContextValues::Int8(val) } } -impl Into for u16 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Uint16(self) +impl From for ThrowContextValues { + fn from(val: u16) -> Self { + ThrowContextValues::Uint16(val) } } -impl Into for i16 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Int16(self) +impl From for ThrowContextValues { + fn from(val: i16) -> Self { + ThrowContextValues::Int16(val) } } -impl Into for u32 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Uint32(self) +impl From for ThrowContextValues { + fn from(val: u32) -> Self { + ThrowContextValues::Uint32(val) } } -impl Into for i32 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Int32(self) +impl From for ThrowContextValues { + fn from(val: i32) -> Self { + ThrowContextValues::Int32(val) } } -impl Into for u64 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Uint64(self) +impl From for ThrowContextValues { + fn from(val: u64) -> Self { + ThrowContextValues::Uint64(val) } } -impl Into for i64 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Int64(self) +impl From for ThrowContextValues { + fn from(val: i64) -> Self { + ThrowContextValues::Int64(val) } } -impl Into for f32 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Float32(self) +impl From for ThrowContextValues { + fn from(val: f32) -> Self { + ThrowContextValues::Float32(val) } } -impl Into for f64 { - fn into(self) -> ThrowContextValues { - ThrowContextValues::Float64(self) +impl From for ThrowContextValues { + fn from(val: f64) -> Self { + ThrowContextValues::Float64(val) } } -impl<'a> Into for &'static str { - fn into(self) -> ThrowContextValues { - ThrowContextValues::StaticStr(self) +impl From<&'static str> for ThrowContextValues { + fn from(val: &'static str) -> Self { + ThrowContextValues::StaticStr(val) } } -impl Into for String { - fn into(self) -> ThrowContextValues { - ThrowContextValues::String(self) +impl From for ThrowContextValues { + fn from(val: String) -> Self { + ThrowContextValues::String(val) } } @@ -400,10 +400,10 @@ impl ErrorPoint { file: &'static str, ) -> ErrorPoint { ErrorPoint { - line: line, - column: column, - module_path: module_path, - file: file, + line, + column, + module_path, + file, } } } @@ -438,7 +438,6 @@ impl KvPair { /// Represents an error. Stores an original error of type E, and any number of ErrorPoints at /// which the error was propagated. - pub struct Error { points: Vec, context: Vec, @@ -466,7 +465,7 @@ impl Error { Error { points: Vec::new(), context: Vec::new(), - error: error, + error, } } @@ -596,7 +595,7 @@ where self.error().description() } - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { Some(self.error()) } } diff --git a/tests/exceptions_work.rs b/tests/exceptions_work.rs index 203093e..625f558 100644 --- a/tests/exceptions_work.rs +++ b/tests/exceptions_work.rs @@ -15,10 +15,7 @@ macro_rules! assert_matches { assert!( re.is_match(&actual), - format!( - "expected error to match regex `\n{}\n`, but found `\n{}\n`", - expected, actual - ) + "expected error to match regex `\n{expected}\n`, but found `\n{actual}\n`", ); }}; } From 1098695050d00e54beb683bc86205a020ed628bd Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 10 Jul 2025 09:48:22 +0000 Subject: [PATCH 3/3] edition 2024 --- Cargo.toml | 1 + benches/lib.rs | 2 +- src/lib.rs | 38 +++++++++++++------------------------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4fef36d..d1afe4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ name = "throw" version = "0.1.7" authors = ["David Ross "] description = "Efficiently add statically-calculated stack traces to errors." +edition = "2024" documentation = "https://docs.rs/throw/" repository = "https://github.com/daboross/rust-throw/" diff --git a/benches/lib.rs b/benches/lib.rs index 604cf91..09b8efe 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -32,7 +32,7 @@ fn throws_throw_ok() -> Result<&'static str, &'static str> { #[inline(never)] fn throws_try_ok() -> StdResult<&'static str, &'static str> { - let ok_msg = test::black_box(try!(gives_ok())); + let ok_msg = test::black_box(gives_ok()?); Ok(ok_msg) } diff --git a/src/lib.rs b/src/lib.rs index 09c7d26..89b4d1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,14 +222,8 @@ use serde::ser::{Serialize, SerializeStruct, Serializer}; /// Types allowed to be value in the context vector #[derive(Debug, Clone)] -#[cfg_attr( - any(feature = "serde-1", feature = "serde-1-std"), - derive(Serialize) -)] -#[cfg_attr( - any(feature = "serde-1", feature = "serde-1-std"), - serde(untagged) -)] +#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))] +#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), serde(untagged))] pub enum ThrowContextValues { /// Boolean context value Bool(bool), @@ -356,10 +350,7 @@ pub type Result = core::result::Result>; /// Represents a location at which an error was thrown via throw!() #[derive(Debug)] -#[cfg_attr( - any(feature = "serde-1", feature = "serde-1-std"), - derive(Serialize) -)] +#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))] pub struct ErrorPoint { line: u32, column: u32, @@ -410,10 +401,7 @@ impl ErrorPoint { /// represent a key-value pair #[derive(Debug, Clone)] -#[cfg_attr( - any(feature = "serde-1", feature = "serde-1-std"), - derive(Serialize) -)] +#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))] pub struct KvPair { key: &'static str, value: ThrowContextValues, @@ -541,21 +529,21 @@ where E: fmt::Display, { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, "Error: {}", self.error)); + write!(fmt, "Error: {}", self.error)?; for kv in self.context.iter().rev() { - try!(write!(fmt, "\n\t{}: {}", kv.key(), kv.value(),)); + write!(fmt, "\n\t{}: {}", kv.key(), kv.value(),)?; } for point in self.points.iter().rev() { - try!(write!( + write!( fmt, "\n\tat {}:{} in {} ({})", point.line(), point.column(), point.module_path(), point.file() - )); + )?; } Ok(()) @@ -567,19 +555,19 @@ where E: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(write!(fmt, "Error: {:?}", self.error)); + write!(fmt, "Error: {:?}", self.error)?; for kv in self.context.iter().rev() { - try!(write!(fmt, "\n\t{}: {}", kv.key(), kv.value(),)); + write!(fmt, "\n\t{}: {}", kv.key(), kv.value(),)?; } for point in self.points.iter().rev() { - try!(write!( + write!( fmt, "\n\tat {}:{} in {} ({})", point.line(), point.column(), point.module_path(), point.file() - )); + )?; } Ok(()) @@ -589,7 +577,7 @@ where #[cfg(feature = "std")] impl std::error::Error for Error where - E: std::error::Error + E: std::error::Error, { fn description(&self) -> &str { self.error().description()