The code following is expanded from macro, most from ctor, which can be compiled for V3, but not V4
What confuses me is V3 can be compiled, due to the error message, it shouldn't. I believe same error should be reported too.
pub struct optv(pub &'static dyn Deref<Target = &'static OptVal>);
unsafe impl Sync for optv {}
static V3: flags::optv = ::comn::flags::optv({
static mut opt___rust_ctor___storage: Option<&'static ::comn::flags::OptVal> = None;
#[used]
#[link_section = ".init_array"]
static opt___rust_ctor___ctor: unsafe extern "C" fn() = {
#[link_section = ".text.startup"]
unsafe extern "C" fn initer() {
opt___rust_ctor___storage = Some({
static x: ::comn::flags::OptVal = ::comn::flags::OptVal::new();
init(&x...);
&x
});
}
initer
};
struct opt<T> {
_data: core::marker::PhantomData<T>,
}
impl core::ops::Deref for opt<&'static ::comn::flags::OptVal> {
type Target = &'static ::comn::flags::OptVal;
fn deref(&self) -> &'static &'static ::comn::flags::OptVal {
unsafe { opt___rust_ctor___storage.as_ref().unwrap() }
}
}
static opt: opt<&'static ::comn::flags::OptVal> = opt {
_data: core::marker::PhantomData::<&'static ::comn::flags::OptVal>,
};
&opt
});
static V4: &'static &'static flags::OptVal = {
static mut opt___rust_ctor___storage: Option<&'static ::comn::flags::OptVal> = None;
#[link_section = ".init_array"]
static opt___rust_ctor___ctor: unsafe extern "C" fn() = {
#[link_section = ".text.startup"]
unsafe extern "C" fn initer() {
opt___rust_ctor___storage = Some({
static x: ::comn::flags::OptVal = ::comn::flags::OptVal::new();
init(&x...);
&x
});
}
initer
};
struct opt<T> {
_data: core::marker::PhantomData<T>,
}
impl core::ops::Deref for opt<&'static ::comn::flags::OptVal> {
type Target = &'static ::comn::flags::OptVal;
fn deref(&self) -> &'static &'static ::comn::flags::OptVal {
unsafe { opt___rust_ctor___storage.as_ref().unwrap() }
}
}
static opt: opt<&'static ::comn::flags::OptVal> = opt {
_data: core::marker::PhantomData::<&'static ::comn::flags::OptVal>,
};
&opt
};
The error message:
rror[E0277]: the trait bound `V4::opt<&'static OptVal>: Deref` is not satisfied
--> b.rs:174:5
|
174 | &opt
| ^^^^ the trait `~const Deref` is not implemented for `V4::opt<&'static OptVal>`
|
note: the trait `Deref` is implemented for `V4::opt<&'static OptVal>`, but that implementation is not `const`