Closed
Description
I tried this code:
#[deny(single_use_lifetimes)]
// error: lifetime parameter `'a` only used once
async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
s3
}
fn foo<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
s3
}
fn main() {}
I expected to see this happen: the code is correct.
Instead, this happened:
error: lifetime parameter `'a` only used once
--> src/main.rs:4:14
|
4 | async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
| ^^ this lifetime... -- ...is used only here
|
note: the lint level is defined here
--> src/main.rs:1:8
|
1 | #[deny(single_use_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^
Just swap the functions, then the code compiles:
#[deny(single_use_lifetimes)]
fn foo<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
s3
}
async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
s3
}
fn main() {}
Update 20201014:
The examples may be misleading.
I forgot that #[deny(single_use_lifetimes)]
takes effect on a single item.
It was a typo.
Here is a new example. It should be correct. But the compiler does not accept it.
#![deny(single_use_lifetimes)]
// error: lifetime parameter `'a` only used once
async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str {
s3
}
Meta
rustc --version --verbose
:
rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-unknown-linux-gnu
release: 1.46.0
LLVM version: 10.0
rustc +nightly --version --verbose
:
rustc 1.48.0-nightly (8b4085359 2020-09-23)
binary: rustc
commit-hash: 8b4085359ae798dedb05c95ad42520557bd25320
commit-date: 2020-09-23
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Lifetimes / regionsArea: Lints (warnings about flaws in source code) such as unused_mut.Async-await issues that have been triaged during a working group meeting.Category: This is a bug.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done