Is this a limitation of the current borrow checker?

I've been working on a prototype of some changes to PyO3's API, and have run into a borrow check error in a case where my intuition disagrees with what the compiler wants.

Usually this means the compiler is right, but in this case I have reasons to suspect that I might be right, and it might be a limitation of the current borrow check implementation.

Playground below, where I've done my best to isolate the case in a concise example. Anyone got some thoughts on what's going on, and maybe why the compiler wants what it's asking for?

Your function is creating a &'a Foo<'b>. However, this type can only exist if 'a is shorter than 'b.

To do this, you need to avoid having 'a be on a reference with 'b on the inner type.

2 Likes

I take it you mean &'a Py<'py, T> created by the self.attach(py)? That indeed makes sense.

And this also leads to the root of the problem: the member PhantomData<&'a Py<'py, T>> in definition of PyBorrowed also applies this constraint.

Thanks, as always the compiler is right!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.