rust-lang / rust-lang/rust-clippy
`clippy::redundant-async-block` causes lifetime mismatch
Open
Nobody has claimed this yet.
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Using the following flags
--force-warn clippy::redundant-async-block
this code:
use core::hash::{BuildHasher, BuildHasherDefault};
fn compute_max_collisions(name: &str, hasher: impl BuildHasher) {
let table_mask = (1 << 17) - 1;
let mut table_orig_order = vec![0u64; 1 << 17];
let mut table_swap_order = vec![0u64; 1 << 17];
for krate in 0..64_u32 {
for def_index in 0..1024_u32 {
let h_orig = hasher.hash_one(((def_index as u64) << 32) | krate as u64);
let h_swap = hasher.hash_one(((krate as u64) << 32) | def_index as u64);
table_orig_order[(h_orig & table_mask) as usize] += 1;
table_swap_order[(h_swap & table_mask) as usize] += 1;
}
}
let max_orig = table_orig_order.into_iter().max().unwrap();
let max_swap = table_swap_order.into_iter().max().unwrap();
println!("{name} max orig collisions: {max_orig}");
println!("{name} max swap collisions: {max_swap}");
}
fn assert_future_unit_covariant_workaround<'s>(
f: impl Future<Output = &'static ()> + 'static,
) -> impl Future<Output = &'s ()> + 's {
// this works
async move { f.await }
}
caused the following diagnostics:
Checking _c562ca7861133a3f34c92e33f4b3dfde571553ec v0.1.0 (/tmp/icemaker_global_tempdir.GToAtTsoC3qp/icemaker_clippyfix_tempdir.z8myuo9KkZEY/_c562ca7861133a3f34c92e33f4b3dfde571553ec)
warning: this async expression only awaits a single future
--> src/lib.rs:26:5
|
26 | async move { f.await }
| ^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_async_block
= note: requested on the command line with `--force-warn clippy::redundant-async-block`
warning: `_c562ca7861133a3f34c92e33f4b3dfde571553ec` (lib) generated 1 warning (run `cargo clippy --fix --lib -p _c562ca7861133a3f34c92e33f4b3dfde571553ec` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s
However after applying these diagnostics, the resulting code:
use core::hash::{BuildHasher, BuildHasherDefault};
fn compute_max_collisions(name: &str, hasher: impl BuildHasher) {
let table_mask = (1 << 17) - 1;
let mut table_orig_order = vec![0u64; 1 << 17];
let mut table_swap_order = vec![0u64; 1 << 17];
for krate in 0..64_u32 {
for def_index in 0..1024_u32 {
let h_orig = hasher.hash_one(((def_index as u64) << 32) | krate as u64);
let h_swap = hasher.hash_one(((krate as u64) << 32) | def_index as u64);
table_orig_order[(h_orig & table_mask) as usize] += 1;
table_swap_order[(h_swap & table_mask) as usize] += 1;
}
}
let max_orig = table_orig_order.into_iter().max().unwrap();
let max_swap = table_swap_order.into_iter().max().unwrap();
println!("{name} max orig collisions: {max_orig}");
println!("{name} max swap collisions: {max_swap}");
}
fn assert_future_unit_covariant_workaround<'s>(
f: impl Future<Output = &'static ()> + 'static,
) -> impl Future<Output = &'s ()> + 's {
// this works
f
}
no longer compiled:
Checking _c562ca7861133a3f34c92e33f4b3dfde571553ec v0.1.0 (/tmp/icemaker_global_tempdir.GToAtTsoC3qp/icemaker_clippyfix_tempdir.z8myuo9KkZEY/_c562ca7861133a3f34c92e33f4b3dfde571553ec)
error: lifetime may not live long enough
--> src/lib.rs:26:5
|
22 | fn assert_future_unit_covariant_workaround<'s>(
| -- lifetime `'s` defined here
...
26 | f
| ^ returning this value requires that `'s` must outlive `'static`
error: could not compile `_c562ca7861133a3f34c92e33f4b3dfde571553ec` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_c562ca7861133a3f34c92e33f4b3dfde571553ec` (lib) due to 1 previous error
Version:
rustc 1.95.0-nightly (75963ce79 2026-01-25)
binary: rustc
commit-hash: 75963ce795666bc1f961e5d60060809809f6bc68
commit-date: 2026-01-25
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the example in src/lib.rs using --force-warn clippy::redundant-async-block, then run cargo clippy --fix --lib to inspect the suggested change. Compare the original and rewritten functions and verify that the resulting code still compiles without the lifetime mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100