-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4266 - uHOOCCOOHu:fix/async_fn_lifetime, r=flip1995
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() {} ```
- Loading branch information
Showing
12 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// compile-flags: --edition 2018 | ||
#![feature(async_await)] | ||
#![allow(dead_code)] | ||
|
||
async fn sink1<'a>(_: &'a str) {} // lint | ||
async fn sink1_elided(_: &str) {} // ok | ||
|
||
// lint | ||
async fn one_to_one<'a>(s: &'a str) -> &'a str { | ||
s | ||
} | ||
|
||
// ok | ||
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 | ||
} | ||
|
||
// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn | ||
|
||
// #3988 | ||
struct Foo; | ||
impl Foo { | ||
// ok | ||
pub async fn foo(&mut self) {} | ||
} | ||
|
||
// rust-lang/rust#61115 | ||
// ok | ||
async fn print(s: &str) { | ||
println!("{}", s); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) | ||
--> $DIR/issue_4266.rs:5:1 | ||
| | ||
LL | async fn sink1<'a>(_: &'a str) {} // lint | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::needless-lifetimes` implied by `-D warnings` | ||
|
||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) | ||
--> $DIR/issue_4266.rs:9:1 | ||
| | ||
LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { | ||
LL | | s | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters