davidcole1340 / ext-php-rs

Bindings for the Zend API to build PHP extensions natively in Rust.
Apache License 2.0
580 stars 62 forks source link

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

Open dmarteau opened 2 hours ago

dmarteau commented 2 hours ago

Returning static str reference from class getter fail to build witth the error: implementation ofFromZvalis 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 commented 2 hours ago

platform: Ubuntu 24.04 php : 8.3.6 rustc: 1.81.0