Skip to content

Commit

Permalink
vec[] to Vec::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-000 committed Feb 19, 2023
1 parent 150f3e8 commit fa49d1f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn fetch_pk_and_vk<P: AsRef<Path>>(
load_hex_data(proving_key_path)?
} else {
// We can return an empty Vec here as `prove_circuit` should only be false when running `nargo verify`
vec![]
Vec::new()
};

let verification_key = if check_proof {
Expand All @@ -227,7 +227,7 @@ fn fetch_pk_and_vk<P: AsRef<Path>>(
load_hex_data(verification_key_path)?
} else {
// We can return an empty Vec here as the verification key is used only is `check_proof` is true
vec![]
Vec::new()
};

Ok((proving_key, verification_key))
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Driver {
///
/// This is used for tests.
pub fn file_compiles(&mut self) -> bool {
let mut errs = vec![];
let mut errs = Vec::new();
CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errs);
reporter::report_all(&self.context.file_manager, &errs, false);
errs.is_empty()
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Driver {
/// Run the lexing, parsing, name resolution, and type checking passes,
/// returning Err(FrontendError) and printing any errors that were found.
pub fn check_crate(&mut self, allow_warnings: bool) -> Result<(), ReportedError> {
let mut errs = vec![];
let mut errs = Vec::new();
CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errs);
let error_count = reporter::report_all(&self.context.file_manager, &errs, allow_warnings);
reporter::finish_report(error_count)
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn convert_diagnostic(
})
.collect()
} else {
vec![]
Vec::new()
};

diagnostic.with_message(&cd.message).with_labels(secondary_labels).with_notes(cd.notes.clone())
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub fn range_constraint(
let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall {
name: acvm::acir::BlackBoxFunc::RANGE,
inputs: vec![FunctionInput { witness, num_bits }],
outputs: vec![],
outputs: Vec::new(),
});
evaluator.opcodes.push(gate);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl SsaContext {
}

let v_type = self.object_type(phi_root);
let operation = Operation::Phi { root: phi_root, block_args: vec![] };
let operation = Operation::Phi { root: phi_root, block_args: Vec::new() };
let new_phi = Instruction::new(operation, v_type, Some(target_block));
let phi_id = self.add_instruction(new_phi);
self[target_block].instructions.insert(1, phi_id);
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl IrGenerator {
let mut call_op = Operation::Call {
func,
arguments: arguments.clone(),
returned_arrays: vec![],
returned_arrays: Vec::new(),
predicate,
location,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn inline_block(
to_inline: Option<FuncId>,
decision: &DecisionTree,
) -> Result<bool, RuntimeError> {
let mut call_ins = vec![];
let mut call_ins = Vec::new();
for i in &ctx[block_id].instructions {
if let Some(ins) = ctx.try_get_instruction(*i) {
if !ins.is_deleted() {
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Recoverable for Ident {

impl<T> Recoverable for Vec<T> {
fn error(_: Span) -> Self {
vec![]
Vec::new()
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl DefCollector {
fn new(def_map: CrateDefMap) -> DefCollector {
DefCollector {
def_map,
collected_imports: vec![],
collected_functions: vec![],
collected_imports: Vec::new(),
collected_functions: Vec::new(),
collected_types: HashMap::new(),
collected_impls: HashMap::new(),
collected_globals: vec![],
collected_globals: Vec::new(),
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ fn type_check_globals(
all_errors: &mut Vec<FileDiagnostic>,
) {
for (file_id, stmt_id) in global_ids {
let mut errors = vec![];
let mut errors = Vec::new();
type_check(interner, &stmt_id, &mut errors);
extend_errors(all_errors, file_id, errors);
}
Expand Down Expand Up @@ -413,7 +413,7 @@ fn resolve_free_functions(
def_maps,
unresolved_functions,
self_type.clone(),
vec![], // no impl generics
Vec::new(), // no impl generics
errors,
)
})
Expand Down
8 changes: 4 additions & 4 deletions crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<'a> Resolver<'a> {

/// Translates an UnresolvedType to a Type
pub fn resolve_type(&mut self, typ: UnresolvedType) -> Type {
self.resolve_type_inner(typ, &mut vec![])
self.resolve_type_inner(typ, &mut Vec::new())
}

pub fn take_errors(self) -> Vec<ResolverError> {
Expand All @@ -484,7 +484,7 @@ impl<'a> Resolver<'a> {
fn resolve_inferred_type(&mut self, typ: UnresolvedType) -> Type {
match typ {
UnresolvedType::Unspecified => self.interner.next_type_variable(),
other => self.resolve_type_inner(other, &mut vec![]),
other => self.resolve_type_inner(other, &mut Vec::new()),
}
}

Expand Down Expand Up @@ -561,8 +561,8 @@ impl<'a> Resolver<'a> {
}
});

let mut parameters = vec![];
let mut parameter_types = vec![];
let mut parameters = Vec::new();
let mut parameter_types = Vec::new();

for (pattern, typ, visibility) in func.parameters().iter().cloned() {
if func.name() != "main" && visibility == noirc_abi::AbiVisibility::Public {
Expand Down
8 changes: 4 additions & 4 deletions crates/noirc_frontend/src/hir/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec<Type
let declared_return_type = meta.return_type().clone();
let can_ignore_ret = meta.can_ignore_return_type();

let mut errors = vec![];
let mut errors = Vec::new();
for param in meta.parameters.into_iter() {
bind_pattern(interner, &param.0, param.1, &mut errors);
}
Expand Down Expand Up @@ -250,7 +250,7 @@ mod test {

// Using assert_eq here instead of assert(errors.is_empty()) displays
// the whole vec if the assert fails rather than just two booleans
assert_eq!(errors, vec![]);
assert_eq!(errors, Vec::new());

let main_id = interner.push_fn(HirFunction::empty());
interner.push_function_definition("main".into(), main_id);
Expand All @@ -272,7 +272,7 @@ mod test {
let func_meta = vecmap(program.functions, |nf| {
let resolver = Resolver::new(&mut interner, &path_resolver, &def_maps, file);
let (hir_func, func_meta, resolver_errors) = resolver.resolve_function(nf, main_id);
assert_eq!(resolver_errors, vec![]);
assert_eq!(resolver_errors, Vec::new());
(hir_func, func_meta)
});

Expand All @@ -283,6 +283,6 @@ mod test {

// Type check section
let errors = super::type_check_func(&mut interner, func_ids.first().cloned().unwrap());
assert_eq!(errors, vec![]);
assert_eq!(errors, Vec::new());
}
}
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/hir_def/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum HirExpression {
impl HirExpression {
/// Returns an empty block expression
pub const fn empty_block() -> HirExpression {
HirExpression::Block(HirBlockExpression(vec![]))
HirExpression::Block(HirBlockExpression(Vec::new()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl<'a> Lexer<'a> {
}

pub fn lex(self) -> (Tokens, Vec<LexerErrorKind>) {
let mut tokens = vec![];
let mut errors = vec![];
let mut tokens = Vec::new();
let mut errors = Vec::new();
for result in self {
match result {
Ok(token) => tokens.push(token),
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn main() {
// This is preamble for analysis
// With a CrateDefMap, we are sure that the imports are correct, and the modules declared are located
// The modules are resolved and type checked!
let mut errors = vec![];
let mut errors = Vec::new();
CrateDefMap::collect_defs(crate_id, &mut context, &mut errors);
assert_eq!(errors, vec![]);
assert_eq!(errors, Vec::new());
let def_map = context.def_map(crate_id).unwrap();

// Get root module
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ impl Default for NodeInterner {
func_meta: HashMap::new(),
function_definition_ids: HashMap::new(),
id_to_location: HashMap::new(),
definitions: vec![],
definitions: Vec::new(),
id_to_type: HashMap::new(),
structs: HashMap::new(),
instantiation_bindings: HashMap::new(),
field_indices: HashMap::new(),
next_type_variable_id: 0,
globals: HashMap::new(),
language: Language::R1CS,
delayed_type_checks: vec![],
delayed_type_checks: Vec::new(),
struct_methods: HashMap::new(),
primitive_methods: HashMap::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl ForRange {
let end_range = ExpressionKind::MethodCall(Box::new(MethodCallExpression {
object: Expression::new(array_ident.clone(), array_span),
method_name: Ident::new("len".to_string(), array_span),
arguments: vec![],
arguments: Vec::new(),
}));
let end_range = Expression::new(end_range, array_span);

Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn struct_definition() -> impl NoirParser<TopLevelStatement> {
LeftBrace,
RightBrace,
[(LeftParen, RightParen), (LeftBracket, RightBracket)],
|_| vec![],
|_| Vec::new(),
),
);

Expand Down Expand Up @@ -218,7 +218,7 @@ fn self_parameter() -> impl NoirParser<(Pattern, UnresolvedType, AbiVisibility)>
Token::Ident(ref word) if word == "self" => {
let ident = Ident::from_token(found, span);
let path = Path::from_single("Self".to_owned(), span);
let self_type = UnresolvedType::Named(path, vec![]);
let self_type = UnresolvedType::Named(path, Vec::new());
Ok((Pattern::Identifier(ident), self_type, AbiVisibility::Private))
}
_ => Err(ParserError::expected_label("parameter".to_owned(), found, span)),
Expand Down

0 comments on commit fa49d1f

Please sign in to comment.