fix: clippy

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2023-07-27 12:39:31 +02:00
parent 05085229be
commit d60cdf9cdb
Signed by: harald
GPG key ID: 900F3C4971086004
7 changed files with 14 additions and 13 deletions

View file

@ -18,7 +18,7 @@ fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
derive_str_context!(Func2Error); derive_str_context!(Func2Error);
fn func2() -> ChainResult<(), Func2Error> { fn func2() -> ChainResult<(), Func2Error> {
func3().context(Func2Error(format!("func2 error: calling func3")))?; func3().context(Func2Error("func2 error: calling func3".to_string()))?;
Ok(()) Ok(())
} }

View file

@ -84,7 +84,7 @@ pub mod mycrate {
let filename = "bar.txt"; let filename = "bar.txt";
do_some_io(filename).map_context(|e| ErrorKind::from_io_error(&e, filename.into()))?; do_some_io(filename).map_context(|e| ErrorKind::from_io_error(e, filename.into()))?;
do_some_io(filename).map_context(|_| ErrorKind::IO(filename.into()))?; do_some_io(filename).map_context(|_| ErrorKind::IO(filename.into()))?;
do_some_io(filename).map_context(|e| ErrorKind::from(e))?; do_some_io(filename).map_context(|e| ErrorKind::from(e))?;

View file

@ -15,7 +15,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
} }
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> { fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(format!("func1 error"))?; func2().context("func1 error")?;
Ok(()) Ok(())
} }

View file

@ -19,7 +19,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
derive_str_context!(Func1Error); derive_str_context!(Func1Error);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> { fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1Error(format!("func1 error")))?; func2().context(Func1Error("func1 error".to_string()))?;
Ok(()) Ok(())
} }

View file

@ -20,7 +20,7 @@ derive_str_context!(Func1ErrorFunc2);
derive_str_context!(Func1ErrorIO); derive_str_context!(Func1ErrorIO);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> { fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1ErrorFunc2(format!("func1 error calling func2")))?; func2().context(Func1ErrorFunc2("func1 error calling func2".to_string()))?;
let filename = "bar.txt"; let filename = "bar.txt";
do_some_io().context(Func1ErrorIO(format!("Error reading '{}'", filename)))?; do_some_io().context(Func1ErrorIO(format!("Error reading '{}'", filename)))?;
Ok(()) Ok(())

View file

@ -103,7 +103,6 @@
//! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html) //! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)
#![deny(clippy::all)] #![deny(clippy::all)]
#![deny(clippy::integer_arithmetic)]
#![allow(clippy::needless_doctest_main)] #![allow(clippy::needless_doctest_main)]
#![deny(missing_docs)] #![deny(missing_docs)]
@ -198,7 +197,9 @@ impl<T: 'static + Display + Debug> ChainError<T> {
/// ``` /// ```
#[inline] #[inline]
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> { pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {
self.iter().filter_map(Error::downcast_ref::<U>).next() self.iter()
.filter_map(<dyn Error>::downcast_ref::<U>)
.next()
} }
/// Find the first error cause of type `ChainError<U>`, if any exists /// Find the first error cause of type `ChainError<U>`, if any exists
@ -220,7 +221,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
#[inline] #[inline]
pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>> { pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>> {
self.iter() self.iter()
.filter_map(Error::downcast_ref::<ChainError<U>>) .filter_map(<dyn Error>::downcast_ref::<ChainError<U>>)
.next() .next()
} }
@ -428,7 +429,7 @@ impl<U: 'static + Display + Debug> ChainErrorDown for ChainError<U> {
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
unsafe { unsafe {
#[allow(trivial_casts)] #[allow(trivial_casts)]
Some(&*(self as *const dyn Error as *const &ChainError<T>)) Some(*(self as *const dyn Error as *const &ChainError<T>))
} }
} else { } else {
None None

View file

@ -18,13 +18,13 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut res = String::new(); let mut res = String::new();
for e in err.iter() { for e in err.iter() {
write!(res, "{}", e.to_string())?; write!(res, "{}", e)?;
} }
assert_eq!(res, "654321entity not found"); assert_eq!(res, "654321entity not found");
let io_error: Option<&io::Error> = err let io_error: Option<&io::Error> = err
.iter() .iter()
.filter_map(Error::downcast_ref::<io::Error>) .filter_map(<dyn Error>::downcast_ref::<io::Error>)
.next(); .next();
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
@ -50,7 +50,7 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
let io_error: Option<&io::Error> = err let io_error: Option<&io::Error> = err
.iter() .iter()
.filter_map(Error::downcast_ref::<io::Error>) .filter_map(<dyn Error>::downcast_ref::<io::Error>)
.next(); .next();
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
@ -88,7 +88,7 @@ fn test_root_cause() -> Result<(), Box<dyn Error + Send + Sync>> {
let err = err.err().unwrap(); let err = err.err().unwrap();
let err: Option<&(dyn std::error::Error + 'static)> = err.root_cause(); let err: Option<&(dyn std::error::Error + 'static)> = err.root_cause();
let io_error: Option<&io::Error> = err.and_then(Error::downcast_ref::<io::Error>); let io_error: Option<&io::Error> = err.and_then(<dyn Error>::downcast_ref::<io::Error>);
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);