mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 22:20:19 +00:00
fix release builds
This commit is contained in:
parent
df85b25548
commit
f09a2e2280
4 changed files with 24 additions and 20 deletions
|
@ -16,3 +16,4 @@ rand = "0.8.5"
|
|||
default = ["check_generation"]
|
||||
check_generation = []
|
||||
debug_borrows = []
|
||||
debug_ownership = []
|
||||
|
|
|
@ -8,7 +8,6 @@ use std::{
|
|||
fmt::{Debug, Display},
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
panic::Location,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
|
@ -157,7 +156,7 @@ pub struct GenerationalBox<T> {
|
|||
raw: MemoryLocation,
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
generation: u32,
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: &'static std::panic::Location<'static>,
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
@ -288,9 +287,8 @@ impl MemoryLocation {
|
|||
fn replace_with_caller<T: 'static>(
|
||||
&mut self,
|
||||
value: T,
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))] caller: &'static Location<
|
||||
'static,
|
||||
>,
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
caller: &'static std::panic::Location<'static>,
|
||||
) -> GenerationalBox<T> {
|
||||
let mut inner_mut = self.0.data.borrow_mut();
|
||||
|
||||
|
@ -301,7 +299,7 @@ impl MemoryLocation {
|
|||
raw: *self,
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
generation: self.0.generation.get(),
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: caller,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
|
@ -310,7 +308,7 @@ impl MemoryLocation {
|
|||
#[track_caller]
|
||||
fn try_borrow<T: Any>(
|
||||
&self,
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: &'static std::panic::Location<'static>,
|
||||
) -> Result<GenerationalRef<'_, T>, BorrowError> {
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
|
@ -329,7 +327,7 @@ impl MemoryLocation {
|
|||
},
|
||||
}),
|
||||
Err(_) => Err(BorrowError::Dropped(ValueDroppedError {
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at,
|
||||
})),
|
||||
},
|
||||
|
@ -343,7 +341,7 @@ impl MemoryLocation {
|
|||
#[track_caller]
|
||||
fn try_borrow_mut<T: Any>(
|
||||
&self,
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: &'static std::panic::Location<'static>,
|
||||
) -> Result<GenerationalRefMut<'_, T>, BorrowMutError> {
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
|
@ -363,7 +361,7 @@ impl MemoryLocation {
|
|||
},
|
||||
}),
|
||||
Err(_) => Err(BorrowMutError::Dropped(ValueDroppedError {
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at,
|
||||
})),
|
||||
}
|
||||
|
@ -422,14 +420,14 @@ impl Error for BorrowMutError {}
|
|||
/// An error that can occur when trying to use a value that has been dropped.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct ValueDroppedError {
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: &'static std::panic::Location<'static>,
|
||||
}
|
||||
|
||||
impl Display for ValueDroppedError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("Failed to borrow because the value was dropped.")?;
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
f.write_fmt(format_args!("created_at: {}", self.created_at))?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -686,7 +684,7 @@ impl Owner {
|
|||
pub fn insert_with_caller<T: 'static>(
|
||||
&self,
|
||||
value: T,
|
||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
caller: &'static std::panic::Location<'static>,
|
||||
) -> GenerationalBox<T> {
|
||||
let mut location = self.store.claim();
|
||||
|
@ -706,7 +704,7 @@ impl Owner {
|
|||
raw: location,
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
generation: location.0.generation.get(),
|
||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||
created_at: std::panic::Location::caller(),
|
||||
_marker: PhantomData,
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::panic::Location;
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus_core::prelude::{
|
||||
|
@ -85,11 +84,18 @@ impl<T: 'static> CopyValue<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_caller(value: T, caller: &'static Location<'static>) -> Self {
|
||||
pub(crate) fn new_with_caller(
|
||||
value: T,
|
||||
#[cfg(debug_assertions)] caller: &'static std::panic::Location<'static>,
|
||||
) -> Self {
|
||||
let owner = current_owner();
|
||||
|
||||
Self {
|
||||
value: owner.insert_with_caller(value, caller),
|
||||
value: owner.insert_with_caller(
|
||||
value,
|
||||
#[cfg(debug_assertions)]
|
||||
caller,
|
||||
),
|
||||
origin_scope: current_scope_id().expect("in a virtual dom"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::{
|
||||
cell::RefCell,
|
||||
ops::{Deref, DerefMut},
|
||||
panic::Location,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
@ -48,7 +47,7 @@ use crate::{CopyValue, Effect};
|
|||
#[track_caller]
|
||||
pub fn use_signal<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal<T> {
|
||||
#[cfg(debug_assertions)]
|
||||
let caller = Location::caller();
|
||||
let caller = std::panic::Location::caller();
|
||||
|
||||
*cx.use_hook(|| {
|
||||
Signal::new_with_caller(
|
||||
|
@ -161,7 +160,7 @@ impl<T: 'static> Signal<T> {
|
|||
/// Creates a new Signal. Signals are a Copy state management solution with automatic dependency tracking.
|
||||
fn new_with_caller(
|
||||
value: T,
|
||||
#[cfg(debug_assertions)] caller: &'static Location<'static>,
|
||||
#[cfg(debug_assertions)] caller: &'static std::panic::Location<'static>,
|
||||
) -> Self {
|
||||
Self {
|
||||
inner: CopyValue::new_with_caller(
|
||||
|
|
Loading…
Reference in a new issue