Open
Description
I tried this code:
trait StorageIterator {
type KeyType<'a> where Self: 'a;
}
fn f<I: for<'a> StorageIterator<KeyType<'a> = &'a [u8]>>() {
|| true;
}
I expected to see this happen: This code can pass compilation.
Instead, this happened: Rustc reports a lifetime error.
error: `I` does not live long enough
--> <source>:6:5
|
6 | || true;
| ^^^^^^^
error: aborting due to 1 previous error
Following situations can pass compilation:
- remove closure
trait StorageIterator {
type KeyType<'a> where Self: 'a;
}
fn f<I: for<'a> StorageIterator<KeyType<'a> = &'a [u8]>>() {}
- remove where bound in trait
trait StorageIterator {
type KeyType<'a>;
}
fn f<I: for<'a> StorageIterator<KeyType<'a> = &'a [u8]>>() {
|| true;
}
- add
'static
for genericI
trait StorageIterator {
type KeyType<'a> where Self: 'a;
}
fn f<I: for<'a> StorageIterator<KeyType<'a> = &'a [u8]> + 'static>() {
|| true;
}
Meta
rustc --version --verbose
:
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5