From 33cdf58921485c4ba3d85aacacd1991e4db17342 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 20 Jan 2025 00:42:29 +0900 Subject: [PATCH 1/3] ci: Use reusable workflows for fmt and security_audit --- .github/workflows/ci.yml | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dbaaed..f754fef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,16 @@ defaults: shell: bash jobs: + fmt: + uses: smol-rs/.github/.github/workflows/fmt.yml@main + security_audit: + uses: smol-rs/.github/.github/workflows/security_audit.yml@main + permissions: + checks: write + contents: read + issues: write + secrets: inherit + test: runs-on: ${{ matrix.os }} strategy: @@ -90,14 +100,6 @@ jobs: RUSTFLAGS: "--cfg=loom" LOOM_MAX_PREEMPTIONS: 4 - fmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Rust - run: rustup update stable - - run: cargo fmt --all --check - miri: runs-on: ubuntu-latest steps: @@ -117,19 +119,3 @@ jobs: - name: Install Rust run: rustup update stable - run: cargo doc --all --all-features - - security_audit: - permissions: - checks: write - contents: read - issues: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - # rustsec/audit-check used to do this automatically - - name: Generate Cargo.lock - run: cargo generate-lockfile - # https://github.com/rustsec/audit-check/issues/2 - - uses: rustsec/audit-check@v2.0.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} From e0fe289b82207421a25ab269e435a87a8e628d3d Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 20 Jan 2025 00:48:28 +0900 Subject: [PATCH 2/3] Fix clippy::needless_lifetimes warning ``` error: the following explicit lifetimes could be elided: 'a --> src/once_cell.rs:690:14 | 690 | impl<'a, T> Drop for Guard<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `-D clippy::needless-lifetimes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | 690 - impl<'a, T> Drop for Guard<'a, T> { 690 + impl Drop for Guard<'_, T> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/futures.rs:107:6 | 107 | impl<'a, T> EventListenerFuture for ReadArcInner<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 107 - impl<'a, T> EventListenerFuture for ReadArcInner<'a, T> { 107 + impl EventListenerFuture for ReadArcInner<'_, T> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/futures.rs:219:6 | 219 | impl<'a, T: ?Sized> EventListenerFuture for UpgradableReadArcInner<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 219 - impl<'a, T: ?Sized> EventListenerFuture for UpgradableReadArcInner<'a, T> { 219 + impl EventListenerFuture for UpgradableReadArcInner<'_, T> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/futures.rs:326:6 | 326 | impl<'a, T: ?Sized> EventListenerFuture for WriteArcInner<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 326 - impl<'a, T: ?Sized> EventListenerFuture for WriteArcInner<'a, T> { 326 + impl EventListenerFuture for WriteArcInner<'_, T> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/raw.rs:310:6 | 310 | impl<'a> EventListenerFuture for RawRead<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 310 - impl<'a> EventListenerFuture for RawRead<'a> { 310 + impl EventListenerFuture for RawRead<'_> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/raw.rs:375:6 | 375 | impl<'a> EventListenerFuture for RawUpgradableRead<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 375 - impl<'a> EventListenerFuture for RawUpgradableRead<'a> { 375 + impl EventListenerFuture for RawUpgradableRead<'_> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/raw.rs:458:6 | 458 | impl<'a> EventListenerFuture for RawWrite<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 458 - impl<'a> EventListenerFuture for RawWrite<'a> { 458 + impl EventListenerFuture for RawWrite<'_> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock/raw.rs:586:6 | 586 | impl<'a> RawUpgrade<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 586 - impl<'a> RawUpgrade<'a> { 586 + impl RawUpgrade<'_> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock.rs:851:6 | 851 | impl<'a, T: ?Sized> Drop for RwLockUpgradableReadGuard<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 851 - impl<'a, T: ?Sized> Drop for RwLockUpgradableReadGuard<'a, T> { 851 + impl Drop for RwLockUpgradableReadGuard<'_, T> { | error: the following explicit lifetimes could be elided: 'a --> src/rwlock.rs:1222:6 | 1222 | impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes help: elide the lifetimes | 1222 - impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> { 1222 + impl Drop for RwLockWriteGuard<'_, T> { | ``` --- src/once_cell.rs | 2 +- src/rwlock.rs | 4 ++-- src/rwlock/futures.rs | 6 +++--- src/rwlock/raw.rs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/once_cell.rs b/src/once_cell.rs index 14f020f..4abdbf2 100644 --- a/src/once_cell.rs +++ b/src/once_cell.rs @@ -687,7 +687,7 @@ impl OnceCell { /// `UNINITIALIZED` and that the next listener is notified. struct Guard<'a, T>(&'a OnceCell); - impl<'a, T> Drop for Guard<'a, T> { + impl Drop for Guard<'_, T> { fn drop(&mut self) { self.0 .state diff --git a/src/rwlock.rs b/src/rwlock.rs index 64f3222..962baad 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -848,7 +848,7 @@ pub struct RwLockUpgradableReadGuard<'a, T: ?Sized> { value: *mut T, } -impl<'a, T: ?Sized> Drop for RwLockUpgradableReadGuard<'a, T> { +impl Drop for RwLockUpgradableReadGuard<'_, T> { #[inline] fn drop(&mut self) { // SAFETY: we are dropping an upgradable read guard. @@ -1219,7 +1219,7 @@ pub struct RwLockWriteGuard<'a, T: ?Sized> { unsafe impl Send for RwLockWriteGuard<'_, T> {} unsafe impl Sync for RwLockWriteGuard<'_, T> {} -impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> { +impl Drop for RwLockWriteGuard<'_, T> { #[inline] fn drop(&mut self) { // SAFETY: we are dropping a write lock diff --git a/src/rwlock/futures.rs b/src/rwlock/futures.rs index 3904c81..0427b12 100644 --- a/src/rwlock/futures.rs +++ b/src/rwlock/futures.rs @@ -104,7 +104,7 @@ impl fmt::Debug for ReadArc<'_, T> { } } -impl<'a, T> EventListenerFuture for ReadArcInner<'a, T> { +impl EventListenerFuture for ReadArcInner<'_, T> { type Output = RwLockReadGuardArc; #[inline] @@ -216,7 +216,7 @@ impl fmt::Debug for UpgradableReadArc<'_, T> { } } -impl<'a, T: ?Sized> EventListenerFuture for UpgradableReadArcInner<'a, T> { +impl EventListenerFuture for UpgradableReadArcInner<'_, T> { type Output = RwLockUpgradableReadGuardArc; #[inline] @@ -323,7 +323,7 @@ impl fmt::Debug for WriteArc<'_, T> { } } -impl<'a, T: ?Sized> EventListenerFuture for WriteArcInner<'a, T> { +impl EventListenerFuture for WriteArcInner<'_, T> { type Output = RwLockWriteGuardArc; #[inline] diff --git a/src/rwlock/raw.rs b/src/rwlock/raw.rs index 03a9972..2b9338a 100644 --- a/src/rwlock/raw.rs +++ b/src/rwlock/raw.rs @@ -307,7 +307,7 @@ pin_project_lite::pin_project! { } } -impl<'a> EventListenerFuture for RawRead<'a> { +impl EventListenerFuture for RawRead<'_> { type Output = (); fn poll_with_strategy<'x, S: Strategy<'x>>( @@ -372,7 +372,7 @@ pin_project_lite::pin_project! { } } -impl<'a> EventListenerFuture for RawUpgradableRead<'a> { +impl EventListenerFuture for RawUpgradableRead<'_> { type Output = (); fn poll_with_strategy<'x, S: Strategy<'x>>( @@ -455,7 +455,7 @@ pin_project_lite::pin_project! { } } -impl<'a> EventListenerFuture for RawWrite<'a> { +impl EventListenerFuture for RawWrite<'_> { type Output = (); fn poll_with_strategy<'x, S: Strategy<'x>>( @@ -583,7 +583,7 @@ impl<'a> EventListenerFuture for RawUpgrade<'a> { } } -impl<'a> RawUpgrade<'a> { +impl RawUpgrade<'_> { /// Whether the future returned `Poll::Ready(..)` at some point. #[inline] pub(super) fn is_ready(&self) -> bool { From 2076b7042d7b1293f309efbb036d6421b672e760 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 20 Jan 2025 00:51:01 +0900 Subject: [PATCH 3/3] Fix clippy::empty_line_after_doc_comments and clippy::empty_line_after_outer_attr warnings ``` error: empty line after doc comment --> src/rwlock/raw.rs:99:5 | 99 | / /// Returns `true` iff an upgradable read lock was successfully acquired. 100 | | | |_^ 101 | pub(super) fn try_upgradable_read(&self) -> bool { | ------------------------------------------------ the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]` = help: if the empty line is unintentional remove it error: empty line after outer attribute --> src/rwlock/raw.rs:132:5 | 132 | / #[inline] 133 | | | |_^ 134 | pub(super) fn upgradable_read(&self) -> RawUpgradableRead<'_> { | ------------------------------------------------------------- the attribute applies to this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_outer_attr)]` = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:141:5 | 141 | / /// Returns `true` iff a write lock was successfully acquired. 142 | | | |_^ 143 | pub(super) fn try_write(&self) -> bool { | -------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after outer attribute --> src/rwlock/raw.rs:165:5 | 165 | / #[inline] 166 | | | |_^ 167 | pub(super) fn write(&self) -> RawWrite<'_> { | ------------------------------------------ the attribute applies to this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:182:5 | 182 | / /// This will attempt to upgrade it to a write lock. 183 | | | |_^ 184 | pub(super) unsafe fn try_upgrade(&self) -> bool { | ----------------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:193:5 | 193 | / /// This will upgrade it to a write lock. 194 | | | |_^ 195 | pub(super) unsafe fn upgrade(&self) -> RawUpgrade<'_> { | ----------------------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after outer attribute --> src/rwlock/raw.rs:211:5 | 211 | / #[inline] 212 | | | |_^ 213 | pub(super) unsafe fn downgrade_upgradable_read(&self) { | ----------------------------------------------------- the attribute applies to this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:220:5 | 220 | / /// This will downgrade it to a read lock. 221 | | | |_^ 222 | pub(super) unsafe fn downgrade_write(&self) { | ------------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:237:5 | 237 | / /// This will downgrade it to an upgradable read lock. 238 | | | |_^ 239 | pub(super) unsafe fn downgrade_to_upgradable(&self) { | --------------------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:248:5 | 248 | / /// This will unlock that lock. 249 | | | |_^ 250 | pub(super) unsafe fn read_unlock(&self) { | --------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:261:5 | 261 | / /// This will unlock that lock. 262 | | | |_^ 263 | pub(super) unsafe fn upgradable_read_unlock(&self) { | -------------------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it error: empty line after doc comment --> src/rwlock/raw.rs:277:5 | 277 | / /// This will unlock that lock. 278 | | | |_^ 279 | pub(super) unsafe fn write_unlock(&self) { | ---------------------------------------- the comment documents this method | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments = help: if the empty line is unintentional remove it ``` --- src/rwlock/raw.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/rwlock/raw.rs b/src/rwlock/raw.rs index 2b9338a..325507a 100644 --- a/src/rwlock/raw.rs +++ b/src/rwlock/raw.rs @@ -97,7 +97,6 @@ impl RawRwLock { } /// Returns `true` iff an upgradable read lock was successfully acquired. - pub(super) fn try_upgradable_read(&self) -> bool { // First try grabbing the mutex. let lock = if let Some(lock) = self.mutex.try_lock() { @@ -130,7 +129,6 @@ impl RawRwLock { } #[inline] - pub(super) fn upgradable_read(&self) -> RawUpgradableRead<'_> { RawUpgradableRead { lock: self, @@ -139,7 +137,6 @@ impl RawRwLock { } /// Returns `true` iff a write lock was successfully acquired. - pub(super) fn try_write(&self) -> bool { // First try grabbing the mutex. let lock = if let Some(lock) = self.mutex.try_lock() { @@ -163,7 +160,6 @@ impl RawRwLock { } #[inline] - pub(super) fn write(&self) -> RawWrite<'_> { RawWrite { lock: self, @@ -180,7 +176,6 @@ impl RawRwLock { /// /// Caller must hold an upgradable read lock. /// This will attempt to upgrade it to a write lock. - pub(super) unsafe fn try_upgrade(&self) -> bool { self.state .compare_exchange(ONE_READER, WRITER_BIT, Ordering::AcqRel, Ordering::Acquire) @@ -191,7 +186,6 @@ impl RawRwLock { /// /// Caller must hold an upgradable read lock. /// This will upgrade it to a write lock. - pub(super) unsafe fn upgrade(&self) -> RawUpgrade<'_> { // Set `WRITER_BIT` and decrement the number of readers at the same time. self.state @@ -209,7 +203,6 @@ impl RawRwLock { /// Caller must hold an upgradable read lock. /// This will downgrade it to a standard read lock. #[inline] - pub(super) unsafe fn downgrade_upgradable_read(&self) { self.mutex.unlock_unchecked(); } @@ -218,7 +211,6 @@ impl RawRwLock { /// /// Caller must hold a write lock. /// This will downgrade it to a read lock. - pub(super) unsafe fn downgrade_write(&self) { // Atomically downgrade state. self.state @@ -235,7 +227,6 @@ impl RawRwLock { /// /// Caller must hold a write lock. /// This will downgrade it to an upgradable read lock. - pub(super) unsafe fn downgrade_to_upgradable(&self) { // Atomically downgrade state. self.state @@ -246,7 +237,6 @@ impl RawRwLock { /// /// Caller must hold a read lock . /// This will unlock that lock. - pub(super) unsafe fn read_unlock(&self) { // Decrement the number of readers. if self.state.fetch_sub(ONE_READER, Ordering::SeqCst) & !WRITER_BIT == ONE_READER { @@ -259,7 +249,6 @@ impl RawRwLock { /// /// Caller must hold an upgradable read lock. /// This will unlock that lock. - pub(super) unsafe fn upgradable_read_unlock(&self) { // Decrement the number of readers. if self.state.fetch_sub(ONE_READER, Ordering::SeqCst) & !WRITER_BIT == ONE_READER { @@ -275,7 +264,6 @@ impl RawRwLock { /// /// Caller must hold a write lock. /// This will unlock that lock. - pub(super) unsafe fn write_unlock(&self) { // Unset `WRITER_BIT`. self.state.fetch_and(!WRITER_BIT, Ordering::SeqCst);