chore: make clippy happy

This commit is contained in:
Jonathan Kelley 2022-07-02 23:45:32 -04:00
parent fcbd260f1a
commit 2884d72b08
10 changed files with 42 additions and 50 deletions

View file

@ -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);

View file

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

View file

@ -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())
);
}

View file

@ -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> {

View file

@ -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();

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 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 {

View file

@ -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{

View file

@ -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)
}
}
}

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)
@ -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(),
)));
}
}
}

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>,
text: &str,
context: captuered_context::CapturedContext<'a>,