Browse Source

chore: make clippy happy

Jonathan Kelley 3 năm trước cách đây
mục cha
commit
2884d72b08

+ 1 - 1
examples/tui_all_events.rs

@@ -27,7 +27,7 @@ enum Event {
 const MAX_EVENTS: usize = 8;
 
 fn app(cx: Scope) -> Element {
-    let events = use_ref(&cx, || Vec::new());
+    let events = use_ref(&cx, Vec::new);
 
     let events_lock = events.read();
     let first_index = events_lock.len().saturating_sub(MAX_EVENTS);

+ 2 - 0
packages/autofmt/tests/sample.rs

@@ -1,3 +1,5 @@
+#![allow(unused)]
+
 const SRC: &str = include_str!("./samples/all.rs");
 
 fn body() -> &'static str {

+ 4 - 7
packages/core-macro/tests/ifmt.rs

@@ -8,22 +8,19 @@ fn formatting_compiles() {
     // escape sequences work
     assert_eq!(
         format_args_f!("{x:?} {{}}}}").to_string(),
-        format!("{:?} {{}}}}", x).to_string()
+        format!("{:?} {{}}}}", x)
     );
     assert_eq!(
         format_args_f!("{{{{}} {x:?}").to_string(),
-        format!("{{{{}} {:?}", x).to_string()
+        format!("{{{{}} {:?}", x)
     );
 
     // paths in formating works
-    assert_eq!(
-        format_args_f!("{x.0}").to_string(),
-        format!("{}", x.0).to_string()
-    );
+    assert_eq!(format_args_f!("{x.0}").to_string(), format!("{}", x.0));
 
     // function calls in formatings work
     assert_eq!(
         format_args_f!("{x.borrow():?}").to_string(),
-        format!("{:?}", x.borrow()).to_string()
+        format!("{:?}", x.borrow())
     );
 }

+ 2 - 2
packages/fermi/src/hooks/read.rs

@@ -2,11 +2,11 @@ use crate::{use_atom_root, AtomId, AtomRoot, Readable};
 use dioxus_core::{ScopeId, ScopeState};
 use std::rc::Rc;
 
-pub fn use_read<'a, V: 'static>(cx: &'a ScopeState, f: impl Readable<V>) -> &'a V {
+pub fn use_read<V: 'static>(cx: &ScopeState, f: impl Readable<V>) -> &V {
     use_read_rc(cx, f).as_ref()
 }
 
-pub fn use_read_rc<'a, V: 'static>(cx: &'a ScopeState, f: impl Readable<V>) -> &'a Rc<V> {
+pub fn use_read_rc<V: 'static>(cx: &ScopeState, f: impl Readable<V>) -> &Rc<V> {
     let root = use_atom_root(cx);
 
     struct UseReadInner<V> {

+ 1 - 1
packages/fermi/src/hooks/set.rs

@@ -2,7 +2,7 @@ use crate::{use_atom_root, Writable};
 use dioxus_core::ScopeState;
 use std::rc::Rc;
 
-pub fn use_set<'a, T: 'static>(cx: &'a ScopeState, f: impl Writable<T>) -> &'a Rc<dyn Fn(T)> {
+pub fn use_set<T: 'static>(cx: &ScopeState, f: impl Writable<T>) -> &Rc<dyn Fn(T)> {
     let root = use_atom_root(cx);
     cx.use_hook(|_| {
         let id = f.unique_id();

+ 4 - 4
packages/fermi/src/hooks/state.rs

@@ -30,7 +30,7 @@ use std::{
 ///     ))
 /// }
 /// ```
-pub fn use_atom_state<'a, T: 'static>(cx: &'a ScopeState, f: impl Writable<T>) -> &'a AtomState<T> {
+pub fn use_atom_state<T: 'static>(cx: &ScopeState, f: impl Writable<T>) -> &AtomState<T> {
     let root = crate::use_atom_root(cx);
 
     let inner = cx.use_hook(|_| AtomState {
@@ -279,13 +279,13 @@ impl<T: 'static> Clone for AtomState<T> {
     }
 }
 
-impl<'a, T: 'static + Display> std::fmt::Display for AtomState<T> {
+impl<T: 'static + Display> std::fmt::Display for AtomState<T> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{}", self.value.as_ref().unwrap())
     }
 }
 
-impl<'a, T: std::fmt::Binary> std::fmt::Binary for AtomState<T> {
+impl<T: std::fmt::Binary> std::fmt::Binary for AtomState<T> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{:b}", self.value.as_ref().unwrap().as_ref())
     }
@@ -316,7 +316,7 @@ impl<T: Debug> Debug for AtomState<T> {
     }
 }
 
-impl<'a, T> std::ops::Deref for AtomState<T> {
+impl<T> std::ops::Deref for AtomState<T> {
     type Target = T;
 
     fn deref(&self) -> &Self::Target {

+ 2 - 2
packages/rsx_interpreter/src/captuered_context.rs

@@ -124,9 +124,9 @@ impl ToTokens for CapturedContextBuilder {
                     let expr = segment.to_token_stream();
                     let as_string = expr.to_string();
                     let format_expr = if format_args.is_empty() {
-                        "{".to_string() + &format_args + "}"
+                        "{".to_string() + format_args + "}"
                     } else {
-                        "{".to_string() + ":" + &format_args + "}"
+                        "{".to_string() + ":" + format_args + "}"
                     };
                     Some(quote! {
                         FormattedArg{

+ 3 - 3
packages/rsx_interpreter/src/error.rs

@@ -44,13 +44,13 @@ impl ParseError {
 impl Display for Error {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         match self {
-            Error::ParseError(error) => write!(
+            Error::ParseError(error) => writeln!(
                 f,
-                "parse error:\n--> at {}:{}:{}\n\t{:?}\n",
+                "parse error:\n--> at {}:{}:{}\n\t{:?}",
                 error.location.file_path, error.location.line, error.location.column, error.message
             ),
             Error::RecompileRequiredError(reason) => {
-                write!(f, "recompile required: {:?}\n", reason)
+                writeln!(f, "recompile required: {:?}", reason)
             }
         }
     }

+ 22 - 29
packages/rsx_interpreter/src/interperter.rs

@@ -38,7 +38,7 @@ fn resolve_ifmt(ifmt: &IfmtInput, captured: &IfmtArgs) -> Result<String, Error>
                     }
                 }
             }
-            Segment::Literal(lit) => result.push_str(&lit),
+            Segment::Literal(lit) => result.push_str(lit),
         }
     }
     Ok(result)
@@ -119,21 +119,16 @@ fn build_node<'a>(
                                     is_volatile: false,
                                     namespace,
                                 });
+                            } else if literal {
+                                // literals will be captured when a full recompile is triggered
+                                return Err(Error::RecompileRequiredError(
+                                    RecompileReason::CapturedAttribute(name.to_string()),
+                                ));
                             } else {
-                                if literal {
-                                    // literals will be captured when a full recompile is triggered
-                                    return Err(Error::RecompileRequiredError(
-                                        RecompileReason::CapturedAttribute(name.to_string()),
-                                    ));
-                                } else {
-                                    return Err(Error::ParseError(ParseError::new(
-                                        syn::Error::new(
-                                            span,
-                                            format!("unknown attribute: {}", name),
-                                        ),
-                                        ctx.location.clone(),
-                                    )));
-                                }
+                                return Err(Error::ParseError(ParseError::new(
+                                    syn::Error::new(span, format!("unknown attribute: {}", name)),
+                                    ctx.location.clone(),
+                                )));
                             }
                         }
 
@@ -164,21 +159,19 @@ fn build_node<'a>(
                                         is_volatile: false,
                                         namespace,
                                     });
+                                } else if literal {
+                                    // literals will be captured when a full recompile is triggered
+                                    return Err(Error::RecompileRequiredError(
+                                        RecompileReason::CapturedAttribute(name.to_string()),
+                                    ));
                                 } else {
-                                    if literal {
-                                        // literals will be captured when a full recompile is triggered
-                                        return Err(Error::RecompileRequiredError(
-                                            RecompileReason::CapturedAttribute(name.to_string()),
-                                        ));
-                                    } else {
-                                        return Err(Error::ParseError(ParseError::new(
-                                            syn::Error::new(
-                                                span,
-                                                format!("unknown attribute: {}", name),
-                                            ),
-                                            ctx.location.clone(),
-                                        )));
-                                    }
+                                    return Err(Error::ParseError(ParseError::new(
+                                        syn::Error::new(
+                                            span,
+                                            format!("unknown attribute: {}", name),
+                                        ),
+                                        ctx.location.clone(),
+                                    )));
                                 }
                             }
                         }

+ 1 - 1
packages/rsx_interpreter/src/lib.rs

@@ -65,7 +65,7 @@ pub fn resolve_scope<'a>(
     }
 }
 
-fn interpert_rsx<'a, 'b>(
+fn interpert_rsx<'a>(
     factory: dioxus_core::NodeFactory<'a>,
     text: &str,
     context: captuered_context::CapturedContext<'a>,