diff --git a/crates/actuate-core/src/compose.rs b/crates/actuate-core/src/compose.rs index f2c7558..1b7179b 100644 --- a/crates/actuate-core/src/compose.rs +++ b/crates/actuate-core/src/compose.rs @@ -11,7 +11,7 @@ use std::{ /// For a dynamically-typed composable, see [`DynCompose`]. pub trait Compose: Data { /// Compose this function. - fn compose(cx: Scope) -> impl Compose; + fn compose(cx: Scope<'_, Self>) -> impl Compose; #[doc(hidden)] fn name() -> Cow<'static, str> { @@ -27,13 +27,13 @@ pub trait Compose: Data { } impl Compose for () { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_empty.set(true); } } impl Compose for &C { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { unsafe { (**cx.me()).any_compose(&cx); } @@ -41,10 +41,10 @@ impl Compose for &C { } impl Compose for Option { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); - let state_cell: &RefCell> = use_ref(&cx, || RefCell::new(None)); + let state_cell: &RefCell>> = use_ref(&cx, || RefCell::new(None)); let mut state_cell = state_cell.borrow_mut(); if let Some(content) = &*cx.me() { @@ -104,7 +104,7 @@ where Item: Data, C: Compose, { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); let items_cell = use_ref(&cx, || RefCell::new(None)); @@ -168,7 +168,7 @@ where T: Clone + Data + PartialEq + 'static, C: Compose, { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { let last = use_ref(&cx, RefCell::default); let mut last = last.borrow_mut(); if let Some(last) = &mut *last { @@ -209,7 +209,7 @@ struct DynComposeState { } impl<'a> Compose for DynCompose<'a> { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); let cell: &UnsafeCell> = use_ref(&cx, || UnsafeCell::new(None)); @@ -256,7 +256,7 @@ macro_rules! impl_tuples { } impl<$($t: Compose),*> Compose for ($($t,)*) { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); $( @@ -299,7 +299,7 @@ pub(crate) trait AnyCompose { unsafe fn reborrow(&mut self, ptr: *mut ()); - unsafe fn any_compose(&self, state: &ScopeData); + unsafe fn any_compose(&self, state: &ScopeData<'_>); fn name(&self) -> Cow<'static, str>; } @@ -320,7 +320,7 @@ where std::ptr::swap(self, ptr as _); } - unsafe fn any_compose(&self, state: &ScopeData) { + unsafe fn any_compose(&self, state: &ScopeData<'_>) { state.hook_idx.set(0); // Transmute the lifetime of `&Self`, `&ScopeData`, and the `Scope` containing both to the same`'a`. diff --git a/crates/actuate-core/src/lib.rs b/crates/actuate-core/src/lib.rs index 85250c0..e6a67c8 100644 --- a/crates/actuate-core/src/lib.rs +++ b/crates/actuate-core/src/lib.rs @@ -11,6 +11,11 @@ //! Instead, always use hooks at the top level of your composable, before any early returns. #![deny(missing_docs)] +#![warn(rust_2018_idioms)] +#![warn(future_incompatible)] +#![deny(clippy::all)] +#![deny(clippy::if_not_else)] +#![deny(clippy::enum_glob_use)] use slotmap::{DefaultKey, SlotMap}; use std::{ @@ -156,7 +161,7 @@ unsafe impl Data for RefMap<'_, T> { } impl Compose for RefMap<'_, C> { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); let state = use_ref(&cx, || { @@ -215,7 +220,7 @@ unsafe impl Sync for Map<'_, T> {} // Safety: The `Map` is dereferenced every re-compose, so it's guranteed not to point to // an invalid memory location (e.g. an `Option` that previously returned `Some` is now `None`). impl Compose for Map<'_, C> { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.is_container.set(true); let state = use_ref(&cx, || { @@ -528,7 +533,7 @@ impl<'a, C> Deref for Scope<'a, C> { /// Use an immutable reference to a value of type `T`. /// /// `make_value` will only be called once to initialize this value. -pub fn use_ref(cx: ScopeState, make_value: impl FnOnce() -> T) -> &T { +pub fn use_ref(cx: ScopeState<'_>, make_value: impl FnOnce() -> T) -> &T { let hooks = unsafe { &mut *cx.hooks.get() }; let idx = cx.hook_idx.get(); @@ -551,7 +556,7 @@ struct MutState { /// Use a mutable reference to a value of type `T`. /// /// `make_value` will only be called once to initialize this value. -pub fn use_mut(cx: ScopeState, make_value: impl FnOnce() -> T) -> Mut<'_, T> { +pub fn use_mut(cx: ScopeState<'_>, make_value: impl FnOnce() -> T) -> Mut<'_, T> { let hooks = unsafe { &mut *cx.hooks.get() }; let idx = cx.hook_idx.get(); @@ -629,7 +634,7 @@ impl fmt::Display for ContextError { /// /// # Panics /// Panics if the context value is not found. -pub fn use_context(cx: &ScopeData) -> Result, ContextError> { +pub fn use_context(cx: &ScopeData<'_>) -> Result, ContextError> { let Some(any) = cx.contexts.borrow().values.get(&TypeId::of::()).cloned() else { return Err(ContextError { _marker: PhantomData, @@ -721,7 +726,7 @@ pub fn use_memo<'a, D, T>( cx: ScopeState<'_>, dependency: D, make_value: impl FnOnce() -> T, -) -> Ref +) -> Ref<'_, T> where D: Memoize, T: 'static, @@ -998,7 +1003,7 @@ mod tests { } impl Compose for Counter { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.me().x.set(cx.me().x.get() + 1); cx.set_changed(); @@ -1011,7 +1016,7 @@ mod tests { } impl Compose for NonUpdateCounter { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { cx.me().x.set(cx.me().x.get() + 1); } } @@ -1024,7 +1029,7 @@ mod tests { } impl Compose for Wrap { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { Counter { x: cx.me().x.clone(), } @@ -1049,7 +1054,7 @@ mod tests { } impl Compose for Wrap { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { NonUpdateCounter { x: cx.me().x.clone(), } @@ -1074,7 +1079,7 @@ mod tests { } impl Compose for Wrap { - fn compose(cx: crate::Scope) -> impl Compose { + fn compose(cx: crate::Scope<'_, Self>) -> impl Compose { DynCompose::new(Counter { x: cx.me().x.clone(), }) @@ -1099,7 +1104,7 @@ mod tests { } impl Compose for B { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { *cx.me().x.borrow_mut() += 1; } } @@ -1110,7 +1115,7 @@ mod tests { } impl Compose for A { - fn compose(cx: Scope) -> impl Compose { + fn compose(cx: Scope<'_, Self>) -> impl Compose { let x = cx.me().x.clone(); Memo::new((), B { x }) }