Skip to content

Commit

Permalink
Fix clippy warnings (awslabs#165)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lukenels authored Nov 29, 2024
1 parent 79735ba commit 4915ff6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/annotations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cfg_if::cfg_if! {
use std::thread_local;

thread_local! {
static ANNOTATION_STATE: RefCell<Option<AnnotationState>> = RefCell::new(None);
static ANNOTATION_STATE: RefCell<Option<AnnotationState>> = const { RefCell::new(None) };
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
Expand Down Expand Up @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lazy_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<T: Sync> std::fmt::Debug for Lazy<T> {

impl<T: Sync> Lazy<T> {
/// 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: &T) -> &'static T {
std::mem::transmute(t)
Expand Down
4 changes: 2 additions & 2 deletions src/sync/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,15 @@ pub struct IntoIter<T> {
rx: Receiver<T>,
}

impl<'a, T> Iterator for Iter<'a, T> {
impl<T> Iterator for Iter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
self.rx.recv().ok()
}
}

impl<'a, T> Iterator for TryIter<'a, T> {
impl<T> Iterator for TryIter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> {
}
}

impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
fn drop(&mut self) {
// Release the inner mutex
self.inner = None;
Expand Down
2 changes: 1 addition & 1 deletion src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<T: 'static> LocalKey<T> {
Ok(f(value))
}

fn get(&'static self) -> Option<std::result::Result<&T, AccessError>> {
fn get(&'static self) -> Option<std::result::Result<&'static T, AccessError>> {
// Safety: see the usage below
unsafe fn extend_lt<'b, T>(t: &'_ T) -> &'b T {
std::mem::transmute(t)
Expand Down
8 changes: 4 additions & 4 deletions tests/demo/bounded_buffer.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand All @@ -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.
///
Expand Down

0 comments on commit 4915ff6

Please sign in to comment.