chore: make clippy happy

This commit is contained in:
Jonathan Kelley committed 2022-07-02 23:45:32 -04:00
1 parent fcbd260f1a
commit 2884d72b08
10 files changed
+42 -50

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ enum Event {
const MAX_EVENTS: usize = 8; const MAX_EVENTS: usize = 8;
fn app(cx: Scope) -> Element { 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 events_lock = events.read();
let first_index = events_lock.len().saturating_sub(MAX_EVENTS); let first_index = events_lock.len().saturating_sub(MAX_EVENTS);
+2
View File
@@ -1,3 +1,5 @@
#![allow(unused)]
const SRC: &str = include_str!("./samples/all.rs"); const SRC: &str = include_str!("./samples/all.rs");
fn body() -> &'static str { fn body() -> &'static str {
+4 -7
View File
@@ -8,22 +8,19 @@ fn formatting_compiles() {
// escape sequences work // escape sequences work
assert_eq!( assert_eq!(
format_args_f!("{x:?} {{}}}}").to_string(), format_args_f!("{x:?} {{}}}}").to_string(),
format!("{:?} {{}}}}", x).to_string() format!("{:?} {{}}}}", x)
); );
assert_eq!( assert_eq!(
format_args_f!("{{{{}} {x:?}").to_string(), format_args_f!("{{{{}} {x:?}").to_string(),
format!("{{{{}} {:?}", x).to_string() format!("{{{{}} {:?}", x)
); );
// paths in formating works // paths in formating works
assert_eq!( assert_eq!(format_args_f!("{x.0}").to_string(), format!("{}", x.0));
format_args_f!("{x.0}").to_string(),
format!("{}", x.0).to_string()
);
// function calls in formatings work // function calls in formatings work
assert_eq!( assert_eq!(
format_args_f!("{x.borrow():?}").to_string(), format_args_f!("{x.borrow():?}").to_string(),
format!("{:?}", x.borrow()).to_string() format!("{:?}", x.borrow())
); );
} }
+2 -2
View File
@@ -2,11 +2,11 @@ use crate::{use_atom_root, AtomId, AtomRoot, Readable};
use dioxus_core::{ScopeId, ScopeState}; use dioxus_core::{ScopeId, ScopeState};
use std::rc::Rc; 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() 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); let root = use_atom_root(cx);
struct UseReadInner<V> { struct UseReadInner<V> {
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{use_atom_root, Writable};
use dioxus_core::ScopeState; use dioxus_core::ScopeState;
use std::rc::Rc; 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); let root = use_atom_root(cx);
cx.use_hook(|_| { cx.use_hook(|_| {
let id = f.unique_id(); let id = f.unique_id();
+4 -4
View File
@@ -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 root = crate::use_atom_root(cx);
let inner = cx.use_hook(|_| AtomState { 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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value.as_ref().unwrap()) 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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:b}", self.value.as_ref().unwrap().as_ref()) 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; type Target = T;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@@ -124,9 +124,9 @@ impl ToTokens for CapturedContextBuilder {
let expr = segment.to_token_stream(); let expr = segment.to_token_stream();
let as_string = expr.to_string(); let as_string = expr.to_string();
let format_expr = if format_args.is_empty() { let format_expr = if format_args.is_empty() {
"{".to_string() + &format_args + "}" "{".to_string() + format_args + "}"
} else { } else {
"{".to_string() + ":" + &format_args + "}" "{".to_string() + ":" + format_args + "}"
}; };
Some(quote! { Some(quote! {
FormattedArg{ FormattedArg{
+3 -3
View File
@@ -44,13 +44,13 @@ impl ParseError {
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Error::ParseError(error) => write!( Error::ParseError(error) => writeln!(
f, 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.location.file_path, error.location.line, error.location.column, error.message
), ),
Error::RecompileRequiredError(reason) => { Error::RecompileRequiredError(reason) => {
write!(f, "recompile required: {:?}\n", reason) writeln!(f, "recompile required: {:?}", reason)
} }
} }
} }
+22 -29
View File
@@ -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) Ok(result)
@@ -119,21 +119,16 @@ fn build_node<'a>(
is_volatile: false, is_volatile: false,
namespace, namespace,
}); });
} else if literal {
// literals will be captured when a full recompile is triggered
return Err(Error::RecompileRequiredError(
RecompileReason::CapturedAttribute(name.to_string()),
));
} else { } else {
if literal { return Err(Error::ParseError(ParseError::new(
// literals will be captured when a full recompile is triggered syn::Error::new(span, format!("unknown attribute: {}", name)),
return Err(Error::RecompileRequiredError( ctx.location.clone(),
RecompileReason::CapturedAttribute(name.to_string()), )));
));
} else {
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, is_volatile: false,
namespace, namespace,
}); });
} else if literal {
// literals will be captured when a full recompile is triggered
return Err(Error::RecompileRequiredError(
RecompileReason::CapturedAttribute(name.to_string()),
));
} else { } else {
if literal { return Err(Error::ParseError(ParseError::new(
// literals will be captured when a full recompile is triggered syn::Error::new(
return Err(Error::RecompileRequiredError( span,
RecompileReason::CapturedAttribute(name.to_string()), format!("unknown attribute: {}", name),
)); ),
} else { ctx.location.clone(),
return Err(Error::ParseError(ParseError::new( )));
syn::Error::new(
span,
format!("unknown attribute: {}", name),
),
ctx.location.clone(),
)));
}
} }
} }
} }
+1 -1
View File
@@ -65,7 +65,7 @@ pub fn resolve_scope<'a>(
} }
} }
fn interpert_rsx<'a, 'b>( fn interpert_rsx<'a>(
factory: dioxus_core::NodeFactory<'a>, factory: dioxus_core::NodeFactory<'a>,
text: &str, text: &str,
context: captuered_context::CapturedContext<'a>, context: captuered_context::CapturedContext<'a>,