From 114dbaea04d45dbe0fdf8982031e2986cf035315 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sun, 2 Feb 2020 14:27:29 +0800 Subject: [PATCH] Fix clippy warnings --- crates/macro/src/html_tree/html_block.rs | 8 +++--- crates/macro/src/html_tree/html_component.rs | 25 +++++++++++-------- crates/macro/src/html_tree/html_node.rs | 8 +++--- .../src/html_tree/html_tag/tag_attributes.rs | 4 +-- crates/macro/src/html_tree/mod.rs | 24 +++++++++--------- examples/dashboard/src/lib.rs | 1 - 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/crates/macro/src/html_tree/html_block.rs b/crates/macro/src/html_tree/html_block.rs index 0c0fbd57ca6..8b7e5d393ac 100644 --- a/crates/macro/src/html_tree/html_block.rs +++ b/crates/macro/src/html_tree/html_block.rs @@ -14,8 +14,8 @@ pub struct HtmlBlock { } enum BlockContent { - Node(HtmlNode), - Iterable(HtmlIterable), + Node(Box), + Iterable(Box), } impl PeekValue<()> for HtmlBlock { @@ -29,9 +29,9 @@ impl Parse for HtmlBlock { let content; let brace = braced!(content in input); let content = if HtmlIterable::peek(content.cursor()).is_some() { - BlockContent::Iterable(content.parse()?) + BlockContent::Iterable(Box::new(content.parse()?)) } else { - BlockContent::Node(content.parse()?) + BlockContent::Node(Box::new(content.parse()?)) }; Ok(HtmlBlock { brace, content }) diff --git a/crates/macro/src/html_tree/html_component.rs b/crates/macro/src/html_tree/html_component.rs index 7893c93aab2..a1afac7c122 100644 --- a/crates/macro/src/html_tree/html_component.rs +++ b/crates/macro/src/html_tree/html_component.rs @@ -87,8 +87,8 @@ impl ToTokens for HtmlComponent { children, } = self; - let validate_props = if let Props::List(ListProps { props, .. }) = props { - let check_props = props.iter().map(|HtmlProp { label, .. }| { + let validate_props = if let Props::List(list_props) = props { + let check_props = list_props.props.iter().map(|HtmlProp { label, .. }| { quote! { props.#label; } }); @@ -121,8 +121,8 @@ impl ToTokens for HtmlComponent { }; let init_props = match props { - Props::List(ListProps { props, .. }) => { - let set_props = props.iter().map(|HtmlProp { label, value }| { + Props::List(list_props) => { + let set_props = list_props.props.iter().map(|HtmlProp { label, value }| { quote_spanned! { value.span()=> .#label( <::yew::virtual_dom::vcomp::VComp as ::yew::virtual_dom::Transformer<_, _>>::transform( #value @@ -137,7 +137,10 @@ impl ToTokens for HtmlComponent { .build() } } - Props::With(WithProps { props, .. }) => quote! { #props }, + Props::With(with_props) => { + let props = &with_props.props; + quote! { #props } + } Props::None => quote! { <<#ty as ::yew::html::Component>::Properties as ::yew::html::Properties>::builder() #set_children @@ -343,16 +346,16 @@ enum PropType { } enum Props { - List(ListProps), - With(WithProps), + List(Box), + With(Box), None, } impl Props { fn node_ref(&self) -> Option<&Expr> { match self { - Props::List(ListProps { node_ref, .. }) => node_ref.as_ref(), - Props::With(WithProps { node_ref, .. }) => node_ref.as_ref(), + Props::List(list_props) => list_props.node_ref.as_ref(), + Props::With(with_props) => with_props.node_ref.as_ref(), Props::None => None, } } @@ -374,8 +377,8 @@ impl PeekValue for Props { impl Parse for Props { fn parse(input: ParseStream) -> ParseResult { match Props::peek(input.cursor()) { - Some(PropType::List) => input.parse().map(Props::List), - Some(PropType::With) => input.parse().map(Props::With), + Some(PropType::List) => input.parse().map(|l| Props::List(Box::new(l))), + Some(PropType::With) => input.parse().map(|w| Props::With(Box::new(w))), None => Ok(Props::None), } } diff --git a/crates/macro/src/html_tree/html_node.rs b/crates/macro/src/html_tree/html_node.rs index f469092034b..e20d47f79f3 100644 --- a/crates/macro/src/html_tree/html_node.rs +++ b/crates/macro/src/html_tree/html_node.rs @@ -17,9 +17,9 @@ impl Parse for HtmlNode { Lit::Str(_) | Lit::Char(_) | Lit::Int(_) | Lit::Float(_) | Lit::Bool(_) => {} _ => return Err(syn::Error::new(lit.span(), "unsupported type")), } - Node::Literal(lit) + Node::Literal(Box::new(lit)) } else { - Node::Expression(input.parse()?) + Node::Expression(Box::new(input.parse()?)) }; Ok(HtmlNode(node)) @@ -56,6 +56,6 @@ impl ToTokens for Node { } enum Node { - Literal(Lit), - Expression(Expr), + Literal(Box), + Expression(Box), } diff --git a/crates/macro/src/html_tree/html_tag/tag_attributes.rs b/crates/macro/src/html_tree/html_tag/tag_attributes.rs index 61ae5581e17..3945bf2f790 100644 --- a/crates/macro/src/html_tree/html_tag/tag_attributes.rs +++ b/crates/macro/src/html_tree/html_tag/tag_attributes.rs @@ -20,7 +20,7 @@ pub struct TagAttributes { pub enum ClassesForm { Tuple(Vec), - Single(Expr), + Single(Box), } lazy_static! { @@ -146,7 +146,7 @@ impl TagAttributes { fn map_classes(class_expr: Expr) -> ClassesForm { match class_expr { Expr::Tuple(ExprTuple { elems, .. }) => ClassesForm::Tuple(elems.into_iter().collect()), - expr => ClassesForm::Single(expr), + expr => ClassesForm::Single(Box::new(expr)), } } } diff --git a/crates/macro/src/html_tree/mod.rs b/crates/macro/src/html_tree/mod.rs index 20102dd53a1..63a1782981a 100644 --- a/crates/macro/src/html_tree/mod.rs +++ b/crates/macro/src/html_tree/mod.rs @@ -31,12 +31,12 @@ pub enum HtmlType { } pub enum HtmlTree { - Block(HtmlBlock), - Component(HtmlComponent), - Iterable(HtmlIterable), - List(HtmlList), - Tag(HtmlTag), - Node(HtmlNode), + Block(Box), + Component(Box), + Iterable(Box), + List(Box), + Tag(Box), + Node(Box), Empty, } @@ -46,9 +46,9 @@ impl Parse for HtmlRoot { let html_root = if HtmlTree::peek(input.cursor()).is_some() { HtmlRoot(input.parse()?) } else if HtmlIterable::peek(input.cursor()).is_some() { - HtmlRoot(HtmlTree::Iterable(input.parse()?)) + HtmlRoot(HtmlTree::Iterable(Box::new(input.parse()?))) } else { - HtmlRoot(HtmlTree::Node(input.parse()?)) + HtmlRoot(HtmlTree::Node(Box::new(input.parse()?))) }; if !input.is_empty() { @@ -76,10 +76,10 @@ impl Parse for HtmlTree { .ok_or_else(|| input.error("expected valid html element"))?; let html_tree = match html_type { HtmlType::Empty => HtmlTree::Empty, - HtmlType::Component => HtmlTree::Component(input.parse()?), - HtmlType::Tag => HtmlTree::Tag(input.parse()?), - HtmlType::Block => HtmlTree::Block(input.parse()?), - HtmlType::List => HtmlTree::List(input.parse()?), + HtmlType::Component => HtmlTree::Component(Box::new(input.parse()?)), + HtmlType::Tag => HtmlTree::Tag(Box::new(input.parse()?)), + HtmlType::Block => HtmlTree::Block(Box::new(input.parse()?)), + HtmlType::List => HtmlTree::List(Box::new(input.parse()?)), }; Ok(html_tree) } diff --git a/examples/dashboard/src/lib.rs b/examples/dashboard/src/lib.rs index f7944eb379f..2927666885f 100644 --- a/examples/dashboard/src/lib.rs +++ b/examples/dashboard/src/lib.rs @@ -5,7 +5,6 @@ use serde_derive::{Deserialize, Serialize}; use yew::format::{Json, Nothing, Toml}; use yew::services::fetch::{FetchService, FetchTask, Request, Response}; use yew::services::websocket::{WebSocketService, WebSocketStatus, WebSocketTask}; -use yew::services::Task; use yew::{html, Component, ComponentLink, Html, ShouldRender}; type AsBinary = bool;