From adbc5bebbab211a208dc0cd05cfcb4c189e13fef Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 22 Aug 2020 06:26:20 +0300 Subject: [PATCH] Generate documentation and run clippy in CI --- .github/workflows/libloading.yml | 24 ++++++++++++++++++++++-- src/os/unix/mod.rs | 10 ++++------ src/os/windows/mod.rs | 4 ++-- src/util.rs | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index 40c44e3..d315445 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -24,12 +24,17 @@ jobs: with: toolchain: ${{ matrix.rust_toolchain }} profile: minimal + components: clippy default: true - name: Update uses: actions-rs/cargo@v1 with: command: update args: --manifest-path=Cargo.toml + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy - name: Build uses: actions-rs/cargo@v1 with: @@ -45,6 +50,14 @@ jobs: with: command: test args: --manifest-path=Cargo.toml --release -- --nocapture + - name: Documentation + uses: actions-rs/cargo@v1 + with: + command: doc + args: --manifest-path=Cargo.toml + env: + RUSTDOCFLAGS: --cfg docsrs + if: ${{ matrix.rust_toolchain == 'nightly' }} windows-gnu-test: runs-on: windows-latest @@ -54,10 +67,17 @@ jobs: rust_toolchain: [nightly, stable] rust_target: - x86_64-pc-windows-gnu - # Only 64 bit GCC is preinstalled - #- i686-pc-windows-gnu + - i686-pc-windows-gnu steps: - uses: actions/checkout@v2 + - name: Add MSYS2 to the PATH + run: echo "::add-path::c:/msys64/bin" + - name: Add 32-bit mingw-w64 to the PATH + run: echo "::add-path::c:/msys64/mingw32/bin" + if: startsWith(matrix.rust_target, 'i686') + - name: Add 64-bit mingw-w64 to the PATH + run: echo "::add-path::c:/msys64/mingw64/bin" + if: startsWith(matrix.rust_target, 'x86_64') - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index b4a7a0c..b460c11 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -219,11 +219,9 @@ impl Library { #[inline(always)] pub unsafe fn get(&self, symbol: &[u8]) -> Result, crate::Error> { #[cfg(mtsafe_dlerror)] - { return self.get_singlethreaded(symbol); } + { self.get_singlethreaded(symbol) } #[cfg(not(mtsafe_dlerror))] - { - return self.get_impl(symbol, || Err(crate::Error::DlSymUnknown)); - } + { self.get_impl(symbol, || Err(crate::Error::DlSymUnknown)) } } /// Get a pointer to function or static variable by symbol name. @@ -275,7 +273,7 @@ impl Library { /// with this pointer as an argument. pub unsafe fn from_raw(handle: *mut raw::c_void) -> Library { Library { - handle: handle + handle } } @@ -359,7 +357,7 @@ impl ::std::ops::Deref for Symbol { fn deref(&self) -> &T { unsafe { // Additional reference level for a dereference on `deref` return value. - mem::transmute(&self.pointer) + &*(&self.pointer as *const *mut _ as *const T) } } } diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index 747e44d..d6bce11 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -265,7 +265,7 @@ impl ::std::ops::Deref for Symbol { fn deref(&self) -> &T { unsafe { // Additional reference level for a dereference on `deref` return value. - mem::transmute(&self.pointer) + &*(&self.pointer as *const *mut _ as *const T) } } } @@ -276,11 +276,11 @@ impl fmt::Debug for Symbol { } } - static USE_ERRORMODE: AtomicBool = AtomicBool::new(false); struct ErrorModeGuard(DWORD); impl ErrorModeGuard { + #[allow(clippy::if_same_then_else)] fn new() -> Option { unsafe { if !USE_ERRORMODE.load(Ordering::Acquire) { diff --git a/src/util.rs b/src/util.rs index e5108c2..880b689 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,7 +7,7 @@ use crate::Error; /// Checks for last byte and avoids allocating if it is zero. /// /// Non-last null bytes still result in an error. -pub(crate) fn cstr_cow_from_bytes<'a>(slice: &'a [u8]) -> Result, Error> { +pub(crate) fn cstr_cow_from_bytes(slice: &[u8]) -> Result, Error> { static ZERO: raw::c_char = 0; Ok(match slice.last() { // Slice out of 0 elements