Fix cargo clippy lints

This commit is contained in:
CreepySkeleton 2020-08-31 09:51:21 +03:00
parent 7d16af9a06
commit 7b06af4369
3 changed files with 15 additions and 19 deletions

View file

@ -48,10 +48,10 @@ impl Generator {
} }
}, },
Markup::Literal { content, .. } => build.push_escaped(&content), Markup::Literal { content, .. } => build.push_escaped(&content),
Markup::Symbol { symbol } => self.name(symbol.into(), build), Markup::Symbol { symbol } => self.name(symbol, build),
Markup::Splice { expr, .. } => build.push_tokens(self.splice(expr.into())), Markup::Splice { expr, .. } => build.push_tokens(self.splice(expr)),
Markup::Element { name, attrs, body } => self.element(name.into(), attrs, body, build), Markup::Element { name, attrs, body } => self.element(name, attrs, body, build),
Markup::Let { tokens, .. } => build.push_tokens(tokens.into()), Markup::Let { tokens, .. } => build.push_tokens(tokens),
Markup::Special { segments } => { Markup::Special { segments } => {
for segment in segments { for segment in segments {
build.push_tokens(self.special(segment)); build.push_tokens(self.special(segment));
@ -65,7 +65,6 @@ impl Generator {
.collect(); .collect();
let mut body = TokenTree::Group(Group::new(Delimiter::Brace, body)); let mut body = TokenTree::Group(Group::new(Delimiter::Brace, body));
body.set_span(arms_span.collapse()); body.set_span(arms_span.collapse());
let head: TokenStream = head.into();
quote!(#head #body) quote!(#head #body)
}); });
}, },
@ -123,21 +122,21 @@ impl Generator {
match attr_type { match attr_type {
AttrType::Normal { value } => { AttrType::Normal { value } => {
build.push_str(" "); build.push_str(" ");
self.name(name.into(), build); self.name(name, build);
build.push_str("=\""); build.push_str("=\"");
self.markup(value, build); self.markup(value, build);
build.push_str("\""); build.push_str("\"");
}, },
AttrType::Empty { toggler: None } => { AttrType::Empty { toggler: None } => {
build.push_str(" "); build.push_str(" ");
self.name(name.into(), build); self.name(name, build);
}, },
AttrType::Empty { toggler: Some(toggler) } => { AttrType::Empty { toggler: Some(toggler) } => {
let head = desugar_toggler(toggler); let head = desugar_toggler(toggler);
build.push_tokens({ build.push_tokens({
let mut build = self.builder(); let mut build = self.builder();
build.push_str(" "); build.push_str(" ");
self.name(name.into(), &mut build); self.name(name, &mut build);
let body = build.finish(); let body = build.finish();
quote!(#head { #body }) quote!(#head { #body })
}) })
@ -148,13 +147,11 @@ impl Generator {
fn special(&self, Special { head, body, .. }: Special) -> TokenStream { fn special(&self, Special { head, body, .. }: Special) -> TokenStream {
let body = self.block(body); let body = self.block(body);
let head: TokenStream = head.into();
quote!(#head #body) quote!(#head #body)
} }
fn match_arm(&self, MatchArm { head, body }: MatchArm) -> TokenStream { fn match_arm(&self, MatchArm { head, body }: MatchArm) -> TokenStream {
let body = self.block(body); let body = self.block(body);
let head: TokenStream = head.into();
quote!(#head #body) quote!(#head #body)
} }
} }
@ -204,11 +201,11 @@ fn desugar_classes_or_ids(
}; };
let head = desugar_toggler(toggler); let head = desugar_toggler(toggler);
markups.push(Markup::Special { markups.push(Markup::Special {
segments: vec![Special { at_span: SpanRange::call_site(), head: head.into(), body }], segments: vec![Special { at_span: SpanRange::call_site(), head, body }],
}); });
} }
Some(Attribute { Some(Attribute {
name: TokenStream::from(TokenTree::Ident(Ident::new(attr_name, Span::call_site()))).into(), name: TokenStream::from(TokenTree::Ident(Ident::new(attr_name, Span::call_site()))),
attr_type: AttrType::Normal { attr_type: AttrType::Normal {
value: Markup::Block(Block { value: Markup::Block(Block {
markups, markups,
@ -231,8 +228,7 @@ fn prepend_leading_space(name: Markup, leading_space: &mut bool) -> Vec<Markup>
markups markups
} }
fn desugar_toggler(Toggler { cond, cond_span }: Toggler) -> TokenStream { fn desugar_toggler(Toggler { mut cond, cond_span }: Toggler) -> TokenStream {
let mut cond = TokenStream::from(cond);
// If the expression contains an opening brace `{`, // If the expression contains an opening brace `{`,
// wrap it in parentheses to avoid parse errors // wrap it in parentheses to avoid parse errors
if cond.clone().into_iter().any(is_braced_block) { if cond.clone().into_iter().any(is_braced_block) {

View file

@ -36,7 +36,7 @@ fn expand(input: TokenStream) -> TokenStream {
// Heuristic: the size of the resulting markup tends to correlate with the // Heuristic: the size of the resulting markup tends to correlate with the
// code size of the template itself // code size of the template itself
let size_hint = input.to_string().len(); let size_hint = input.to_string().len();
let markups = parse::parse(input.into()); let markups = parse::parse(input);
let stmts = generate::generate(markups, output_ident.clone()); let stmts = generate::generate(markups, output_ident.clone());
quote!({ quote!({
extern crate maud; extern crate maud;

View file

@ -86,7 +86,7 @@ impl Parser {
Some(( Some((
TokenTree::Punct(ref punct), TokenTree::Punct(ref punct),
Some(TokenTree::Ident(ref ident)), Some(TokenTree::Ident(ref ident)),
)) if punct.as_char() == '@' && ident.to_string() == "let" => { )) if punct.as_char() == '@' && *ident == "let" => {
self.advance2(); self.advance2();
let keyword = TokenTree::Ident(ident.clone()); let keyword = TokenTree::Ident(ident.clone());
result.push(self.let_expr(punct.span(), keyword)); result.push(self.let_expr(punct.span(), keyword));
@ -234,13 +234,13 @@ impl Parser {
Some(( Some((
TokenTree::Punct(ref punct), TokenTree::Punct(ref punct),
Some(TokenTree::Ident(ref else_keyword)), Some(TokenTree::Ident(ref else_keyword)),
)) if punct.as_char() == '@' && else_keyword.to_string() == "else" => { )) if punct.as_char() == '@' && *else_keyword == "else" => {
self.advance2(); self.advance2();
let at_span = punct.span(); let at_span = punct.span();
let else_keyword = TokenTree::Ident(else_keyword.clone()); let else_keyword = TokenTree::Ident(else_keyword.clone());
match self.peek() { match self.peek() {
// `@else if` // `@else if`
Some(TokenTree::Ident(ref if_keyword)) if if_keyword.to_string() == "if" => { Some(TokenTree::Ident(ref if_keyword)) if *if_keyword == "if" => {
self.advance(); self.advance();
let if_keyword = TokenTree::Ident(if_keyword.clone()); let if_keyword = TokenTree::Ident(if_keyword.clone());
self.if_expr(at_span, vec![else_keyword, if_keyword], segments) self.if_expr(at_span, vec![else_keyword, if_keyword], segments)
@ -300,7 +300,7 @@ impl Parser {
let mut head = vec![keyword]; let mut head = vec![keyword];
loop { loop {
match self.next() { match self.next() {
Some(TokenTree::Ident(ref in_keyword)) if in_keyword.to_string() == "in" => { Some(TokenTree::Ident(ref in_keyword)) if *in_keyword == "in" => {
head.push(TokenTree::Ident(in_keyword.clone())); head.push(TokenTree::Ident(in_keyword.clone()));
break; break;
}, },