From 4915ff648e5b24ab5d6edda7869d352d9014f4cc Mon Sep 17 00:00:00 2001 From: Luke Nelson Date: Fri, 29 Nov 2024 00:47:53 -0800 Subject: [PATCH] Fix clippy warnings (#165) * Fix two instances of elided_named_lifetimes warning `cargo check` on 1.83 currently fails due to the use of `#[deny(warnings)]` because of two occurrences of the `elided_named_lifetimes` warning, as shown below: ``` error: elided lifetime has a name --> src/lazy_static.rs:48:34 | 48 | pub fn get(&'static self) -> &T { | ^ this elided lifetime gets resolved as `'static` | note: the lint level is defined here --> src/lib.rs:1:9 | 1 | #![deny(warnings, missing_debug_implementations, missing_docs)] | ^^^^^^^^ = note: `#[deny(elided_named_lifetimes)]` implied by `#[deny(warnings)]` help: consider specifying it explicitly | 48 | pub fn get(&'static self) -> &'static T { | +++++++ ``` This commit fixes both of the warnings by applying the recommended fix. Since the elided lifetime is resolved to be `'static` anyways, there's no change in behavior. * Fix additional clippy warnings This commit fixes a few Clippy warnings that are set to `deny` and therefore cause CI checks in pull requests to fail. I verified that `cargo clippy --all-targets --all-features` succeeds (with no warnings nor errors) after the fixes. --- src/annotations/mod.rs | 10 ++++++---- src/lazy_static.rs | 2 +- src/sync/mpsc.rs | 4 ++-- src/sync/mutex.rs | 2 +- src/thread.rs | 2 +- tests/demo/bounded_buffer.rs | 8 ++++---- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/annotations/mod.rs b/src/annotations/mod.rs index 87681126..1bb9e853 100644 --- a/src/annotations/mod.rs +++ b/src/annotations/mod.rs @@ -23,7 +23,7 @@ cfg_if::cfg_if! { use std::thread_local; thread_local! { - static ANNOTATION_STATE: RefCell> = RefCell::new(None); + static ANNOTATION_STATE: RefCell> = const { RefCell::new(None) }; } #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)] @@ -284,9 +284,11 @@ cfg_if::cfg_if! { ANNOTATION_STATE.with(|cell| { let mut bw = cell.borrow_mut(); assert!(bw.is_none(), "annotations already started"); - let mut state: AnnotationState = Default::default(); - state.version = ANNOTATION_VERSION; - state.last_task_id = Some(0.into()); + let state = AnnotationState { + version: ANNOTATION_VERSION, + last_task_id: Some(0.into()), + ..Default::default() + }; *bw = Some(state); }); } diff --git a/src/lazy_static.rs b/src/lazy_static.rs index 1c00ee2b..152a1ab3 100644 --- a/src/lazy_static.rs +++ b/src/lazy_static.rs @@ -45,7 +45,7 @@ impl std::fmt::Debug for Lazy { impl Lazy { /// Get a reference to the lazy value, initializing it first if necessary. - pub fn get(&'static self) -> &T { + pub fn get(&'static self) -> &'static T { // Safety: see the usage below unsafe fn extend_lt(t: &T) -> &'static T { std::mem::transmute(t) diff --git a/src/sync/mpsc.rs b/src/sync/mpsc.rs index a84f7235..07b62a15 100644 --- a/src/sync/mpsc.rs +++ b/src/sync/mpsc.rs @@ -484,7 +484,7 @@ pub struct IntoIter { rx: Receiver, } -impl<'a, T> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = T; fn next(&mut self) -> Option { @@ -492,7 +492,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } } -impl<'a, T> Iterator for TryIter<'a, T> { +impl Iterator for TryIter<'_, T> { type Item = T; fn next(&mut self) -> Option { diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 4dc41e89..4f258d78 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -177,7 +177,7 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> { } } -impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { +impl Drop for MutexGuard<'_, T> { fn drop(&mut self) { // Release the inner mutex self.inner = None; diff --git a/src/thread.rs b/src/thread.rs index e5acfe8d..62cac172 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -318,7 +318,7 @@ impl LocalKey { Ok(f(value)) } - fn get(&'static self) -> Option> { + fn get(&'static self) -> Option> { // Safety: see the usage below unsafe fn extend_lt<'b, T>(t: &'_ T) -> &'b T { std::mem::transmute(t) diff --git a/tests/demo/bounded_buffer.rs b/tests/demo/bounded_buffer.rs index 5f62b268..d128821f 100644 --- a/tests/demo/bounded_buffer.rs +++ b/tests/demo/bounded_buffer.rs @@ -1,3 +1,7 @@ +//! This file implements the example from a blog post about Coyote (P#): +//! https://cloudblogs.microsoft.com/opensource/2020/07/14/extreme-programming-meets-systematic-testing-using-coyote/ +//! The comments in this file are quotes from that blog post. + // For symmetry we clone some `Arc`s even though we could just move them #![allow(clippy::redundant_clone)] @@ -8,10 +12,6 @@ use shuttle::{check_random, replay, thread}; use std::sync::Arc; use test_log::test; -/// This file implements the example from a blog post about Coyote (P#): -/// https://cloudblogs.microsoft.com/opensource/2020/07/14/extreme-programming-meets-systematic-testing-using-coyote/ -/// The comments in this file are quotes from that blog post. - /// Let’s walk through how Coyote can easily solve the programming problem posed by Tom Cargill. He /// shared a BoundedBuffer implementation written in Java with a known, but tricky, deadlock bug. ///