Potentially false positive of "lifetime may not live long enough" after introduction of Sized
bound on associated type
#137184
Labels
A-lifetimes
Area: Lifetimes / regions
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
I tried this code:
I expected to see this happen: this code should compile. In fact, if I remove the
where T: CopyTo<Data<'to>: Sized>
clause, which isn't used at all, this code compiles.Instead, this happened: I get a lifetime may not live long enough error, with the note "Proving this value is
Sized
requires toto
must outlive'from
" as well as the dual message:Context
This is a simplified version of a real use-case where I have arena-allocated data and I want a trait that implements moving them from one arena to another with a different lifetime. Since Rust doesn't support general higher-kinded types, I use GATs as a poor man's HKT, which requires more annotations but it works ok. However, when I try to implement a variant of
copy
where I need additional bounds on the associated type, I started to get strange lifetime errors. What's surprising here is that the trait bound is unrelated to the body of the function and never used. It's surprising that adding aSized
bound adds any lifetime constraints at all, unless I'm missing something obvious.Potential duplicate of #108345, but I wanted to make sure it's not a different error first.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: