Fix clippy lints from 1.54.0 (#1976)

* Fix clippy lints from 1.54.0

* Format fixed code
This commit is contained in:
Xavientois 2021-07-30 11:21:45 -04:00 committed by GitHub
parent f94487364f
commit c9deba05f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 38 additions and 40 deletions

View File

@ -127,7 +127,7 @@ impl Component for Model {
</> </>
}, },
FetchState::Fetching => html! { "Fetching" }, FetchState::Fetching => html! { "Fetching" },
FetchState::Success(data) => html! { markdown::render_markdown(&data) }, FetchState::Success(data) => html! { markdown::render_markdown(data) },
FetchState::Failed(err) => html! { err }, FetchState::Failed(err) => html! { err },
} }
} }

View File

@ -5,10 +5,10 @@ use yew_agent::AgentLink;
pub type PostId = u32; pub type PostId = u32;
#[derive(Debug)] #[derive(Debug)]
pub enum Request { pub enum PostRequest {
CreatePost(String), Create(String),
UpdatePost(PostId, String), Update(PostId, String),
RemovePost(PostId), Remove(PostId),
} }
#[derive(Debug)] #[derive(Debug)]
@ -25,7 +25,7 @@ pub struct PostStore {
impl Store for PostStore { impl Store for PostStore {
type Action = Action; type Action = Action;
type Input = Request; type Input = PostRequest;
fn new() -> Self { fn new() -> Self {
let mut posts = HashMap::new(); let mut posts = HashMap::new();
@ -42,13 +42,13 @@ impl Store for PostStore {
fn handle_input(&self, link: AgentLink<StoreWrapper<Self>>, msg: Self::Input) { fn handle_input(&self, link: AgentLink<StoreWrapper<Self>>, msg: Self::Input) {
match msg { match msg {
Request::CreatePost(text) => { PostRequest::Create(text) => {
link.send_message(Action::SetPost(None, text)); link.send_message(Action::SetPost(None, text));
} }
Request::UpdatePost(id, text) => { PostRequest::Update(id, text) => {
link.send_message(Action::SetPost(Some(id), text)); link.send_message(Action::SetPost(Some(id), text));
} }
Request::RemovePost(id) => { PostRequest::Remove(id) => {
link.send_message(Action::RemovePost(id)); link.send_message(Action::RemovePost(id));
} }
} }

View File

@ -2,7 +2,7 @@ mod agents;
mod post; mod post;
mod text_input; mod text_input;
use agents::posts::{PostId, PostStore, Request}; use agents::posts::{PostId, PostRequest, PostStore};
use post::Post; use post::Post;
use text_input::TextInput; use text_input::TextInput;
use weblog::console_log; use weblog::console_log;
@ -37,7 +37,7 @@ impl Component for Model {
fn update(&mut self, msg: Self::Message) -> ShouldRender { fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg { match msg {
Msg::CreatePost(text) => { Msg::CreatePost(text) => {
self.post_store.send(Request::CreatePost(text)); self.post_store.send(PostRequest::Create(text));
false false
} }
Msg::PostStoreMsg(state) => { Msg::PostStoreMsg(state) => {

View File

@ -1,4 +1,4 @@
use crate::agents::posts::{PostId, PostStore, Request}; use crate::agents::posts::{PostId, PostRequest, PostStore};
use crate::text_input::TextInput; use crate::text_input::TextInput;
use yew::prelude::*; use yew::prelude::*;
use yew::utils::NeqAssign; use yew::utils::NeqAssign;
@ -8,7 +8,7 @@ use yew_agent::Bridge;
pub enum Msg { pub enum Msg {
UpdateText(String), UpdateText(String),
Delete, Delete,
PostStoreMsg(ReadOnly<PostStore>), PostStore(ReadOnly<PostStore>),
} }
#[derive(Properties, Clone, PartialEq)] #[derive(Properties, Clone, PartialEq)]
@ -28,7 +28,7 @@ impl Component for Post {
type Properties = Props; type Properties = Props;
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self { fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
let callback = link.callback(Msg::PostStoreMsg); let callback = link.callback(Msg::PostStore);
Self { Self {
link, link,
id: props.id, id: props.id,
@ -40,14 +40,14 @@ impl Component for Post {
fn update(&mut self, msg: Self::Message) -> ShouldRender { fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg { match msg {
Msg::UpdateText(text) => { Msg::UpdateText(text) => {
self.post_store.send(Request::UpdatePost(self.id, text)); self.post_store.send(PostRequest::Update(self.id, text));
false false
} }
Msg::Delete => { Msg::Delete => {
self.post_store.send(Request::RemovePost(self.id)); self.post_store.send(PostRequest::Remove(self.id));
false false
} }
Msg::PostStoreMsg(state) => { Msg::PostStore(state) => {
let state = state.borrow(); let state = state.borrow();
// Only update if the post changed. // Only update if the post changed.

View File

@ -220,7 +220,7 @@ impl Model {
<label ondblclick={self.link.callback(move |_| Msg::ToggleEdit(idx))}>{ &entry.description }</label> <label ondblclick={self.link.callback(move |_| Msg::ToggleEdit(idx))}>{ &entry.description }</label>
<button class="destroy" onclick={self.link.callback(move |_| Msg::Remove(idx))} /> <button class="destroy" onclick={self.link.callback(move |_| Msg::Remove(idx))} />
</div> </div>
{ self.view_entry_edit_input((idx, &entry)) } { self.view_entry_edit_input((idx, entry)) }
</li> </li>
} }
} }

View File

@ -103,11 +103,11 @@ impl Model {
gl.buffer_data_with_array_buffer_view(GL::ARRAY_BUFFER, &verts, GL::STATIC_DRAW); gl.buffer_data_with_array_buffer_view(GL::ARRAY_BUFFER, &verts, GL::STATIC_DRAW);
let vert_shader = gl.create_shader(GL::VERTEX_SHADER).unwrap(); let vert_shader = gl.create_shader(GL::VERTEX_SHADER).unwrap();
gl.shader_source(&vert_shader, &vert_code); gl.shader_source(&vert_shader, vert_code);
gl.compile_shader(&vert_shader); gl.compile_shader(&vert_shader);
let frag_shader = gl.create_shader(GL::FRAGMENT_SHADER).unwrap(); let frag_shader = gl.create_shader(GL::FRAGMENT_SHADER).unwrap();
gl.shader_source(&frag_shader, &frag_code); gl.shader_source(&frag_shader, frag_code);
gl.compile_shader(&frag_shader); gl.compile_shader(&frag_shader);
let shader_program = gl.create_program().unwrap(); let shader_program = gl.create_program().unwrap();

View File

@ -34,7 +34,7 @@ impl<T: Serialize + for<'de> Deserialize<'de>> Packed for T {
} }
fn unpack(data: &[u8]) -> Self { fn unpack(data: &[u8]) -> Self {
bincode::deserialize(&data).expect("can't deserialize an agent message") bincode::deserialize(data).expect("can't deserialize an agent message")
} }
} }

View File

@ -41,13 +41,13 @@ impl ToTokens for PropsBuilder<'_> {
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let turbofish_generics = ty_generics.as_turbofish(); let turbofish_generics = ty_generics.as_turbofish();
let generic_args = to_arguments(&generics, build_step.clone()); let generic_args = to_arguments(generics, build_step.clone());
// Each builder step implements the `BuilderStep` trait and `step_generics` is used to // Each builder step implements the `BuilderStep` trait and `step_generics` is used to
// enforce that. // enforce that.
let step_generic_param = Ident::new("YEW_PROPS_BUILDER_STEP", Span::call_site()); let step_generic_param = Ident::new("YEW_PROPS_BUILDER_STEP", Span::call_site());
let step_generics = let step_generics =
with_param_bounds(&generics, step_generic_param.clone(), (*step_trait).clone()); with_param_bounds(generics, step_generic_param.clone(), (*step_trait).clone());
let builder = quote! { let builder = quote! {
#( #(

View File

@ -61,13 +61,13 @@ impl ToTokens for DerivePropsInput {
// The wrapper is a new struct which wraps required props in `Option` // The wrapper is a new struct which wraps required props in `Option`
let wrapper_name = Ident::new(&format!("{}Wrapper", props_name), Span::call_site()); let wrapper_name = Ident::new(&format!("{}Wrapper", props_name), Span::call_site());
let wrapper = PropsWrapper::new(&wrapper_name, &generics, &self.prop_fields); let wrapper = PropsWrapper::new(&wrapper_name, generics, &self.prop_fields);
tokens.extend(wrapper.into_token_stream()); tokens.extend(wrapper.into_token_stream());
// The builder will only build if all required props have been set // The builder will only build if all required props have been set
let builder_name = Ident::new(&format!("{}Builder", props_name), Span::call_site()); let builder_name = Ident::new(&format!("{}Builder", props_name), Span::call_site());
let builder_step = Ident::new(&format!("{}BuilderStep", props_name), Span::call_site()); let builder_step = Ident::new(&format!("{}BuilderStep", props_name), Span::call_site());
let builder = PropsBuilder::new(&builder_name, &builder_step, &self, &wrapper_name); let builder = PropsBuilder::new(&builder_name, &builder_step, self, &wrapper_name);
let builder_generic_args = builder.first_step_generic_args(); let builder_generic_args = builder.first_step_generic_args();
tokens.extend(builder.into_token_stream()); tokens.extend(builder.into_token_stream());

View File

@ -16,7 +16,7 @@ pub fn build_router<R: Routable>() -> Router {
router.add(route, path.to_string()); router.add(route, path.to_string());
} }
_ => { _ => {
router.add(&path, path.to_string()); router.add(path, path.to_string());
} }
}; };
}); });

View File

@ -61,7 +61,7 @@ where
T: for<'de> Deserialize<'de>, T: for<'de> Deserialize<'de>,
{ {
let query = yew::utils::document().location().unwrap().search().unwrap(); let query = yew::utils::document().location().unwrap().search().unwrap();
serde_urlencoded::from_str(query.strip_prefix("?").unwrap_or("")) serde_urlencoded::from_str(query.strip_prefix('?').unwrap_or(""))
} }
pub fn current_route<R: Routable>() -> Option<R> { pub fn current_route<R: Routable>() -> Option<R> {

View File

@ -2,7 +2,7 @@ use std::cell::RefCell;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
pub(crate) fn strip_slash_suffix(path: &str) -> &str { pub(crate) fn strip_slash_suffix(path: &str) -> &str {
path.strip_suffix("/").unwrap_or(&path) path.strip_suffix('/').unwrap_or(path)
} }
static BASE_URL_LOADED: std::sync::Once = std::sync::Once::new(); static BASE_URL_LOADED: std::sync::Once = std::sync::Once::new();

View File

@ -1,4 +1,3 @@
#[macro_use]
macro_rules! impl_action { macro_rules! impl_action {
($($action:ident(name: $name:literal, event: $type:ident) -> $ret:ty => $convert:expr)*) => {$( ($($action:ident(name: $name:literal, event: $type:ident) -> $ret:ty => $convert:expr)*) => {$(
/// An abstract implementation of a listener. /// An abstract implementation of a listener.

View File

@ -314,8 +314,7 @@ impl Attributes {
} }
fn set_attribute(el: &Element, key: &str, value: &str) { fn set_attribute(el: &Element, key: &str, value: &str) {
el.set_attribute(&key, &value) el.set_attribute(key, value).expect("invalid attribute key")
.expect("invalid attribute key")
} }
} }
@ -327,7 +326,7 @@ impl Apply for Attributes {
Self::Vec(v) => { Self::Vec(v) => {
for attr in v.iter() { for attr in v.iter() {
if let Some(v) = &attr.1 { if let Some(v) = &attr.1 {
Self::set_attribute(el, &attr.0, v) Self::set_attribute(el, attr.0, v)
} }
} }
} }
@ -346,7 +345,7 @@ impl Apply for Attributes {
Self::set_attribute(el, key, value); Self::set_attribute(el, key, value);
} }
Patch::Remove(key) => { Patch::Remove(key) => {
el.remove_attribute(&key) el.remove_attribute(key)
.expect("could not remove attribute"); .expect("could not remove attribute");
} }
} }
@ -425,7 +424,7 @@ pub(crate) trait VDiff {
pub(crate) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&Node>) { pub(crate) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&Node>) {
match next_sibling { match next_sibling {
Some(next_sibling) => parent Some(next_sibling) => parent
.insert_before(&node, Some(next_sibling)) .insert_before(node, Some(next_sibling))
.expect("failed to insert tag before next sibling"), .expect("failed to insert tag before next sibling"),
None => parent.append_child(node).expect("failed to append child"), None => parent.append_child(node).expect("failed to append child"),
}; };
@ -606,17 +605,17 @@ mod benchmarks {
const TIME_LIMIT: f64 = 2.0; const TIME_LIMIT: f64 = 2.0;
let vv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_vec), |(new, old)| { let vv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_vec), |(new, old)| {
format!("{:?}", Attributes::diff(&new, &old)) format!("{:?}", Attributes::diff(new, old))
}); });
let mm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_map), |(new, old)| { let mm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_map), |(new, old)| {
format!("{:?}", Attributes::diff(&new, &old)) format!("{:?}", Attributes::diff(new, old))
}); });
let vm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_map), |(new, old)| { let vm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_map), |(new, old)| {
format!("{:?}", Attributes::diff(&new, &old)) format!("{:?}", Attributes::diff(new, old))
}); });
let mv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_vec), |(new, old)| { let mv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_vec), |(new, old)| {
format!("{:?}", Attributes::diff(&new, &old)) format!("{:?}", Attributes::diff(new, old))
}); });
wasm_bindgen_test::console_log!( wasm_bindgen_test::console_log!(

View File

@ -422,7 +422,7 @@ mod tests {
// clear parent // clear parent
parent.set_inner_html(""); parent.set_inner_html("");
node.apply(&scope, &parent, NodeRef::default(), None); node.apply(scope, parent, NodeRef::default(), None);
parent.inner_html() parent.inner_html()
} }

View File

@ -165,7 +165,7 @@ impl Apply for Listeners {
*self = Self::Registered( *self = Self::Registered(
std::mem::take(v) std::mem::take(v)
.into_iter() .into_iter()
.map(|l| l.attach(&el)) .map(|l| l.attach(el))
.collect(), .collect(),
); );
} }