Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all clippy warnings and errors #555

Merged
merged 4 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion derive/tests/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
#![allow(unknown_lints, clippy)]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::{format, vec::Vec};
Expand Down
1 change: 0 additions & 1 deletion generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use pest_meta::ast::*;
use pest_meta::optimizer::*;
use pest_meta::UNICODE_PROPERTY_NAMES;

#[allow(clippy::needless_pass_by_value)]
pub fn generate(
name: Ident,
generics: &Generics,
Expand Down
1 change: 0 additions & 1 deletion generator/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

macro_rules! insert_builtin {
($builtin: expr, $name: ident, $pattern: expr) => {
#[allow(clippy::vec_init_then_push)]
$builtin.push((stringify!($name), generate_rule!($name, $pattern)));
};
}
Expand Down
4 changes: 1 addition & 3 deletions meta/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ fn main() {
})
.wait()
.unwrap();
if !status.success() {
panic!("Bootstrap failed");
}
assert!(status.success(), "Bootstrap failed");
} else {
println!(" Fresh `meta/src/grammar.rs`");
}
Expand Down
2 changes: 1 addition & 1 deletion meta/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod tests {
Box::new(Expr::Str(String::from("a"))),
Box::new(Expr::Str(String::from("b"))),
);
let mut top_down = expr.clone().iter_top_down();
let mut top_down = expr.iter_top_down();
assert_eq!(top_down.next(), Some(expr));
assert_eq!(top_down.next(), Some(Expr::Str(String::from("a"))));
assert_eq!(top_down.next(), Some(Expr::Str(String::from("b"))));
Expand Down
2 changes: 0 additions & 2 deletions meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

#![allow(clippy::range_plus_one)]

#[cfg(test)]
#[macro_use]
extern crate pest;
Expand Down
6 changes: 2 additions & 4 deletions meta/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use crate::ast::{Expr, Rule as AstRule, RuleType};
use crate::validator;

mod grammar {
#![allow(unknown_lints, clippy::all)]

include!("grammar.rs");
}

Expand Down Expand Up @@ -1228,7 +1226,7 @@ mod tests {

let pairs = PestParser::parse(Rule::grammar_rules, input).unwrap();
let ast = consume_rules_with_spans(pairs).unwrap();
let ast: Vec<_> = ast.into_iter().map(|rule| convert_rule(rule)).collect();
let ast: Vec<_> = ast.into_iter().map(convert_rule).collect();

assert_eq!(
ast,
Expand Down Expand Up @@ -1266,7 +1264,7 @@ mod tests {

let pairs = PestParser::parse(Rule::grammar_rules, input).unwrap();
let ast = consume_rules_with_spans(pairs).unwrap();
let ast: Vec<_> = ast.into_iter().map(|rule| convert_rule(rule)).collect();
let ast: Vec<_> = ast.into_iter().map(convert_rule).collect();

assert_eq!(
ast,
Expand Down
10 changes: 4 additions & 6 deletions meta/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use pest::Span;
use crate::parser::{ParserExpr, ParserNode, ParserRule, Rule};
use crate::UNICODE_PROPERTY_NAMES;

#[allow(clippy::needless_pass_by_value)]
pub fn validate_pairs(pairs: Pairs<Rule>) -> Result<Vec<&str>, Vec<Error<Rule>>> {
let mut rust_keywords = HashSet::new();
rust_keywords.insert("abstract");
Expand Down Expand Up @@ -142,7 +141,7 @@ pub fn validate_pairs(pairs: Pairs<Rule>) -> Result<Vec<&str>, Vec<Error<Rule>>>
Ok(defaults.cloned().collect())
}

#[allow(clippy::implicit_hasher, clippy::ptr_arg)]
#[allow(clippy::ptr_arg)]
pub fn validate_rust_keywords<'i>(
definitions: &Vec<Span<'i>>,
rust_keywords: &HashSet<&str>,
Expand All @@ -165,7 +164,7 @@ pub fn validate_rust_keywords<'i>(
errors
}

#[allow(clippy::implicit_hasher, clippy::ptr_arg)]
#[allow(clippy::ptr_arg)]
pub fn validate_pest_keywords<'i>(
definitions: &Vec<Span<'i>>,
pest_keywords: &HashSet<&str>,
Expand Down Expand Up @@ -211,7 +210,7 @@ pub fn validate_already_defined(definitions: &Vec<Span>) -> Vec<Error<Rule>> {
errors
}

#[allow(clippy::implicit_hasher, clippy::ptr_arg)]
#[allow(clippy::ptr_arg)]
pub fn validate_undefined<'i>(
definitions: &Vec<Span<'i>>,
called_rules: &Vec<Span<'i>>,
Expand Down Expand Up @@ -449,7 +448,6 @@ fn to_hash_map<'a, 'i: 'a>(rules: &'a [ParserRule<'i>]) -> HashMap<String, &'a P
rules.iter().map(|r| (r.name.clone(), &r.node)).collect()
}

#[allow(clippy::needless_pass_by_value)]
fn left_recursion<'a, 'i: 'a>(rules: HashMap<String, &'a ParserNode<'i>>) -> Vec<Error<Rule>> {
fn check_expr<'a, 'i: 'a>(
node: &'a ParserNode<'i>,
Expand Down Expand Up @@ -514,7 +512,7 @@ fn left_recursion<'a, 'i: 'a>(rules: HashMap<String, &'a ParserNode<'i>>) -> Vec
let mut errors = vec![];

for (name, node) in &rules {
let name = (*name).clone();
let name = name.clone();

if let Some(error) = check_expr(node, &rules, &mut vec![name]) {
errors.push(error);
Expand Down
4 changes: 2 additions & 2 deletions pest/examples/parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct ParenParser;
impl Parser<Rule> for ParenParser {
fn parse(rule: Rule, input: &str) -> Result<Pairs<Rule>, Error<Rule>> {
fn expr(state: Box<ParserState<Rule>>) -> ParseResult<Box<ParserState<Rule>>> {
state.sequence(|s| s.repeat(|s| paren(s)).and_then(|s| s.end_of_input()))
state.sequence(|s| s.repeat(paren).and_then(|s| s.end_of_input()))
}

fn paren(state: Box<ParserState<Rule>>) -> ParseResult<Box<ParserState<Rule>>> {
Expand All @@ -30,7 +30,7 @@ impl Parser<Rule> for ParenParser {
s.optional(|s| {
s.sequence(|s| {
s.lookahead(true, |s| s.match_string("("))
.and_then(|s| s.repeat(|s| paren(s)))
.and_then(|s| s.repeat(paren))
})
})
})
Expand Down
2 changes: 0 additions & 2 deletions pest/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ impl<R: RuleType> Error<R> {
///
/// println!("{}", error);
/// ```
#[allow(clippy::needless_pass_by_value)]
pub fn new_from_pos(variant: ErrorVariant<R>, pos: Position) -> Error<R> {
let visualize_ws = pos.match_char('\n') || pos.match_char('\r');
let line_of = pos.line_of();
Expand Down Expand Up @@ -150,7 +149,6 @@ impl<R: RuleType> Error<R> {
///
/// println!("{}", error);
/// ```
#[allow(clippy::needless_pass_by_value)]
pub fn new_from_span(variant: ErrorVariant<R>, span: Span) -> Error<R> {
let end = span.end_pos();
let mut end_line_col = end.line_col();
Expand Down
67 changes: 34 additions & 33 deletions pest/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ macro_rules! consumes_to {
$rules::$name, $start);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::Start { rule, pos } => {
if rule != $rules::$name || pos.pos() != $start {
panic!("{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(
rule == $rules::$name && pos.pos() == $start,
"{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
)
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -28,10 +29,10 @@ macro_rules! consumes_to {
$rules::$name, $end);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::End { rule, pos } => {
if rule != $rules::$name || pos.pos() != $end {
panic!("{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $end,
"{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -43,10 +44,10 @@ macro_rules! consumes_to {
$rules::$name, $start);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::Start { rule, pos } => {
if rule != $rules::$name || pos.pos() != $start {
panic!("{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $start,
"{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -55,10 +56,10 @@ macro_rules! consumes_to {
$rules::$name, $end);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::End { rule, pos } => {
if rule != $rules::$name || pos.pos() != $end {
panic!("{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $end,
"{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -71,10 +72,10 @@ macro_rules! consumes_to {
$rules::$name, $start);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::Start { rule, pos } => {
if rule != $rules::$name || pos.pos() != $start {
panic!("{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $start,
"{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -85,10 +86,10 @@ macro_rules! consumes_to {
$rules::$name, $end);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::End { rule, pos } => {
if rule != $rules::$name || pos.pos() != $end {
panic!("{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $end,
"{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -102,10 +103,10 @@ macro_rules! consumes_to {
$rules::$name, $start);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::Start { rule, pos } => {
if rule != $rules::$name || pos.pos() != $start {
panic!("{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $start,
"{} but found Start {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand All @@ -116,10 +117,10 @@ macro_rules! consumes_to {
$rules::$name, $end);
match $tokens.next().expect(&format!("{} but found nothing", expected)) {
$crate::Token::End { rule, pos } => {
if rule != $rules::$name || pos.pos() != $end {
panic!("{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos());
}
assert!(rule == $rules::$name && pos.pos() == $end,
"{} but found End {{ rule: {:?}, pos: Position {{ {} }} }}",
expected, rule, pos.pos(),
);
},
token => panic!("{} but found {:?}", expected, token)
};
Expand Down Expand Up @@ -333,7 +334,7 @@ pub mod tests {
pub struct AbcParser;

impl Parser<Rule> for AbcParser {
fn parse<'i>(_: Rule, input: &'i str) -> Result<Pairs<'i, Rule>, Error<Rule>> {
fn parse(_: Rule, input: &str) -> Result<Pairs<Rule>, Error<Rule>> {
state(input, |state| {
state
.rule(Rule::a, |s| {
Expand Down
1 change: 0 additions & 1 deletion pest/src/parser_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ impl<'i, R: RuleType> ParserState<'i, R> {
/// let input = "";
/// let state: Box<pest::ParserState<&str>> = pest::ParserState::new(input);
/// ```
#[allow(clippy::new_ret_no_self)]
pub fn new(input: &'i str) -> Box<Self> {
Box::new(ParserState {
position: Position::from_start(input),
Expand Down
Loading