mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-01 22:36:52 +03:00
clippy vec_init_then_push more
This commit is contained in:
parent
0addc80080
commit
b5f80c925c
@ -353,7 +353,7 @@ impl ParserContext {
|
||||
/// Otherwise, tries to parse the next token using [`parse_access_expression`].
|
||||
///
|
||||
pub fn parse_unary_expression(&mut self) -> SyntaxResult<Expression> {
|
||||
let mut ops = vec![];
|
||||
let mut ops = Vec::new();
|
||||
while let Some(token) = self.eat_any(&[Token::Not, Token::Minus, Token::BitNot]) {
|
||||
ops.push(token);
|
||||
}
|
||||
@ -455,7 +455,7 @@ impl ParserContext {
|
||||
}
|
||||
}
|
||||
Token::LeftParen => {
|
||||
let mut arguments = vec![];
|
||||
let mut arguments = Vec::new();
|
||||
let end_span;
|
||||
loop {
|
||||
let end = self.eat(Token::RightParen);
|
||||
@ -509,7 +509,7 @@ impl ParserContext {
|
||||
///
|
||||
pub fn parse_circuit_init(&mut self, identifier: Identifier) -> SyntaxResult<Expression> {
|
||||
self.expect(Token::LeftCurly)?;
|
||||
let mut members = vec![];
|
||||
let mut members = Vec::new();
|
||||
let end_span;
|
||||
loop {
|
||||
if let Some(end) = self.eat(Token::RightCurly) {
|
||||
@ -603,7 +603,7 @@ impl ParserContext {
|
||||
},
|
||||
)))));
|
||||
}
|
||||
let mut args = vec![];
|
||||
let mut args = Vec::new();
|
||||
let end_span;
|
||||
loop {
|
||||
let end = self.eat(Token::RightParen);
|
||||
@ -630,7 +630,7 @@ impl ParserContext {
|
||||
Token::LeftSquare => {
|
||||
if let Some(end) = self.eat(Token::RightSquare) {
|
||||
return Ok(Expression::ArrayInline(ArrayInlineExpression {
|
||||
elements: vec![],
|
||||
elements: Vec::new(),
|
||||
span: span + end.span,
|
||||
}));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ impl ParserContext {
|
||||
/// Returns a [`Program`] AST if all tokens can be consumed and represent a valid Leo program.
|
||||
///
|
||||
pub fn parse_program(&mut self) -> SyntaxResult<Program> {
|
||||
let mut imports = vec![];
|
||||
let mut imports = Vec::new();
|
||||
let mut circuits = IndexMap::new();
|
||||
let mut functions = IndexMap::new();
|
||||
// let mut tests = IndexMap::new();
|
||||
@ -70,7 +70,7 @@ impl ParserContext {
|
||||
}
|
||||
Ok(Program {
|
||||
name: String::new(),
|
||||
expected_input: vec![],
|
||||
expected_input: Vec::new(),
|
||||
imports,
|
||||
circuits,
|
||||
functions,
|
||||
@ -90,7 +90,7 @@ impl ParserContext {
|
||||
}
|
||||
let end_span;
|
||||
let arguments = if self.eat(Token::LeftParen).is_some() {
|
||||
let mut args = vec![];
|
||||
let mut args = Vec::new();
|
||||
loop {
|
||||
if let Some(end) = self.eat(Token::RightParen) {
|
||||
end_span = end.span;
|
||||
@ -112,7 +112,7 @@ impl ParserContext {
|
||||
args
|
||||
} else {
|
||||
end_span = name.span.clone();
|
||||
vec![]
|
||||
Vec::new()
|
||||
};
|
||||
Ok(Annotation {
|
||||
name,
|
||||
@ -126,7 +126,7 @@ impl ParserContext {
|
||||
/// expressions within an import statement.
|
||||
///
|
||||
pub fn parse_package_accesses(&mut self) -> SyntaxResult<Vec<PackageAccess>> {
|
||||
let mut out = vec![];
|
||||
let mut out = Vec::new();
|
||||
self.expect(Token::LeftParen)?;
|
||||
while self.eat(Token::RightParen).is_none() {
|
||||
let access = self.parse_package_access()?;
|
||||
@ -293,7 +293,7 @@ impl ParserContext {
|
||||
self.expect(Token::Circuit)?;
|
||||
let name = self.expect_ident()?;
|
||||
self.expect(Token::LeftCurly)?;
|
||||
let mut members = vec![];
|
||||
let mut members = Vec::new();
|
||||
while self.eat(Token::RightCurly).is_none() {
|
||||
let member = self.parse_circuit_member()?;
|
||||
members.push(member);
|
||||
@ -353,14 +353,14 @@ impl ParserContext {
|
||||
/// and function definition.
|
||||
///
|
||||
pub fn parse_function(&mut self) -> SyntaxResult<(Identifier, Function)> {
|
||||
let mut annotations = vec![];
|
||||
let mut annotations = Vec::new();
|
||||
while self.peek()?.token == Token::At {
|
||||
annotations.push(self.parse_annotation()?);
|
||||
}
|
||||
let start = self.expect(Token::Function)?;
|
||||
let name = self.expect_ident()?;
|
||||
self.expect(Token::LeftParen)?;
|
||||
let mut inputs = vec![];
|
||||
let mut inputs = Vec::new();
|
||||
while self.eat(Token::RightParen).is_none() {
|
||||
let input = self.parse_function_input()?;
|
||||
inputs.push(input);
|
||||
|
@ -72,7 +72,7 @@ impl ParserContext {
|
||||
///
|
||||
pub fn construct_assignee(expr: Expression) -> SyntaxResult<Assignee> {
|
||||
let expr_span = expr.span().clone();
|
||||
let mut accesses = vec![];
|
||||
let mut accesses = Vec::new();
|
||||
let identifier = Self::construct_assignee_access(expr, &mut accesses)?;
|
||||
|
||||
Ok(Assignee {
|
||||
@ -140,7 +140,6 @@ impl ParserContext {
|
||||
pub fn parse_block(&mut self) -> SyntaxResult<Block> {
|
||||
let start = self.expect(Token::LeftCurly)?;
|
||||
|
||||
#[allow(clippy::vec_init_then_push)]
|
||||
let mut statements = Vec::new();
|
||||
loop {
|
||||
match self.eat(Token::RightCurly) {
|
||||
@ -232,7 +231,7 @@ impl ParserContext {
|
||||
}
|
||||
SpannedToken { token, span } => return Err(SyntaxError::unexpected_str(&token, "formatted string", &span)),
|
||||
};
|
||||
let mut parameters = vec![];
|
||||
let mut parameters = Vec::new();
|
||||
while self.eat(Token::Comma).is_some() {
|
||||
let param = self.parse_expression()?;
|
||||
parameters.push(param);
|
||||
@ -306,7 +305,7 @@ impl ParserContext {
|
||||
///
|
||||
pub fn parse_definition_statement(&mut self) -> SyntaxResult<DefinitionStatement> {
|
||||
let declare = self.expect_oneof(&[Token::Let, Token::Const])?;
|
||||
let mut variable_names = vec![];
|
||||
let mut variable_names = Vec::new();
|
||||
if self.eat(Token::LeftParen).is_some() {
|
||||
variable_names.push(self.parse_variable_name()?);
|
||||
while self.eat(Token::Comma).is_some() {
|
||||
|
@ -61,7 +61,7 @@ impl ParserContext {
|
||||
ArrayDimensions(vec![int])
|
||||
} else {
|
||||
self.expect(Token::LeftParen)?;
|
||||
let mut dimensions = vec![];
|
||||
let mut dimensions = Vec::new();
|
||||
loop {
|
||||
if let Some((int, _)) = self.eat_int() {
|
||||
dimensions.push(int);
|
||||
@ -89,7 +89,7 @@ impl ParserContext {
|
||||
let span = ident.span.clone();
|
||||
(Type::Circuit(ident), span)
|
||||
} else if let Some(token) = self.eat(Token::LeftParen) {
|
||||
let mut types = vec![];
|
||||
let mut types = Vec::new();
|
||||
let end_span;
|
||||
loop {
|
||||
if let Some(end) = self.eat(Token::RightParen) {
|
||||
|
@ -43,8 +43,8 @@ pub fn find_tests<T: AsRef<Path>>(path: T, out: &mut Vec<(String, String)>) {
|
||||
#[test]
|
||||
pub fn parser_pass_tests() {
|
||||
let mut pass = 0;
|
||||
let mut fail = vec![];
|
||||
let mut tests = vec![];
|
||||
let mut fail = Vec::new();
|
||||
let mut tests = Vec::new();
|
||||
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
test_dir.push("../tests/pass/parse/");
|
||||
find_tests(&test_dir, &mut tests);
|
||||
@ -76,8 +76,8 @@ pub fn parser_pass_tests() {
|
||||
#[test]
|
||||
pub fn parser_fail_tests() {
|
||||
let mut pass = 0;
|
||||
let mut fail = vec![];
|
||||
let mut tests = vec![];
|
||||
let mut fail = Vec::new();
|
||||
let mut tests = Vec::new();
|
||||
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
test_dir.push("../tests/fail/parse/");
|
||||
find_tests(&test_dir, &mut tests);
|
||||
|
@ -106,7 +106,7 @@ impl Token {
|
||||
let mut i = 1;
|
||||
let mut in_escape = false;
|
||||
let mut start = 1usize;
|
||||
let mut segments = vec![];
|
||||
let mut segments = Vec::new();
|
||||
while i < input.len() {
|
||||
if !in_escape {
|
||||
if input[i] == b'"' {
|
||||
|
@ -34,7 +34,7 @@ use std::rc::Rc;
|
||||
pub(crate) fn tokenize(path: &str, source: &str) -> Result<Vec<SpannedToken>, TokenError> {
|
||||
let path = Rc::new(path.to_string());
|
||||
let mut input = source.as_bytes();
|
||||
let mut tokens = vec![];
|
||||
let mut tokens = Vec::new();
|
||||
let mut index = 0usize;
|
||||
let mut line_no = 1usize;
|
||||
let mut line_start = 0usize;
|
||||
|
Loading…
Reference in New Issue
Block a user