diff --git a/prql-compiler/src/sql/gen_expr.rs b/prql-compiler/src/sql/gen_expr.rs index ab55a572cc18..4467d6250ba6 100644 --- a/prql-compiler/src/sql/gen_expr.rs +++ b/prql-compiler/src/sql/gen_expr.rs @@ -130,7 +130,9 @@ fn try_into_binary_op(expr: Expr, ctx: &mut Context) -> Result Result; 2] = [STD_NEG, STD_NOT]; const OPS: [UnaryOperator; 2] = [Minus, Not]; - let Some((decl, _)) = try_unpack(&expr, DECLS)? else { + let decl = if let Some((decl, _)) = try_unpack(&expr, DECLS)? { + decl + } else { return Ok(Err(expr)); }; + // this lookup is O(N), but 13 is not that big of a N let decl_index = DECLS.iter().position(|x| x == &decl).unwrap(); let op = OPS[decl_index]; @@ -191,7 +196,7 @@ fn try_into_concat_function(expr: Expr, ctx: &mut Context) -> Result Result, Expr>> { - let Some((_, _)) = try_unpack(&expr, [STD_CONCAT])? else { + let () = if let Some((_, _)) = try_unpack(&expr, [STD_CONCAT])? { return Ok(Err(expr)); }; let [left, right] = unpack(expr, STD_CONCAT); @@ -531,8 +536,10 @@ pub(super) fn translate_select_item(cid: CId, ctx: &mut Context) -> Result Result> { - let Some((decl, [a, b])) = try_unpack(&expr, [STD_EQ, STD_NE])? else { - return Ok(Err(expr)) + let (decl, a, b) = if let Some((decl, [a, b])) = try_unpack(&expr, [STD_EQ, STD_NE])? { + (decl, a, b) + } else { + return Ok(Err(expr)); }; let take_a = if matches!(a.kind, ExprKind::Literal(Literal::Null)) { diff --git a/prql-compiler/src/sql/preprocess.rs b/prql-compiler/src/sql/preprocess.rs index 4651716e01e2..966436ead4ed 100644 --- a/prql-compiler/src/sql/preprocess.rs +++ b/prql-compiler/src/sql/preprocess.rs @@ -538,7 +538,9 @@ impl RqFold for Normalizer { ..expr }; - let Some((decl, _)) = super::std::try_unpack(&expr, [super::std::STD_EQ])? else { + let decl = if let Some((decl, _)) = super::std::try_unpack(&expr, [super::std::STD_EQ])? { + decl + } else { return Ok(expr); }; let name = decl.name.to_string();