Compiler will infer incorrect life time for system param in system closure with inferred type #269
Labels
C-enhancement
New content that isn't covered already
S-pitfalls
Content in the Pitfalls chapter
Z-medium
medium task that needs moderate time investment
Background
The problem started when I have:
which I wish to pipe to another system
system_b
if the output ofsystem_a
isSome(...)
:Afaik, there's currently no built in way in bevy for doing this so I tried to create a wrapper system closure:
At first I thought this should work but this actually doesn't compiles and took me a whole day with another Bevy discord user
_urben
to figure out why.The problem
After tinkering around, I found out that
The compiler error output is very hard to read though I figured that:
One that compiles:
fn (Query<&MyComponent>)
has the life timefor<'a> fn(Query<'_, '_, &'a MyComponent>)
.One that doesn't compiles:
fn (_)
has the life timefn(Query<'_, '_, &'_ MyComponent>)
.We've tried to create a mockup in the playground but it doesn't work so we replicate it directly in Bevy with:
This problem seems to arise with other
SystemParam
too such asRes
orResMut
and possibly others that have some lifetime in their type.I can't find this problem to be documented any where so I submit this issue for it to be at least recorded for other user to see!
I've solved the original problem using
CombinatorSystem
, created my ownPipeOrBreak
type that took system that returnsControlFlow
which I could map myOption
into.Here is the code that I'd like to share.
The text was updated successfully, but these errors were encountered: