From b291619d10a4e8869b724a85d965663bb43c83ee Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 19 Nov 2022 19:36:10 +0100 Subject: [PATCH] Remove unnecessary Clone bounds --- src/parser.rs | 1 - src/parser/basic.rs | 6 +++--- src/parser/expr.rs | 4 ++-- src/parser/lit.rs | 10 +++++----- src/parser/prefix.rs | 6 +++--- src/parser/suffix.rs | 22 +++++++++++----------- src/parser/table_constr.rs | 2 +- src/parser/table_destr.rs | 4 ++-- src/parser/var.rs | 10 +++++----- 9 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 6688a5b..7f4a722 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -6,7 +6,6 @@ //! made public later. // TODO Turn multiple calls to subparsers into clone-s -// TODO Remove unnecessary +Clone-s and 'static-s mod basic; mod expr; diff --git a/src/parser/basic.rs b/src/parser/basic.rs index cc0b41a..d40bc0e 100644 --- a/src/parser/basic.rs +++ b/src/parser/basic.rs @@ -10,17 +10,17 @@ pub type Error = Simple; // TODO https://github.com/rust-lang/rust/issues/63063 -fn inline() -> impl Parser + Clone { +fn inline() -> impl Parser { filter(|c: &char| c.is_whitespace() && *c != '\n') .repeated() .to(()) } -fn newline() -> impl Parser + Clone { +fn newline() -> impl Parser { just('\n').to(()) } -fn line() -> impl Parser + Clone { +fn line() -> impl Parser { let empty = newline().to(Line::Empty); let comment = just('#') diff --git a/src/parser/expr.rs b/src/parser/expr.rs index c307086..2636268 100644 --- a/src/parser/expr.rs +++ b/src/parser/expr.rs @@ -51,7 +51,7 @@ fn atom( } fn left_assoc( - op: impl Parser + Clone + 'static, + op: impl Parser + 'static, over: impl Parser + Clone + 'static, ) -> BoxedParser<'static, char, Expr, Error> { let op_over = space() @@ -73,7 +73,7 @@ fn left_assoc( } fn right_assoc( - op: impl Parser + Clone + 'static, + op: impl Parser + 'static, over: impl Parser + Clone + 'static, ) -> BoxedParser<'static, char, Expr, Error> { let over_op = over diff --git a/src/parser/lit.rs b/src/parser/lit.rs index 0c56991..8325a38 100644 --- a/src/parser/lit.rs +++ b/src/parser/lit.rs @@ -7,7 +7,7 @@ use crate::builtin::Builtin; use super::basic::{ident, space, Error}; -fn builtin_lit() -> impl Parser + Clone { +fn builtin_lit() -> impl Parser { just('\'').ignore_then(choice(( text::keyword("get").to(Builtin::Get), text::keyword("set").to(Builtin::Set), @@ -21,7 +21,7 @@ fn builtin_lit() -> impl Parser + Clone { ))) } -fn num_lit_str_radix(radix: u32) -> impl Parser + Clone { +fn num_lit_str_radix(radix: u32) -> impl Parser { // Minimum amount of digits required to represent i64::MAX. The rest of this // code assumes that any value that can be represented using this amount of // digits fits into an u64. @@ -71,14 +71,14 @@ fn num_lit_str_radix(radix: u32) -> impl Parser impl Parser + Clone { +fn num_lit() -> impl Parser { (just("0b").ignore_then(num_lit_str_radix(2))) .or(just("0x").ignore_then(num_lit_str_radix(16))) .or(num_lit_str_radix(10)) .map_with_span(|(value, str), span| NumLit { value, str, span }) } -fn string_lit() -> impl Parser + Clone { +fn string_lit() -> impl Parser { // TODO Parse string literals filter(|_| false).map(|_| unreachable!()) } @@ -108,7 +108,7 @@ pub fn table_lit_elem( fn table_lit( expr: impl Parser + Clone + 'static, -) -> impl Parser + Clone { +) -> impl Parser { let elem = space() .then(table_lit_elem(expr)) .then(space()) diff --git a/src/parser/prefix.rs b/src/parser/prefix.rs index b11428a..fadb81d 100644 --- a/src/parser/prefix.rs +++ b/src/parser/prefix.rs @@ -35,14 +35,14 @@ impl Prefix { } } -fn prefix_neg() -> impl Parser + Clone { +fn prefix_neg() -> impl Parser { just('-') .map_with_span(|_, span| span) .then(space()) .map(|(minus, s0)| Prefix::Neg { minus, s0 }) } -fn prefix_not() -> impl Parser + Clone { +fn prefix_not() -> impl Parser { text::keyword("not") .map_with_span(|_, span| span) .then(space()) @@ -50,7 +50,7 @@ fn prefix_not() -> impl Parser + Clone { } pub fn prefixed( - suffixed: impl Parser + Clone + 'static, + suffixed: impl Parser + 'static, ) -> BoxedParser<'static, char, Expr, Error> { let prefix = prefix_neg() .or(prefix_not()) diff --git a/src/parser/suffix.rs b/src/parser/suffix.rs index aea85b9..00436f3 100644 --- a/src/parser/suffix.rs +++ b/src/parser/suffix.rs @@ -131,8 +131,8 @@ impl Suffix { } fn suffix_call_arg( - expr: impl Parser + Clone, -) -> impl Parser + Clone { + expr: impl Parser, +) -> impl Parser { space() .then_ignore(just('(')) .then(space()) @@ -147,7 +147,7 @@ fn suffix_call_arg( }) } -fn suffix_call_no_arg() -> impl Parser + Clone { +fn suffix_call_no_arg() -> impl Parser { space() .then_ignore(just('(')) .then(space()) @@ -157,15 +157,15 @@ fn suffix_call_no_arg() -> impl Parser + Clone { fn suffix_call_constr( expr: impl Parser + Clone + 'static, -) -> impl Parser + Clone { +) -> impl Parser { space() .then(table_constr(expr)) .map(|(s0, constr)| Suffix::CallConstr { s0, constr }) } fn suffix_field_access( - expr: impl Parser + Clone, -) -> impl Parser + Clone { + expr: impl Parser, +) -> impl Parser { space() .then_ignore(just('[')) .then(space()) @@ -182,7 +182,7 @@ fn suffix_field_access( fn suffix_field_assign( expr: impl Parser + Clone, -) -> impl Parser + Clone { +) -> impl Parser { space() .then_ignore(just('[')) .then(space()) @@ -206,7 +206,7 @@ fn suffix_field_assign( ) } -fn suffix_field_access_ident() -> impl Parser + Clone { +fn suffix_field_access_ident() -> impl Parser { space() .then_ignore(just('.')) .then(space()) @@ -215,8 +215,8 @@ fn suffix_field_access_ident() -> impl Parser + Clo } fn suffix_field_assign_ident( - expr: impl Parser + Clone, -) -> impl Parser + Clone { + expr: impl Parser, +) -> impl Parser { space() .then_ignore(just('.')) .then(space()) @@ -238,7 +238,7 @@ fn suffix_field_assign_ident( } pub fn suffixed( - atom: impl Parser + Clone + 'static, + atom: impl Parser + 'static, expr: impl Parser + Clone + 'static, ) -> BoxedParser<'static, char, Expr, Error> { let call_arg = suffix_call_arg(expr.clone()); diff --git a/src/parser/table_constr.rs b/src/parser/table_constr.rs index 1ab6c71..25cf684 100644 --- a/src/parser/table_constr.rs +++ b/src/parser/table_constr.rs @@ -9,7 +9,7 @@ use super::lit::table_lit_elem; fn table_constr_elem( expr: impl Parser + Clone + 'static, -) -> impl Parser + Clone { +) -> impl Parser { let lit = table_lit_elem(expr.clone()).map(TableConstrElem::Lit); let indexed = just('[') diff --git a/src/parser/table_destr.rs b/src/parser/table_destr.rs index 538a6a9..eda0532 100644 --- a/src/parser/table_destr.rs +++ b/src/parser/table_destr.rs @@ -6,7 +6,7 @@ use crate::ast::{Expr, TableDestr, TablePattern, TablePatternElem}; use super::basic::{ident, space, Error}; -fn table_pattern_elem() -> impl Parser + Clone { +fn table_pattern_elem() -> impl Parser { let positional = ident().map(TablePatternElem::Positional); let named = ident() @@ -47,7 +47,7 @@ pub fn table_pattern() -> BoxedParser<'static, char, TablePattern, Error> { } pub fn table_destr( - expr: impl Parser + Clone + 'static, + expr: impl Parser + 'static, ) -> BoxedParser<'static, char, TableDestr, Error> { let local = text::keyword("local").ignore_then(space()).or_not(); diff --git a/src/parser/var.rs b/src/parser/var.rs index 1d1610f..9946d87 100644 --- a/src/parser/var.rs +++ b/src/parser/var.rs @@ -7,8 +7,8 @@ use crate::ast::{Expr, Var}; use super::basic::{ident, local, space, Error}; fn var_access( - expr: impl Parser + Clone, -) -> impl Parser + Clone { + expr: impl Parser, +) -> impl Parser { just('[') .ignore_then(space()) .then(expr) @@ -24,7 +24,7 @@ fn var_access( fn var_assign( expr: impl Parser + Clone, -) -> impl Parser + Clone { +) -> impl Parser { local() .then_ignore(just('[')) .then(space()) @@ -50,8 +50,8 @@ fn var_assign( } fn var_assign_ident( - expr: impl Parser + Clone, -) -> impl Parser + Clone { + expr: impl Parser, +) -> impl Parser { local() .then(ident()) .then(space())