Merge pull request #586 from huitseeker/warts

[easy] Simplifies a number of pattern-matches
This commit is contained in:
Collin Chin 2021-02-26 15:41:47 -08:00 committed by GitHub
commit dece42a4e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 40 deletions

View File

@ -71,10 +71,7 @@ impl<'a, R: ExpressionVisitor<'a>> VisitorDirector<'a, R> {
} }
fn visit_opt_expression(&mut self, input: &Cell<Option<&'a Expression<'a>>>) -> ConcreteVisitResult { fn visit_opt_expression(&mut self, input: &Cell<Option<&'a Expression<'a>>>) -> ConcreteVisitResult {
let interior = match input.get() { let interior = input.get().map(Cell::new);
Some(expr) => Some(Cell::new(expr)),
None => None,
};
if let Some(interior) = interior.as_ref() { if let Some(interior) = interior.as_ref() {
let result = self.visit_expression(interior); let result = self.visit_expression(interior);
input.replace(Some(interior.get())); input.replace(Some(interior.get()));
@ -246,10 +243,7 @@ impl<'a, R: StatementVisitor<'a>> VisitorDirector<'a, R> {
} }
fn visit_opt_statement(&mut self, input: &Cell<Option<&'a Statement<'a>>>) -> ConcreteVisitResult { fn visit_opt_statement(&mut self, input: &Cell<Option<&'a Statement<'a>>>) -> ConcreteVisitResult {
let interior = match input.get() { let interior = input.get().map(Cell::new);
Some(expr) => Some(Cell::new(expr)),
None => None,
};
if let Some(interior) = interior.as_ref() { if let Some(interior) = interior.as_ref() {
let result = self.visit_statement(interior); let result = self.visit_statement(interior);
input.replace(Some(interior.get())); input.replace(Some(interior.get()));

View File

@ -34,11 +34,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
arguments: &[Cell<&'a Expression<'a>>], arguments: &[Cell<&'a Expression<'a>>],
span: &Span, span: &Span,
) -> Result<ConstrainedValue<'a, F, G>, ExpressionError> { ) -> Result<ConstrainedValue<'a, F, G>, ExpressionError> {
let target_value = if let Some(target) = target { let target_value = target.map(|target| self.enforce_expression(cs, target)).transpose()?;
Some(self.enforce_expression(cs, target)?)
} else {
None
};
// Get the value of each core function argument // Get the value of each core function argument
let arguments = arguments let arguments = arguments

View File

@ -34,11 +34,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
target: Option<&'a Expression<'a>>, target: Option<&'a Expression<'a>>,
arguments: &[Cell<&'a Expression<'a>>], arguments: &[Cell<&'a Expression<'a>>],
) -> Result<ConstrainedValue<'a, F, G>, FunctionError> { ) -> Result<ConstrainedValue<'a, F, G>, FunctionError> {
let target_value = if let Some(target) = target { let target_value = target.map(|target| self.enforce_expression(cs, target)).transpose()?;
Some(self.enforce_expression(cs, target)?)
} else {
None
};
let self_var = if let Some(target) = &target_value { let self_var = if let Some(target) = &target_value {
let self_var = function let self_var = function

View File

@ -96,10 +96,7 @@ impl Command for Add {
return Err(anyhow!("Package manifest not found, try running `leo init`")); return Err(anyhow!("Package manifest not found, try running `leo init`"));
}; };
let (author, package_name) = match self.try_read_arguments() { let (author, package_name) = self.try_read_arguments()?;
Ok((author, package)) => (author, package),
Err(err) => return Err(err),
};
// Attempt to fetch the package. // Attempt to fetch the package.
let reader = { let reader = {

View File

@ -105,10 +105,7 @@ impl Command for Clone {
} }
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> { fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
let (author, package_name) = match self.try_read_arguments() { let (author, package_name) = self.try_read_arguments()?;
Ok((author, package)) => (author, package),
Err(err) => return Err(err),
};
// Attempt to fetch the package. // Attempt to fetch the package.
let reader = { let reader = {

View File

@ -93,10 +93,10 @@ impl Command for Publish {
// Client for make POST request // Client for make POST request
let client = Client::new(); let client = Client::new();
let token = match context.api.auth_token() { let token = context
Some(token) => token, .api
None => return Err(anyhow!("Login before publishing package: try leo login --help")), .auth_token()
}; .ok_or_else(|| anyhow!("Login before publishing package: try leo login --help"))?;
// Headers for request to publish package // Headers for request to publish package
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();

View File

@ -49,10 +49,7 @@ impl Context {
/// Create a new context for the current directory. /// Create a new context for the current directory.
pub fn create_context(path: PathBuf) -> Result<Context> { pub fn create_context(path: PathBuf) -> Result<Context> {
let token = match config::read_token() { let token = config::read_token().ok();
Ok(token) => Some(token),
Err(_) => None,
};
let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token); let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token);
@ -61,10 +58,7 @@ pub fn create_context(path: PathBuf) -> Result<Context> {
/// Returns project context. /// Returns project context.
pub fn get_context() -> Result<Context> { pub fn get_context() -> Result<Context> {
let token = match config::read_token() { let token = config::read_token().ok();
Ok(token) => Some(token),
Err(_) => None,
};
let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token); let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token);

View File

@ -174,11 +174,11 @@ impl TryFrom<SerializedCircuit> for CircuitSynthesizer<Bls12_377> {
} }
Ok(CircuitSynthesizer::<Bls12_377> { Ok(CircuitSynthesizer::<Bls12_377> {
input_assignment,
aux_assignment,
at, at,
bt, bt,
ct, ct,
input_assignment,
aux_assignment,
}) })
} }
} }