Open
Description
Consider this code (playground):
#[warn(single_use_lifetimes)]
// warning: lifetime parameter `'a` only used once
fn foo<'a>(x: impl IntoIterator<Item = &'a i32>) -> Vec<i32> {
x.into_iter().copied().collect()
}
fn main() {
foo(&[1, 2, 3]);
}
The warning is issued: warning: lifetime parameter `'a` only used once
. However, removing the lifetime as suggested makes code to not compile:
#[warn(single_use_lifetimes)]
// error[E0658]: anonymous lifetimes in `impl Trait` are unstable
fn foo(x: impl IntoIterator<Item = &i32>) -> Vec<i32> {
x.into_iter().copied().collect()
}
fn main() {
foo(&[1, 2, 3]);
}
So the compiler contradicts itself.
I suspect single_use_lifetimes
does not correctly verify whether the compiler feature is available. My understanding is that it will be stabilized in 2024 edition (#117587).
Meta
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
I tried in the playground by setting "nightly" and both 2021 and 2024 editions, and the problem is currently still there.