-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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
theemathas
Metadata
Metadata
Assignees
Labels
A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.