Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[pyproto] can break lifetime elision #1031

Closed
davidhewitt opened this issue Jul 9, 2020 · 1 comment
Closed

#[pyproto] can break lifetime elision #1031

davidhewitt opened this issue Jul 9, 2020 · 1 comment

Comments

@davidhewitt
Copy link
Member

🐛 Bug Reports

🌍 Environment

  • Your PyO3 version: 0.11.1
  • Have you tried using latest PyO3 master?`: yes

💥 Reproducing

This sample code looks correct according to lifetime elision rules:

#[pyproto]
impl PyIterProtocol for Foo {
    fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
        slf
    }
}

But it doesn't compile successfully:

error[E0106]: missing lifetime specifier
  --> src/main.rs:26:44
   |
26 |     fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
   |                                            ^ expected named lifetime parameter
   |
help: consider using the `'p` lifetime
   |
26 |     fn __iter__(slf: PyRef<Self>) -> PyRef<'p, Self> {
   |                                            ^^^

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'p` due to
 conflicting requirements
  --> src/main.rs:26:50
   |
26 |       fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
   |  __________________________________________________^
27 | |         slf
28 | |     }
   | |_____^
   |
note: first, the lifetime cannot outlive the lifetime `'p` as defined on the impl at
24:1...
  --> src/main.rs:24:1
   |
24 | #[pyproto]
   | ^^^^^^^^^^
note: ...so that the types are compatible
  --> src/main.rs:26:50
   |
26 |       fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
   |  __________________________________________________^
27 | |         slf
28 | |     }
   | |_____^
   = note: expected `pyo3::class::iter::PyIterIterProtocol<'p>`
              found `pyo3::class::iter::PyIterIterProtocol<'_>`
   = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the expression is assignable
  --> src/main.rs:27:9
   |
27 |         slf
   |         ^^^
   = note: expected `pyo3::pycell::PyRef<'static, _>`
              found `pyo3::pycell::PyRef<'_, _>`
   = note: this error originates in an attribute macro (in Nightly builds, run with -
Z macro-backtrace for more info)

It might be nice to adjust the pyproto proc macro so that this works.

@davidhewitt
Copy link
Member Author

davidhewitt commented Aug 25, 2020

This got resolved in #1093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants