-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
given these definitions
#[stabby::stabby(checked)]
pub trait Test {
extern "C" fn test(&self);
}
#[stabby::stabby]
pub struct TestImpl(u32);
impl Test for TestImpl {
extern "C" fn test(&self) {
println!("test: {}", self.0);
}
}
the following works fine:
type DynTest<'a> = stabby::dynptr!(&'a mut dyn Test);
fn main() {
println!("Hello, world!");
let mut test = TestImpl(42);
let dyn_test: DynTest = (&mut test).into();
}
but the following is broken:
type DynTest<'a> = stabby::dynptr!(&'a dyn Test);
fn main() {
println!("Hello, world!");
let test = TestImpl(42);
let dyn_test: DynTest = (&test).into();
}
compiler error:
error[E0597]: `test` does not live long enough
--> src/main.rs:27:29
|
26 | let test = TestImpl(42);
| ---- binding `test` declared here
27 | let dyn_test: DynTest = (&test).into();
| ^^^^^^^-------
| |
| borrowed value does not live long enough
| argument requires that `test` is borrowed for `'static`
28 | }
| - `test` dropped here while still borrowed
speaking of, it's rather unexpected that one must always specify a lifetime or it's 'static
let dyn_test = <stabby::dynptr!(&mut dyn Test)>::from(&mut test);
should implicitly use '_ lifetime, no?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels