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

Returning static str reference from class getter fail to compile #325

Open
dmarteau opened this issue Oct 10, 2024 · 1 comment
Open

Returning static str reference from class getter fail to compile #325

dmarteau opened this issue Oct 10, 2024 · 1 comment

Comments

@dmarteau
Copy link

Returning static str reference from class getter fail to build witth the error: implementation ofFromZval is not general enough

Example:

use ext_php_rs::prelude::*;

#[php_class]
struct Test;

#[php_impl]
impl Test {

    #[getter]
    fn get_static_value(&self) -> &'static str {
        "Hello"
    }
}

#[php_module]
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
    module
}

Fail to complie with the error:

error: implementation of `FromZval` is not general enough
   --> proj4rs-php/src/lib.rs:188:1
    |
188 | #[php_module]
    | ^^^^^^^^^^^^^ implementation of `FromZval` is not general enough
    |
    = note: `FromZval<'0>` would have to be implemented for the type `&str`, for any lifetime `'0`...
    = note: ...but `FromZval<'1>` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`
    = note: this error originates in the attribute macro `php_module` (in Nightly builds, run with -Z macro-backtrace for more info)

Removing the #[getter] macro makes compilation succeed.

@dmarteau
Copy link
Author

platform: Ubuntu 24.04
php : 8.3.6
rustc: 1.81.0

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

No branches or pull requests

1 participant