Implement some clippy fixes

This commit is contained in:
Jonathan Kelley 2024-01-30 18:17:45 -08:00
parent a72c035de4
commit 09e14f1936
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
11 changed files with 103 additions and 133 deletions

2
Cargo.lock generated
View file

@ -2466,8 +2466,6 @@ name = "dioxus-core"
version = "0.4.3" version = "0.4.3"
dependencies = [ dependencies = [
"dioxus", "dioxus",
"dioxus-core",
"dioxus-html",
"dioxus-ssr", "dioxus-ssr",
"futures-channel", "futures-channel",
"futures-util", "futures-util",

View file

@ -56,7 +56,7 @@ version = "0.4.3"
# dependencies that are shared across packages # dependencies that are shared across packages
[workspace.dependencies] [workspace.dependencies]
dioxus = { path = "packages/dioxus", version = "0.4.0", default-features = false } dioxus = { path = "packages/dioxus", version = "0.4.0" }
dioxus-lib = { path = "packages/dioxus-lib", version = "0.4.0" } dioxus-lib = { path = "packages/dioxus-lib", version = "0.4.0" }
dioxus-core = { path = "packages/core", version = "0.4.2" } dioxus-core = { path = "packages/core", version = "0.4.2" }
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" } dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }

View file

@ -25,8 +25,6 @@ serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies] [dev-dependencies]
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
dioxus = { workspace = true } dioxus = { workspace = true }
dioxus-core = { workspace = true }
dioxus-html = { workspace = true, features = ["serialize"] }
pretty_assertions = "1.3.0" pretty_assertions = "1.3.0"
rand = "0.8.5" rand = "0.8.5"
dioxus-ssr = { workspace = true } dioxus-ssr = { workspace = true }

View file

@ -738,6 +738,7 @@ impl PartialEq for AttributeValue {
(Self::Bool(l0), Self::Bool(r0)) => l0 == r0, (Self::Bool(l0), Self::Bool(r0)) => l0 == r0,
(Self::Listener(_), Self::Listener(_)) => true, (Self::Listener(_), Self::Listener(_)) => true,
(Self::Any(l0), Self::Any(r0)) => l0.as_ref().any_cmp(r0.as_ref()), (Self::Any(l0), Self::Any(r0)) => l0.as_ref().any_cmp(r0.as_ref()),
(Self::None, Self::None) => true,
_ => false, _ => false,
} }
} }

View file

@ -1,6 +1,6 @@
use dioxus::dioxus_core::Mutation::*; use dioxus::dioxus_core::Mutation::*;
use dioxus::dioxus_core::{AttributeValue, ElementId, NoOpMutations};
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_core::{AttributeValue, ElementId, NoOpMutations};
#[test] #[test]
fn text_diff() { fn text_diff() {
@ -85,119 +85,99 @@ fn element_swap() {
#[test] #[test]
fn attribute_diff() { fn attribute_diff() {
// fn app() -> Element { fn app() -> Element {
// let gen = cx.generation(); let gen = generation();
// // attributes have to be sorted by name // attributes have to be sorted by name
// let attrs = match gen % 5 { let attrs = match gen % 5 {
// 0 => cx.bump().alloc([Attribute::new( 0 => vec![Attribute::new(
// "a", "a",
// AttributeValue::Text("hello".into()), AttributeValue::Text("hello".into()),
// None, None,
// false, false,
// )]) as &[Attribute], )],
// 1 => cx.bump().alloc([ 1 => vec![
// Attribute::new("a", AttributeValue::Text("hello".into()), None, false), Attribute::new("a", AttributeValue::Text("hello".into()), None, false),
// Attribute::new("b", AttributeValue::Text("hello".into()), None, false), Attribute::new("b", AttributeValue::Text("hello".into()), None, false),
// Attribute::new("c", AttributeValue::Text("hello".into()), None, false), Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
// ]) as &[Attribute], ],
// 2 => cx.bump().alloc([ 2 => vec![
// Attribute::new("c", AttributeValue::Text("hello".into()), None, false), Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
// Attribute::new("d", AttributeValue::Text("hello".into()), None, false), Attribute::new("d", AttributeValue::Text("hello".into()), None, false),
// Attribute::new("e", AttributeValue::Text("hello".into()), None, false), Attribute::new("e", AttributeValue::Text("hello".into()), None, false),
// ]) as &[Attribute], ],
// 3 => cx.bump().alloc([Attribute::new( 3 => vec![Attribute::new(
// "d", "d",
// AttributeValue::Text("world".into()), AttributeValue::Text("world".into()),
// None, None,
// false, false,
// )]) as &[Attribute], )],
// _ => unreachable!(), _ => unreachable!(),
// }; };
// cx.render(rsx!( rsx!(
// div { div {
// ..*attrs, ..attrs,
// "hello" "hello"
// } }
// )) )
// } }
// let mut vdom = VirtualDom::new(app); let mut vdom = VirtualDom::new(app);
// _ = vdom.rebuild(); vdom.rebuild(&mut NoOpMutations);
// vdom.mark_dirty(ScopeId::ROOT); vdom.mark_dirty(ScopeId::ROOT);
// assert_eq!( assert_eq!(
// vdom.render_immediate().santize().edits, vdom.render_immediate_to_vec().santize().edits,
// [ [
// SetAttribute { SetAttribute {
// name: "b", name: "b",
// value: (&AttributeValue::Text("hello",)).into(), value: (AttributeValue::Text("hello".into())),
// id: ElementId(1,), id: ElementId(1,),
// ns: None, ns: None,
// }, },
// SetAttribute { SetAttribute {
// name: "c", name: "c",
// value: (&AttributeValue::Text("hello",)).into(), value: (AttributeValue::Text("hello".into())),
// id: ElementId(1,), id: ElementId(1,),
// ns: None, ns: None,
// }, },
// ] ]
// ); );
// vdom.mark_dirty(ScopeId::ROOT); vdom.mark_dirty(ScopeId::ROOT);
// assert_eq!( assert_eq!(
// vdom.render_immediate().santize().edits, vdom.render_immediate_to_vec().santize().edits,
// [ [
// SetAttribute { SetAttribute { name: "a", value: AttributeValue::None, id: ElementId(1,), ns: None },
// name: "a", SetAttribute { name: "b", value: AttributeValue::None, id: ElementId(1,), ns: None },
// value: (&AttributeValue::None).into(), SetAttribute {
// id: ElementId(1,), name: "d",
// ns: None, value: AttributeValue::Text("hello".into()),
// }, id: ElementId(1,),
// SetAttribute { ns: None,
// name: "b", },
// value: (&AttributeValue::None).into(), SetAttribute {
// id: ElementId(1,), name: "e",
// ns: None, value: AttributeValue::Text("hello".into()),
// }, id: ElementId(1,),
// SetAttribute { ns: None,
// name: "d", },
// value: (&AttributeValue::Text("hello",)).into(), ]
// id: ElementId(1,), );
// ns: None,
// },
// SetAttribute {
// name: "e",
// value: (&AttributeValue::Text("hello",)).into(),
// id: ElementId(1,),
// ns: None,
// },
// ]
// );
// vdom.mark_dirty(ScopeId::ROOT); vdom.mark_dirty(ScopeId::ROOT);
// assert_eq!( assert_eq!(
// vdom.render_immediate().santize().edits, vdom.render_immediate_to_vec().santize().edits,
// [ [
// SetAttribute { SetAttribute { name: "c", value: AttributeValue::None, id: ElementId(1,), ns: None },
// name: "c", SetAttribute {
// value: (&AttributeValue::None).into(), name: "d",
// id: ElementId(1,), value: AttributeValue::Text("world".into()),
// ns: None, id: ElementId(1,),
// }, ns: None,
// SetAttribute { },
// name: "d", SetAttribute { name: "e", value: AttributeValue::None, id: ElementId(1,), ns: None },
// value: (&AttributeValue::Text("world",)).into(), ]
// id: ElementId(1,), );
// ns: None,
// },
// SetAttribute {
// name: "e",
// value: (&AttributeValue::None).into(),
// id: ElementId(1,),
// ns: None,
// },
// ]
// );
} }

View file

@ -6,7 +6,7 @@ static CLICKS: Mutex<usize> = Mutex::new(0);
#[test] #[test]
fn events_propagate() { fn events_propagate() {
set_event_converter(Box::new(dioxus_html::SerializedHtmlEventConverter)); set_event_converter(Box::new(dioxus::html::SerializedHtmlEventConverter));
let mut dom = VirtualDom::new(app); let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations); dom.rebuild(&mut dioxus_core::NoOpMutations);

View file

@ -3,8 +3,8 @@
//! Tests for the lifecycle of components. //! Tests for the lifecycle of components.
use dioxus::dioxus_core::{ElementId, Mutation::*}; use dioxus::dioxus_core::{ElementId, Mutation::*};
use dioxus::html::SerializedHtmlEventConverter;
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_html::SerializedHtmlEventConverter;
use std::rc::Rc; use std::rc::Rc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View file

@ -94,7 +94,7 @@ async fn flushing() {
fn app() -> Element { fn app() -> Element {
use_hook(|| { use_hook(|| {
spawn(async move { spawn(async move {
for x in 0..10 { for _ in 0..10 {
flush_sync().await; flush_sync().await;
SEQUENCE.with(|s| s.borrow_mut().push(1)); SEQUENCE.with(|s| s.borrow_mut().push(1));
} }
@ -103,7 +103,7 @@ async fn flushing() {
use_hook(|| { use_hook(|| {
spawn(async move { spawn(async move {
for x in 0..10 { for _ in 0..10 {
flush_sync().await; flush_sync().await;
SEQUENCE.with(|s| s.borrow_mut().push(2)); SEQUENCE.with(|s| s.borrow_mut().push(2));
} }

View file

@ -97,7 +97,7 @@ where
/// See the docs for [`use_coroutine`] for more details. /// See the docs for [`use_coroutine`] for more details.
#[must_use] #[must_use]
pub fn use_coroutine_handle<M: 'static>() -> Coroutine<M> { pub fn use_coroutine_handle<M: 'static>() -> Coroutine<M> {
use_hook(|| consume_context::<Coroutine<M>>()) use_hook(consume_context::<Coroutine<M>>)
} }
#[derive(PartialEq)] #[derive(PartialEq)]
@ -110,7 +110,7 @@ pub struct Coroutine<T: 'static> {
impl<T> Coroutine<T> { impl<T> Coroutine<T> {
/// Get the underlying task handle /// Get the underlying task handle
pub fn task(&self) -> Task { pub fn task(&self) -> Task {
self.task.read().clone().unwrap() (*self.task.read()).unwrap()
} }
/// Send a message to the coroutine /// Send a message to the coroutine
@ -133,12 +133,9 @@ impl<T> Coroutine<T> {
// manual impl since deriving doesn't work with generics // manual impl since deriving doesn't work with generics
impl<T> Copy for Coroutine<T> {} impl<T> Copy for Coroutine<T> {}
impl<T> Clone for Coroutine<T> { impl<T> Clone for Coroutine<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { *self
tx: self.tx,
task: self.task,
needs_regen: self.needs_regen,
}
} }
} }

View file

@ -39,13 +39,9 @@ where
let res = future::poll_fn(|cx| { let res = future::poll_fn(|cx| {
// Set the effect stack properly // Set the effect stack properly
// Poll the inner future
let ready = fut.poll_unpin(cx);
// add any dependencies to the effect stack that we need to watch when restarting the future // add any dependencies to the effect stack that we need to watch when restarting the future
// Poll the inner future
ready fut.poll_unpin(cx)
}) })
.await; .await;

View file

@ -52,7 +52,7 @@ where
fn default() -> Self { fn default() -> Self {
Self { Self {
current: "/".parse().unwrap_or_else(|err| { current: "/".parse().unwrap_or_else(|err| {
panic!("index route does not exist:\n{}\n use MemoryHistory::with_initial_path to set a custom path", err) panic!("index route does not exist:\n{err}\n use MemoryHistory::with_initial_path to set a custom path")
}), }),
history: Vec::new(), history: Vec::new(),
future: Vec::new(), future: Vec::new(),