An async function with one static reference compiles:
pub async fn test_0(_a: &'static str) {
}
An async function with a non-static and a static reference compiles:
pub async fn test_1<'a>(_a: &'a str, _b: &'static str) {
}
An async function with three non-static references compiles:
pub async fn test_2<'a, 'b, 'c>(_a: &'a str, _b: &'b str, _c: &'c str) {
}
A function that takes two non-static references and a static reference and returns a future compiles:
pub fn test_3_desugared<'a, 'b>(_a: &'a str, _b: &'b str, _c: &'static str) -> impl std::future::Future<Output=()> {
std::future::ready(())
}
So why does an async function that takes two non-static references and a static reference not compile?
pub async fn test_3<'a, 'b>(_a: &'a str, _b: &'b str, _c: &'static str) {
}
The compilation error in question:
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> src/lib.rs:11:74
|
11 | pub async fn test_3<'a, 'b>(_a: &'a str, _b: &'b str, _c: &'static str) {
| ^
|
note: hidden type `impl Future` captures lifetime smaller than the function body
--> src/lib.rs:11:74
|
11 | pub async fn test_3<'a, 'b>(_a: &'a str, _b: &'b str, _c: &'static str) {
|
Playground link for reference: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4d90427b4a592ccc3b3d119a326cc401
My current rust version:
$ rustc --version
rustc 1.56.1 (59eed8a2a 2021-11-01)
I came across this issue while trying to add a ring digest algorithm argument to a function that had two reference arguments already. A workaround is pretty easy, as I can wrap the static reference in a struct, pass that in, and use it without issue. I am just curious why this breaks.