sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
806 stars 76 forks source link

value.rs "ensure_tmp_mut" error #148

Closed enp6 closed 4 months ago

enp6 commented 4 months ago
fn ensure_tmp_mut(&self) -> &mut Value {
    let cp = self as *const Value;
    let mp = cp as *mut Value;
    let me = unsafe { &mut *mp };
    return me.ensure_tmp();
}

&mut *mp There is an error prompt here

casting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell for more information, visit https://doc.rust-lang.org/book/ch15-05-interior-mutability.html #[deny(invalid_reference_casting)] on by defaultrustcClick for full compiler diagnostic value.rs(577, 12): casting happend here

Martinfx commented 4 months ago

Are you going to fix this undefined behavior?

Martinfx commented 4 months ago
fn ensure_tmp_mut(&self) -> &mut Value {
  let cp = self as *const Value;
  let mp = cp as *mut Value;
  let me = unsafe { &mut *mp };
  return me.ensure_tmp();
}

&mut *mp There is an error prompt here

casting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell for more information, visit https://doc.rust-lang.org/book/ch15-05-interior-mutability.html #[deny(invalid_reference_casting)] on by defaultrustcClick for full compiler diagnostic value.rs(577, 12): casting happend here

You try add #[allow(invalid_reference_casting)]

enp6 commented 4 months ago

@Martinfx

[allow(invalid_reference_casting)]

This method works, it compiles successfully without modification! Thanks.