Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

single_use_lifetimes: false positive (suggests unstable anonymous lifetimes in impl Trait) #129255

Open
ivan-aksamentov opened this issue Aug 18, 2024 · 1 comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-lint-single_use_lifetimes `single_use_lifetimes` lint

Comments

@ivan-aksamentov
Copy link

ivan-aksamentov commented Aug 18, 2024

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.

@ivan-aksamentov ivan-aksamentov added the C-bug Category: This is a bug. label Aug 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 18, 2024
@ChayimFriedman2
Copy link
Contributor

@rustbot label +A-lint +F-lint-single_use_lifetimes +D-incorrect -needs-triage

@rustbot rustbot added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-lint-single_use_lifetimes `single_use_lifetimes` lint and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-lint-single_use_lifetimes `single_use_lifetimes` lint
Projects
None yet
Development

No branches or pull requests

3 participants