Skip to content

Commit 6c88706

Browse files
committed
Fix lint errors
1 parent c8b4683 commit 6c88706

7 files changed

Lines changed: 27 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
override: true
9999
components: clippy
100100
- name: Lint code
101-
run: cargo clippy --all-features --no-deps -- -D clippy::all
101+
run: cargo clippy --all-targets --all-features --no-deps -- -D clippy::all
102102
release:
103103
if: github.event_name == 'push' && github.ref_type == 'tag'
104104
needs: [build, test, lint]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ check_fmt:
1111
cargo +nightly fmt --all -- --check
1212

1313
lint:
14-
cargo clippy --all-features --no-deps -- -D clippy::all
14+
cargo clippy --all-targets --all-features --no-deps -- -D clippy::all
1515

1616
build:
1717
cargo build-all-features

examples/echo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ mod echo {
1717
id_counter += 1;
1818
let id = id_counter;
1919
let handle = spawns::spawn(async move {
20-
eprintln!("{:010}[{}]: serving", id, remote_addr);
20+
eprintln!("{id:010}[{remote_addr}]: serving");
2121
let (reader, writer) = io::split(stream);
2222
match io::copy(reader, writer).await {
23-
Ok(_) => eprintln!("{:010}[{}]: closed", id, remote_addr),
24-
Err(err) => eprintln!("{:010}[{}]: {:?}", id, remote_addr, err),
23+
Ok(_) => eprintln!("{id:010}[{remote_addr}]: closed"),
24+
Err(err) => eprintln!("{id:010}[{remote_addr}]: {err:?}"),
2525
}
2626
})
2727
.attach();

spawns-compat/src/tokio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod tests {
3131

3232
#[tokio::test]
3333
async fn spawn_cascading() {
34+
#[allow(clippy::async_yields_async)]
3435
let handle = spawn(async { spawn(async { id() }) });
3536
let handle = handle.await.unwrap();
3637
let id = handle.id();
@@ -39,6 +40,7 @@ mod tests {
3940

4041
#[tokio::test]
4142
async fn spawn_interleaving() {
43+
#[allow(clippy::async_yields_async)]
4244
let handle = spawn(async { tokio::spawn(async { spawn(async { id() }) }) });
4345
let handle = handle.await.unwrap().await.unwrap();
4446
let id = handle.id();
@@ -47,6 +49,7 @@ mod tests {
4749

4850
#[tokio::test]
4951
async fn spawn_into_tokio() {
52+
#[allow(clippy::async_yields_async)]
5053
let handle = spawn(async { tokio::spawn(async { try_id() }) });
5154
let handle = handle.await.unwrap();
5255
assert_eq!(handle.await.unwrap(), None);

spawns-core/src/spawn.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub struct SpawnScope<'a> {
2222

2323
fn exchange(spawner: Option<&dyn Spawn>) -> Option<&'static dyn Spawn> {
2424
SPAWNER.with_borrow_mut(|previous| unsafe {
25-
std::mem::replace(previous, std::mem::transmute(spawner))
25+
std::mem::replace(
26+
previous,
27+
std::mem::transmute::<Option<&dyn Spawn>, Option<&'static dyn Spawn>>(spawner),
28+
)
2629
})
2730
}
2831

@@ -148,6 +151,7 @@ mod tests {
148151
fn thread_spawner_cascading_ready() {
149152
let spawner = ThreadSpawner::default();
150153
let _scope = enter(&spawner);
154+
#[allow(clippy::async_yields_async)]
151155
let handle = spawn(async move { spawn(async { id() }) });
152156
let handle = block_on(handle).unwrap();
153157
let id = handle.id();
@@ -158,6 +162,7 @@ mod tests {
158162
fn thread_spawner_cascading_cancel() {
159163
let spawner = ThreadSpawner::default();
160164
let _scope = enter(&spawner);
165+
#[allow(clippy::async_yields_async)]
161166
let handle = spawn(async move { spawn(pending::<()>()) });
162167
let handle = block_on(handle).unwrap();
163168
handle.cancel();
@@ -172,7 +177,7 @@ mod tests {
172177
use linkme::distributed_slice;
173178
use std::cell::Cell;
174179
thread_local! {
175-
static DROP_SPAWNER: Cell<Option<DropSpawner>> = Cell::new(None);
180+
static DROP_SPAWNER: Cell<Option<DropSpawner>> = const { Cell::new(None) };
176181
}
177182

178183
#[distributed_slice(COMPATS)]
@@ -187,7 +192,7 @@ mod tests {
187192
}
188193

189194
thread_local! {
190-
static THREAD_SPAWNER: Cell<Option<ThreadSpawner>> = Cell::new(None);
195+
static THREAD_SPAWNER: Cell<Option<ThreadSpawner>> = const { Cell::new(None) };
191196
}
192197

193198
#[distributed_slice(COMPATS)]

spawns-core/src/task.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Display for Id {
117117

118118
impl Debug for Id {
119119
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
120-
write!(f, "TaskId({})", self)
120+
write!(f, "TaskId({self})")
121121
}
122122
}
123123

@@ -798,7 +798,7 @@ mod tests {
798798
handle.cancel();
799799
block_on(Box::into_pin(task.future));
800800
let err = block_on(handle).unwrap_err();
801-
assert_eq!(err.is_cancelled(), true);
801+
assert!(err.is_cancelled());
802802
}
803803

804804
#[test]
@@ -807,15 +807,15 @@ mod tests {
807807
handle.cancel_handle().cancel();
808808
block_on(Box::into_pin(task.future));
809809
let err = block_on(handle).unwrap_err();
810-
assert_eq!(err.is_cancelled(), true);
810+
assert!(err.is_cancelled());
811811
}
812812

813813
#[test]
814814
fn task_cancel_passively() {
815815
let (task, handle) = Task::new(Name::default(), ready(()));
816816
drop(task);
817817
let err = block_on(handle).unwrap_err();
818-
assert_eq!(err.is_cancelled(), true);
818+
assert!(err.is_cancelled());
819819
}
820820

821821
#[test]
@@ -828,7 +828,7 @@ mod tests {
828828
handle.cancel();
829829
assert_eq!(task.as_mut().poll(&mut cx), Poll::Ready(()));
830830
let err = block_on(handle).unwrap_err();
831-
assert_eq!(err.is_cancelled(), true);
831+
assert!(err.is_cancelled());
832832
}
833833

834834
#[test]
@@ -937,7 +937,7 @@ mod tests {
937937
});
938938
let handle = handle.attach();
939939
let err = block_on(async move { handle.cancel().await.unwrap_err() });
940-
assert_eq!(err.is_cancelled(), true);
940+
assert!(err.is_cancelled());
941941
}
942942

943943
struct Sleep {
@@ -990,7 +990,7 @@ mod tests {
990990
let handle = handle.attach().detach();
991991
drop(handle);
992992
block_on(Box::into_pin(task.future));
993-
assert_eq!(cancelled.load(Ordering::Relaxed), false);
993+
assert!(!cancelled.load(Ordering::Relaxed));
994994
}
995995

996996
struct CustomFuture {

spawns-executor/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Blocking {
8686
let shutdown_signal = shutdown.wait_shutdown_triggered();
8787
(2..=threads).for_each(|i| {
8888
thread::Builder::new()
89-
.name(format!("spawns-executor-{}/{}", i, threads))
89+
.name(format!("spawns-executor-{i}/{threads}"))
9090
.spawn({
9191
let executor = executor.clone();
9292
let shutdown_signal = shutdown_signal.clone();
@@ -147,7 +147,7 @@ mod tests {
147147

148148
pub async fn echo_one(data: &[u8]) -> Vec<u8> {
149149
let (port, _server_handle) = start_echo_server().await;
150-
let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port))
150+
let mut stream = TcpStream::connect(format!("127.0.0.1:{port}"))
151151
.await
152152
.unwrap();
153153
stream.write_all(data).await.unwrap();
@@ -176,6 +176,7 @@ mod tests {
176176
fn task_cancelled_after_main_return_current_thread() {
177177
use async_io::Timer;
178178
use std::time::Duration;
179+
#[allow(clippy::async_yields_async)]
179180
let handle = block_on(async {
180181
spawns::spawn(async { Timer::after(Duration::from_secs(30)).await })
181182
});
@@ -187,6 +188,7 @@ mod tests {
187188
fn task_cancelled_after_main_return_multi_thread() {
188189
use async_io::Timer;
189190
use std::time::Duration;
191+
#[allow(clippy::async_yields_async)]
190192
let handle = Blocking::new(4).block_on(async {
191193
spawns::spawn(async { Timer::after(Duration::from_secs(30)).await })
192194
});

0 commit comments

Comments
 (0)