ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

Returning static str reference from class getter fail to compile

Open dmarteau opened this issue 1 year ago • 1 comments

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 avatar Oct 10 '24 16:10 dmarteau

platform: Ubuntu 24.04 php : 8.3.6 rustc: 1.81.0

dmarteau avatar Oct 10 '24 16:10 dmarteau