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

comby-rust #2065

Merged
merged 4 commits into from
Jun 21, 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
15 changes: 7 additions & 8 deletions sway-core/src/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2704,10 +2704,10 @@ fn asm_register_declaration_to_asm_register_declaration(
) -> Result<AsmRegisterDeclaration, ErrorEmitted> {
Ok(AsmRegisterDeclaration {
name: asm_register_declaration.register,
initializer: match asm_register_declaration.value_opt {
None => None,
Some((_colon_token, expr)) => Some(expr_to_expression(ec, *expr)?),
},
initializer: asm_register_declaration
.value_opt
.map(|(_colon_token, expr)| expr_to_expression(ec, *expr))
.transpose()?,
})
}

Expand Down Expand Up @@ -2877,10 +2877,9 @@ fn pattern_struct_field_to_struct_scrutinee_field(
} => {
let struct_scrutinee_field = StructScrutineeField::Field {
field: field_name,
scrutinee: match pattern_opt {
Some((_colon_token, pattern)) => Some(pattern_to_scrutinee(ec, *pattern)?),
None => None,
},
scrutinee: pattern_opt
.map(|(_colon_token, pattern)| pattern_to_scrutinee(ec, *pattern))
.transpose()?,
span,
};
Ok(struct_scrutinee_field)
Expand Down
7 changes: 3 additions & 4 deletions sway-ir/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ impl<'a> InstructionVerifier<'a> {

fn verify_bitcast(&self, value: &Value, ty: &Type) -> Result<(), IrError> {
// The to and from types must be copy-types, excluding short strings, and the same size.
let val_ty = match value.get_type(self.context) {
None => return Err(IrError::VerifyBitcastUnknownSourceType),
Some(ty) => ty,
};
let val_ty = value
.get_type(self.context)
.ok_or(IrError::VerifyBitcastUnknownSourceType)?;
if !val_ty.is_copy_type() {
return Err(IrError::VerifyBitcastFromNonCopyType(
val_ty.as_string(self.context),
Expand Down
15 changes: 7 additions & 8 deletions sway-parse/src/expr/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ impl ParseToEnd for AsmBlockContents {
impl Parse for AsmImmediate {
fn parse(parser: &mut Parser) -> ParseResult<AsmImmediate> {
let ident = parser.parse::<Ident>()?;
let digits = match ident.as_str().strip_prefix('i') {
Some(digits) => digits,
None => return Err(parser.emit_error(ParseErrorKind::MalformedAsmImmediate)),
};
let parsed = match BigUint::from_str(digits).ok() {
Some(parsed) => parsed,
None => return Err(parser.emit_error(ParseErrorKind::MalformedAsmImmediate)),
};
let digits = ident
.as_str()
.strip_prefix('i')
.ok_or_else(|| parser.emit_error(ParseErrorKind::MalformedAsmImmediate))?;
let parsed = BigUint::from_str(digits)
.ok()
.ok_or_else(|| parser.emit_error(ParseErrorKind::MalformedAsmImmediate))?;
Ok(AsmImmediate {
span: ident.span(),
parsed,
Expand Down
7 changes: 3 additions & 4 deletions sway-parse/src/item/item_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ impl Parse for UseTree {
if let Some(star_token) = parser.take() {
return Ok(UseTree::Glob { star_token });
}
let name = match parser.take() {
Some(name) => name,
None => return Err(parser.emit_error(ParseErrorKind::ExpectedImportNameGroupOrGlob)),
};
let name = parser
.take()
.ok_or_else(|| parser.emit_error(ParseErrorKind::ExpectedImportNameGroupOrGlob))?;
if let Some(as_token) = parser.take() {
let alias = parser.parse()?;
return Ok(UseTree::Rename {
Expand Down
7 changes: 3 additions & 4 deletions sway-parse/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ impl Peek for Literal {

impl Parse for Literal {
fn parse(parser: &mut Parser) -> ParseResult<Literal> {
match parser.take() {
Some(literal) => Ok(literal),
None => Err(parser.emit_error(ParseErrorKind::ExpectedLiteral)),
}
parser
.take()
.ok_or_else(|| parser.emit_error(ParseErrorKind::ExpectedLiteral))
}
}

Expand Down