clippy lints 2

This commit is contained in:
collin 2020-11-10 16:34:44 -08:00
parent 33fae17b35
commit f28eb8c20a
6 changed files with 21 additions and 36 deletions

View File

@ -214,7 +214,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
})?; })?;
// Run type inference check on program. // Run type inference check on program.
TypeInference::run(&self.program, symbol_table).map_err(|mut e| { TypeInference::new(&self.program, symbol_table).map_err(|mut e| {
e.set_path(&self.main_file_path); e.set_path(&self.main_file_path);
e e
@ -256,7 +256,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
let symbol_table = SymbolTable::new(&self.program, &self.imported_programs, &self.program_input)?; let symbol_table = SymbolTable::new(&self.program, &self.imported_programs, &self.program_input)?;
// Run type inference check on program. // Run type inference check on program.
TypeInference::run(&self.program, symbol_table)?; TypeInference::new(&self.program, symbol_table)?;
tracing::debug!("Program parsing complete\n{:#?}", self.program); tracing::debug!("Program parsing complete\n{:#?}", self.program);

View File

@ -88,13 +88,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
Declare::Let => false, Declare::Let => false,
Declare::Const => true, Declare::Const => true,
}; };
let expression = self.enforce_expression( let expression =
cs, self.enforce_expression(cs, file_scope, function_scope, variables.type_.clone(), expression)?;
file_scope.clone(),
function_scope.clone(),
variables.type_.clone(),
expression,
)?;
if num_variables == 1 { if num_variables == 1 {
// Define a single variable with a single value // Define a single variable with a single value

View File

@ -273,37 +273,25 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
// Data type wrappers // Data type wrappers
ConstrainedValue::Array(array) => { ConstrainedValue::Array(array) => {
array array.iter_mut().enumerate().try_for_each(|(i, value)| {
.iter_mut() let unique_name = format!("allocate array member {} {}:{}", i, span.line, span.start);
.enumerate()
.map(|(i, value)| {
let unique_name = format!("allocate array member {} {}:{}", i, span.line, span.start);
value.allocate_value(cs.ns(|| unique_name), span) value.allocate_value(cs.ns(|| unique_name), span)
}) })?;
.collect::<Result<(), ValueError>>()?;
} }
ConstrainedValue::Tuple(tuple) => { ConstrainedValue::Tuple(tuple) => {
tuple tuple.iter_mut().enumerate().try_for_each(|(i, value)| {
.iter_mut() let unique_name = format!("allocate tuple member {} {}:{}", i, span.line, span.start);
.enumerate()
.map(|(i, value)| {
let unique_name = format!("allocate tuple member {} {}:{}", i, span.line, span.start);
value.allocate_value(cs.ns(|| unique_name), span) value.allocate_value(cs.ns(|| unique_name), span)
}) })?;
.collect::<Result<(), ValueError>>()?;
} }
ConstrainedValue::CircuitExpression(_id, members) => { ConstrainedValue::CircuitExpression(_id, members) => {
members members.iter_mut().enumerate().try_for_each(|(i, member)| {
.iter_mut() let unique_name = format!("allocate circuit member {} {}:{}", i, span.line, span.start);
.enumerate()
.map(|(i, member)| {
let unique_name = format!("allocate circuit member {} {}:{}", i, span.line, span.start);
member.1.allocate_value(cs.ns(|| unique_name), span) member.1.allocate_value(cs.ns(|| unique_name), span)
}) })?;
.collect::<Result<(), ValueError>>()?;
} }
ConstrainedValue::Mutable(value) => { ConstrainedValue::Mutable(value) => {
value.allocate_value(cs, span)?; value.allocate_value(cs, span)?;

View File

@ -29,6 +29,7 @@ pub trait CLI {
const OPTIONS: &'static [OptionType]; const OPTIONS: &'static [OptionType];
const SUBCOMMANDS: &'static [SubCommandType]; const SUBCOMMANDS: &'static [SubCommandType];
#[allow(clippy::new_ret_no_self)]
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn new<'a, 'b>() -> App<'a, 'b> { fn new<'a, 'b>() -> App<'a, 'b> {
let arguments = &Self::ARGUMENTS let arguments = &Self::ARGUMENTS

View File

@ -34,7 +34,8 @@ impl TypeInference {
/// ///
/// Evaluates all `TypeAssertion` predicates. /// Evaluates all `TypeAssertion` predicates.
/// ///
pub fn run(program: &Program, symbol_table: SymbolTable) -> Result<(), TypeInferenceError> { #[allow(clippy::new_ret_no_self)]
pub fn new(program: &Program, symbol_table: SymbolTable) -> Result<(), TypeInferenceError> {
let mut type_inference = Self { let mut type_inference = Self {
table: symbol_table, table: symbol_table,
frames: Vec::new(), frames: Vec::new(),

View File

@ -66,11 +66,11 @@ impl TestTypeInference {
} }
pub fn check(self) { pub fn check(self) {
TypeInference::run(&self.program, self.symbol_table).unwrap(); TypeInference::new(&self.program, self.symbol_table).unwrap();
} }
pub fn expect_error(self) { pub fn expect_error(self) {
assert!(TypeInference::run(&self.program, self.symbol_table).is_err()); assert!(TypeInference::new(&self.program, self.symbol_table).is_err());
} }
} }