Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic lints #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions crates/actuate-core/src/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
/// For a dynamically-typed composable, see [`DynCompose`].
pub trait Compose: Data {
/// Compose this function.
fn compose(cx: Scope<Self>) -> impl Compose;
fn compose(cx: Scope<'_, Self>) -> impl Compose;

#[doc(hidden)]
fn name() -> Cow<'static, str> {
Expand All @@ -27,24 +27,24 @@ pub trait Compose: Data {
}

impl Compose for () {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_empty.set(true);
}
}

impl<C: Compose> Compose for &C {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
unsafe {
(**cx.me()).any_compose(&cx);
}
}
}

impl<C: Compose> Compose for Option<C> {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

let state_cell: &RefCell<Option<ScopeData>> = use_ref(&cx, || RefCell::new(None));
let state_cell: &RefCell<Option<ScopeData<'_>>> = use_ref(&cx, || RefCell::new(None));
let mut state_cell = state_cell.borrow_mut();

if let Some(content) = &*cx.me() {
Expand Down Expand Up @@ -104,7 +104,7 @@ where
Item: Data,
C: Compose,
{
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

let items_cell = use_ref(&cx, || RefCell::new(None));
Expand Down Expand Up @@ -168,7 +168,7 @@ where
T: Clone + Data + PartialEq + 'static,
C: Compose,
{
fn compose(cx: Scope<Self>) -> 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 {
Expand Down Expand Up @@ -209,7 +209,7 @@ struct DynComposeState {
}

impl<'a> Compose for DynCompose<'a> {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

let cell: &UnsafeCell<Option<DynComposeState>> = use_ref(&cx, || UnsafeCell::new(None));
Expand Down Expand Up @@ -256,7 +256,7 @@ macro_rules! impl_tuples {
}

impl<$($t: Compose),*> Compose for ($($t,)*) {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

$(
Expand Down Expand Up @@ -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>;
}
Expand All @@ -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`.
Expand Down
31 changes: 18 additions & 13 deletions crates/actuate-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -156,7 +161,7 @@ unsafe impl<T: Data> Data for RefMap<'_, T> {
}

impl<C: Compose> Compose for RefMap<'_, C> {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

let state = use_ref(&cx, || {
Expand Down Expand Up @@ -215,7 +220,7 @@ unsafe impl<T: Sync> 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<C: Compose> Compose for Map<'_, C> {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.is_container.set(true);

let state = use_ref(&cx, || {
Expand Down Expand Up @@ -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<T: 'static>(cx: ScopeState, make_value: impl FnOnce() -> T) -> &T {
pub fn use_ref<T: 'static>(cx: ScopeState<'_>, make_value: impl FnOnce() -> T) -> &T {
let hooks = unsafe { &mut *cx.hooks.get() };

let idx = cx.hook_idx.get();
Expand All @@ -551,7 +556,7 @@ struct MutState<T> {
/// 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<T: 'static>(cx: ScopeState, make_value: impl FnOnce() -> T) -> Mut<'_, T> {
pub fn use_mut<T: 'static>(cx: ScopeState<'_>, make_value: impl FnOnce() -> T) -> Mut<'_, T> {
let hooks = unsafe { &mut *cx.hooks.get() };

let idx = cx.hook_idx.get();
Expand Down Expand Up @@ -629,7 +634,7 @@ impl<T> fmt::Display for ContextError<T> {
///
/// # Panics
/// Panics if the context value is not found.
pub fn use_context<T: 'static>(cx: &ScopeData) -> Result<Rc<T>, ContextError<T>> {
pub fn use_context<T: 'static>(cx: &ScopeData<'_>) -> Result<Rc<T>, ContextError<T>> {
let Some(any) = cx.contexts.borrow().values.get(&TypeId::of::<T>()).cloned() else {
return Err(ContextError {
_marker: PhantomData,
Expand Down Expand Up @@ -721,7 +726,7 @@ pub fn use_memo<'a, D, T>(
cx: ScopeState<'_>,
dependency: D,
make_value: impl FnOnce() -> T,
) -> Ref<T>
) -> Ref<'_, T>
where
D: Memoize,
T: 'static,
Expand Down Expand Up @@ -998,7 +1003,7 @@ mod tests {
}

impl Compose for Counter {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.me().x.set(cx.me().x.get() + 1);

cx.set_changed();
Expand All @@ -1011,7 +1016,7 @@ mod tests {
}

impl Compose for NonUpdateCounter {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
cx.me().x.set(cx.me().x.get() + 1);
}
}
Expand All @@ -1024,7 +1029,7 @@ mod tests {
}

impl Compose for Wrap {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
Counter {
x: cx.me().x.clone(),
}
Expand All @@ -1049,7 +1054,7 @@ mod tests {
}

impl Compose for Wrap {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
NonUpdateCounter {
x: cx.me().x.clone(),
}
Expand All @@ -1074,7 +1079,7 @@ mod tests {
}

impl Compose for Wrap {
fn compose(cx: crate::Scope<Self>) -> impl Compose {
fn compose(cx: crate::Scope<'_, Self>) -> impl Compose {
DynCompose::new(Counter {
x: cx.me().x.clone(),
})
Expand All @@ -1099,7 +1104,7 @@ mod tests {
}

impl Compose for B {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
*cx.me().x.borrow_mut() += 1;
}
}
Expand All @@ -1110,7 +1115,7 @@ mod tests {
}

impl Compose for A {
fn compose(cx: Scope<Self>) -> impl Compose {
fn compose(cx: Scope<'_, Self>) -> impl Compose {
let x = cx.me().x.clone();
Memo::new((), B { x })
}
Expand Down
Loading