Skip to content

Commit

Permalink
feat: support old Rust versions
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Jan 18, 2023
1 parent a212519 commit 1b4217c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
4 changes: 3 additions & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ impl Lowerer {
) -> Result<Vec<CId>> {
let mut r = Vec::with_capacity(exprs.len());
for expr in exprs {
let pl::ExprKind::All { except, .. } = expr.kind else {
let except = if let pl::ExprKind::All { except, .. } = expr.kind {
except
} else {
// base case
r.push(self.declare_as_column(expr, is_aggregation)?);
continue;
Expand Down
12 changes: 10 additions & 2 deletions prql-compiler/src/semantic/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,16 @@ pub fn cast_transform(resolver: &mut Resolver, closure: Closure) -> Result<Resul

let [csv_expr] = unpack::<1>(closure);

let ExprKind::Literal(Literal::String(csv)) = csv_expr.kind else {
return Err(Error::new(Reason::Expected { who: Some("std.from_csv".to_string()), expected: "a string literal".to_string(), found: format!("`{csv_expr}`") }).with_span(csv_expr.span).into())
let csv = if let ExprKind::Literal(Literal::String(csv)) = csv_expr.kind {
csv
} else {
return Err(Error::new(Reason::Expected {
who: Some("std.from_csv".to_string()),
expected: "a string literal".to_string(),
found: format!("`{}`", csv_expr),
})
.with_span(csv_expr.span)
.into());
};

let res = parse_csv(&csv)?;
Expand Down
4 changes: 3 additions & 1 deletion prql-compiler/src/sql/gen_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ fn try_into_between(
if !matches!(op, BinOp::And) {
return Ok(None);
}
let Some((a, b)) = a.kind.as_binary().zip(b.kind.as_binary()) else {
let (a, b) = if let Some((a, b)) = a.kind.as_binary().zip(b.kind.as_binary()) {
(a, b)
} else {
return Ok(None);
};
if !(matches!(a.1, BinOp::Gte) && matches!(b.1, BinOp::Lte)) {
Expand Down
24 changes: 17 additions & 7 deletions prql-compiler/src/sql/gen_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ pub(super) fn try_into_exprs(
.map(|cid| {
let decl = ctx.anchor.column_decls.get(&cid).unwrap();

let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl else {
let tiid = if let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl {
tiid
} else {
// base case
return translate_cid(cid, ctx)
return translate_cid(cid, ctx);
};

// wildcard
Expand Down Expand Up @@ -69,7 +71,11 @@ pub(super) fn translate_wildcards(ctx: &AnchorContext, cols: Vec<CId>) -> (Vec<C
// requested.
// This function adds that column to the exclusion list.
fn exclude(star: &mut Option<(CId, HashSet<CId>)>, excluded: &mut Excluded) {
let Some((cid, in_star)) = star.take() else { return };
let (cid, in_star) = if let Some((cid, in_star)) = star.take() {
(cid, in_star)
} else {
return;
};
if in_star.is_empty() {
return;
}
Expand Down Expand Up @@ -125,9 +131,11 @@ pub(super) fn translate_select_items(
.map(|cid| {
let decl = ctx.anchor.column_decls.get(&cid).unwrap();

let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl else {
// general case
return translate_select_item(cid, ctx)
let tiid = if let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl {
tiid
} else {
// base case
return translate_select_item(cid, ctx);
};

// wildcard case
Expand Down Expand Up @@ -158,7 +166,9 @@ fn translate_exclude(
) -> Option<WildcardAdditionalOptions> {
let excluded = as_col_names(&excluded, &ctx.anchor);

let Some(supported) = ctx.dialect.column_exclude() else {
let supported = if let Some(supported) = ctx.dialect.column_exclude() {
supported
} else {
// TODO: eventually this should throw an error
// I don't want to do this now, because we have no way around it.
// We could also ask the user to add table definitions.
Expand Down
4 changes: 3 additions & 1 deletion prql-compiler/src/sql/gen_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ fn sql_union_of_pipeline(
let append = pipeline.pluck(|t| t.into_append()).into_iter().next();
let unique = pipeline.iter().any(|t| matches!(t, Transform::Unique));

let Some(bottom) = append else {
let bottom = if let Some(bottom) = append {
bottom
} else {
return Ok(top);
};

Expand Down

0 comments on commit 1b4217c

Please sign in to comment.