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

unused-lifetimes lint false-positives with async functions #61115

Closed
Seeker14491 opened this issue May 24, 2019 · 4 comments · Fixed by #64603
Closed

unused-lifetimes lint false-positives with async functions #61115

Seeker14491 opened this issue May 24, 2019 · 4 comments · Fixed by #64603
Assignees
Labels
A-async-await Area: Async & Await A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Seeker14491
Copy link
Contributor

Seeker14491 commented May 24, 2019

Async functions that take references seem to always trigger the unused-lifetimes lint (which is allow-by-default). Example:

#![feature(async_await)]

#![warn(unused_lifetimes)]

pub async fn print(s: &str) {
    println!("{}", s);
}
warning: lifetime parameter `'_` never used
 --> src/lib.rs:5:23
  |
5 | pub async fn print(s: &str) {
  |                       ^
  |
@Seeker14491
Copy link
Contributor Author

I found this clippy issue which describes basically the same problem.

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 24, 2019
@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jun 4, 2019
@nikomatsakis
Copy link
Contributor

Seeing as this lint is not enabled by default, marking as deferred, though this would be good to fix and probably not too hard.

bors added a commit to rust-lang/rust-clippy that referenced this issue Jul 23, 2019
Ignore generated fresh lifetimes in elision check

<!--
Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only updates to the latest nightly, you can leave the
`changelog` entry as `none`. Otherwise, please write a short comment
explaining your change.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- [ ] Followed [lint naming conventions][lint_naming]
- [ ] Added passing UI tests (including committed `.stderr` file)
- [ ] `cargo test` passes locally
- [ ] Executed `util/dev update_lints`
- [ ] Added lint documentation
- [ ] Run `cargo fmt`

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR -->

fixes #3988

changelog: Ignore generated fresh lifetimes in elision check.

**HELP**: It seems `tests/ui` are compiled under edition 2015, and I don't know how to add tests for this properly.

Here is the test input it had already passed:
```rust
#![feature(async_await)]
#![allow(dead_code)]

async fn sink1<'a>(_: &'a str) {} // lint
async fn sink1_elided(_: &str) {} // ok

async fn one_to_one<'a>(s: &'a str) -> &'a str { s } // lint
async fn one_to_one_elided(s: &str) -> &str { s } // ok
async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { a } // ok
// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn

// #3988
struct Foo;
impl Foo {
    pub async fn foo(&mut self) {} // ok
}

// rust-lang/rust#61115
async fn print(s: &str) { // ok
    println!("{}", s);
}

fn main() {}

```
@gilescope
Copy link
Contributor

@rustbot claim

@gilescope
Copy link
Contributor

Looks the same issue as #64493.

A little inelegant but if

    !"5 | pub async fn print(s: &str) {".contains("'_")

we can suppress the lint I think...

@nikomatsakis nikomatsakis added AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. and removed AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. labels Oct 1, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 15, 2019
…r=matthewjasper

Reducing spurious unused lifetime warnings.

Fixes rust-lang#61115, fixes rust-lang#64493.
@bors bors closed this as completed in fcef4b1 Oct 16, 2019
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: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants