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

Bad interaction of async functions with unused_lifetimes lint #78522

Closed
c410-f3r opened this issue Oct 29, 2020 · 8 comments
Closed

Bad interaction of async functions with unused_lifetimes lint #78522

c410-f3r opened this issue Oct 29, 2020 · 8 comments
Assignees
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@c410-f3r
Copy link
Contributor

c410-f3r commented Oct 29, 2020

The following shouldn't trigger the lint:

#![forbid(unused_lifetimes)]

pub async fn stuff<'a, I>(_: I) 
where
    I: Iterator<Item = &'a i32>
{
}

Also happens with &'a self or &'a mut self parameters

@c410-f3r c410-f3r added the C-bug Category: This is a bug. label Oct 29, 2020
@jonas-schievink jonas-schievink added A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Oct 29, 2020
@jyn514 jyn514 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await labels Oct 29, 2020
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Nov 19, 2020
@tmandry
Copy link
Member

tmandry commented Nov 19, 2020

Odd, it looks like the lint is broken for async fns. We definitely want to fix this.

If anyone wants to take this on, the place to start is check_uses_for_lifetimes_defined_by_scope and reading / logging to understand how async functions are handled differently.

@tmandry tmandry added the E-help-wanted Call for participation: Help is requested to fix this issue. label Nov 19, 2020
@Vooblin
Copy link
Contributor

Vooblin commented Dec 1, 2020

Hello!
I'm new in the Rust community and I'm going to actively contribute in Rust. I would like to start with this issue.

@Vooblin
Copy link
Contributor

Vooblin commented Dec 7, 2020

@rustbot claim

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 7, 2020

@Vooblin Thank you!

@tmandry
Copy link
Member

tmandry commented Jan 9, 2021

Ping from triage. @Vooblin are you still interested in working on this?

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Jan 9, 2021

@tmandry -> #79689 (comment)

@tmandry
Copy link
Member

tmandry commented Jan 9, 2021

Oops ☺️ sorry about that. This slipped through my email filters. I'll give it a review next week.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 14, 2021
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues rust-lang#78522, rust-lang#77217
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 14, 2021
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues rust-lang#78522, rust-lang#77217
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 14, 2021
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues rust-lang#78522, rust-lang#77217
@tmandry
Copy link
Member

tmandry commented Jan 15, 2021

Fixed in #79689

@tmandry tmandry closed this as completed Jan 15, 2021
@tmandry tmandry moved this to Done in wg-async work Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

No branches or pull requests

5 participants