From d60cdf9cdb6953f0211cd03204b72cc355500b2f Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 27 Jul 2023 12:39:31 +0200 Subject: [PATCH 1/4] fix: clippy Signed-off-by: Harald Hoyer --- examples/example.rs | 2 +- examples/tutorial15.rs | 2 +- examples/tutorial7.rs | 2 +- examples/tutorial8.rs | 2 +- examples/tutorial9.rs | 2 +- src/lib.rs | 9 +++++---- tests/test_iter.rs | 8 ++++---- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/example.rs b/examples/example.rs index 89b0d77..370631e 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -18,7 +18,7 @@ fn func3() -> Result<(), Box> { derive_str_context!(Func2Error); fn func2() -> ChainResult<(), Func2Error> { - func3().context(Func2Error(format!("func2 error: calling func3")))?; + func3().context(Func2Error("func2 error: calling func3".to_string()))?; Ok(()) } diff --git a/examples/tutorial15.rs b/examples/tutorial15.rs index ef35003..3b0eef3 100644 --- a/examples/tutorial15.rs +++ b/examples/tutorial15.rs @@ -84,7 +84,7 @@ pub mod mycrate { 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(|e| ErrorKind::from(e))?; diff --git a/examples/tutorial7.rs b/examples/tutorial7.rs index feb7cf8..969588d 100644 --- a/examples/tutorial7.rs +++ b/examples/tutorial7.rs @@ -15,7 +15,7 @@ fn func2() -> Result<(), Box> { } fn func1() -> Result<(), Box> { - func2().context(format!("func1 error"))?; + func2().context("func1 error")?; Ok(()) } diff --git a/examples/tutorial8.rs b/examples/tutorial8.rs index 2093782..cf5e654 100644 --- a/examples/tutorial8.rs +++ b/examples/tutorial8.rs @@ -19,7 +19,7 @@ fn func2() -> Result<(), Box> { derive_str_context!(Func1Error); fn func1() -> Result<(), Box> { - func2().context(Func1Error(format!("func1 error")))?; + func2().context(Func1Error("func1 error".to_string()))?; Ok(()) } diff --git a/examples/tutorial9.rs b/examples/tutorial9.rs index 1561535..754c621 100644 --- a/examples/tutorial9.rs +++ b/examples/tutorial9.rs @@ -20,7 +20,7 @@ derive_str_context!(Func1ErrorFunc2); derive_str_context!(Func1ErrorIO); fn func1() -> Result<(), Box> { - func2().context(Func1ErrorFunc2(format!("func1 error calling func2")))?; + func2().context(Func1ErrorFunc2("func1 error calling func2".to_string()))?; let filename = "bar.txt"; do_some_io().context(Func1ErrorIO(format!("Error reading '{}'", filename)))?; Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 5febac3..9ba0f28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,7 +103,6 @@ //! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html) #![deny(clippy::all)] -#![deny(clippy::integer_arithmetic)] #![allow(clippy::needless_doctest_main)] #![deny(missing_docs)] @@ -198,7 +197,9 @@ impl ChainError { /// ``` #[inline] pub fn find_cause(&self) -> Option<&U> { - self.iter().filter_map(Error::downcast_ref::).next() + self.iter() + .filter_map(::downcast_ref::) + .next() } /// Find the first error cause of type `ChainError`, if any exists @@ -220,7 +221,7 @@ impl ChainError { #[inline] pub fn find_chain_cause(&self) -> Option<&ChainError> { self.iter() - .filter_map(Error::downcast_ref::>) + .filter_map(::downcast_ref::>) .next() } @@ -428,7 +429,7 @@ impl ChainErrorDown for ChainError { #[allow(clippy::cast_ptr_alignment)] unsafe { #[allow(trivial_casts)] - Some(&*(self as *const dyn Error as *const &ChainError)) + Some(*(self as *const dyn Error as *const &ChainError)) } } else { None diff --git a/tests/test_iter.rs b/tests/test_iter.rs index 318c7a7..ad4f9f1 100644 --- a/tests/test_iter.rs +++ b/tests/test_iter.rs @@ -18,13 +18,13 @@ fn test_iter() -> Result<(), Box> { let mut res = String::new(); for e in err.iter() { - write!(res, "{}", e.to_string())?; + write!(res, "{}", e)?; } assert_eq!(res, "654321entity not found"); let io_error: Option<&io::Error> = err .iter() - .filter_map(Error::downcast_ref::) + .filter_map(::downcast_ref::) .next(); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); @@ -50,7 +50,7 @@ fn test_iter() -> Result<(), Box> { let io_error: Option<&io::Error> = err .iter() - .filter_map(Error::downcast_ref::) + .filter_map(::downcast_ref::) .next(); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); @@ -88,7 +88,7 @@ fn test_root_cause() -> Result<(), Box> { let err = err.err().unwrap(); let err: Option<&(dyn std::error::Error + 'static)> = err.root_cause(); - let io_error: Option<&io::Error> = err.and_then(Error::downcast_ref::); + let io_error: Option<&io::Error> = err.and_then(::downcast_ref::); assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); From bb5f372a92d6cca496d97e1dbf9a42ae3910c724 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 27 Jul 2023 12:27:28 +0200 Subject: [PATCH 2/4] fix: use `dtolnay/rust-toolchain` instead of `actions-rs/toolchain` Signed-off-by: Harald Hoyer --- .github/workflows/rust.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9e148b2..2f81b29 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,10 +26,9 @@ jobs: steps: - uses: actions/checkout@v1 - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.version }} - default: true profile: minimal - name: Build run: cargo build --verbose @@ -45,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master with: components: rustfmt toolchain: stable @@ -61,7 +60,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master with: components: clippy toolchain: stable @@ -77,7 +76,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master with: toolchain: stable profile: minimal From 376e133836b3f1c2a22d598a0ca61509c8ee2128 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 27 Jul 2023 12:32:37 +0200 Subject: [PATCH 3/4] ci: use codecov for coverage Signed-off-by: Harald Hoyer --- .github/workflows/coverage.yml | 55 +++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1925bb5..21025a8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,22 +1,43 @@ -name: coverage +name: coverage + +on: + # Trigger the workflow on push or pull request, + # but only for the master branch + push: + branches: + - master + pull_request: + branches: + - master + release: + types: + - created -on: [ "push" , "pull_request" ] jobs: test: - name: coverage - runs-on: ubuntu-latest - container: - image: xd009642/tarpaulin - options: --security-opt seccomp=unconfined + name: coverage + runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Generate code coverage - run: | - cargo tarpaulin --verbose --workspace --timeout 120 --out Lcov --output-dir coverage - - - name: Upload to coveralls - uses: coverallsapp/github-action@master + - uses: actions/checkout@v1 + - uses: dtolnay/rust-toolchain@master with: - github-token: ${{ secrets.GITHUB_TOKEN }} + target: x86_64-unknown-linux-gnu + toolchain: nightly + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + run: > + curl -LsSf 'https://github.com/taiki-e/cargo-llvm-cov/releases/download/v0.5.23/cargo-llvm-cov-x86_64-unknown-linux-musl.tar.gz' + | tar xzf - + && mv cargo-llvm-cov $HOME/.cargo/bin + + - name: Run cargo-llvm-cov + run: cargo llvm-cov --doctests --all --all-features --lcov --output-path lcov.info + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + directory: ./ + fail_ci_if_error: false + files: ./lcov.info + verbose: true From 95c5a02d507a418c68cadf1c4a4a9db73111c1f8 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 27 Jul 2023 13:28:15 +0200 Subject: [PATCH 4/4] test: rewrite doc test Line numbering has changed in Rust 1.71 in the doc tests, due to an extra inserted `#[allow(unused_extern_crates)]` line. Don't test for the exact line number anymore. Signed-off-by: Harald Hoyer --- src/lib.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9ba0f28..2c58ec4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,17 +60,16 @@ //! fn main() { //! if let Err(e) = process_config_file() { //! eprintln!("Error:\n{:?}", e); -//! # assert_eq!( -//! # format!("{:?}\n", e), -//! # "\ -//! # src/lib.rs:16:51: read the config file\n\ -//! # Caused by:\n\ -//! # src/lib.rs:9:47: Reading file: \"foo.txt\"\n\ -//! # Caused by:\n\ -//! # Os { code: 2, kind: NotFound, message: \"No such file or directory\" }\n\ -//! # ", -//! # ); +//! # let s = format!("{:?}", e); +//! # let lines = s.lines().collect::>(); +//! # assert_eq!(lines.len(), 5); +//! # assert!(lines[0].starts_with("src/lib.rs:")); +//! # assert_eq!(lines[1], "Caused by:"); +//! # assert!(lines[2].starts_with("src/lib.rs:")); +//! # assert_eq!(lines[3], "Caused by:"); +//! # assert_eq!(lines[4], "Os { code: 2, kind: NotFound, message: \"No such file or directory\" }"); //! } +//! # else { panic!(); } //! } //! ``` //!