Skip to content

Commit

Permalink
BE: Bring in a type alias for Guards in HIR
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: robertoaloi

Differential Revision: D61590977

fbshipit-source-id: 8200c34f203da5e6af28da656e969e93822ab885
  • Loading branch information
alanz authored and facebook-github-bot committed Aug 21, 2024
1 parent b1c2397 commit 623b635
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/hir/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use super::InFileAstPtr;
use super::TopLevelMacro;
use crate::db::DefDatabase;
use crate::def_map::FunctionDefId;
use crate::expr::Guards;
use crate::expr::MaybeExpr;
use crate::expr::StringVariant;
use crate::known;
Expand Down Expand Up @@ -1617,7 +1618,7 @@ impl<'a> Ctx<'a> {
}
}

fn lower_guards(&mut self, guards: Option<ast::Guard>) -> Vec<Vec<ExprId>> {
fn lower_guards(&mut self, guards: Option<ast::Guard>) -> Guards {
guards
.iter()
.flat_map(|guard| guard.clauses())
Expand Down
3 changes: 2 additions & 1 deletion crates/hir/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::str;

use super::SpecOrCallback;
use crate::db::InternDatabase;
use crate::expr::Guards;
use crate::expr::MaybeExpr;
use crate::expr::StringVariant;
use crate::AnyAttribute;
Expand Down Expand Up @@ -304,7 +305,7 @@ impl<'a> Printer<'a> {
}
}

fn print_guards(&mut self, guards: &[Vec<ExprId>], when_nested: bool) -> fmt::Result {
fn print_guards(&mut self, guards: &Guards, when_nested: bool) -> fmt::Result {
if !guards.is_empty() {
if when_nested {
self.indent_level += 1;
Expand Down
3 changes: 2 additions & 1 deletion crates/hir/src/body/tree_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::fmt::Write as _;
use std::str;

use crate::db::InternDatabase;
use crate::expr::Guards;
use crate::expr::MaybeExpr;
use crate::AnyAttribute;
use crate::AttributeBody;
Expand Down Expand Up @@ -1015,7 +1016,7 @@ impl<'a> Printer<'a> {
});
}

fn print_guards(&mut self, guards: &[Vec<ExprId>]) {
fn print_guards(&mut self, guards: &Guards) {
if !guards.is_empty() {
for guard_clause in guards {
self.print_labelled("guard", false, &mut |this| {
Expand Down
10 changes: 6 additions & 4 deletions crates/hir/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,25 @@ impl AstClauseId {
}
}

pub type Guards = Vec<Vec<ExprId>>;

#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Clause {
pub pats: Vec<PatId>,
pub guards: Vec<Vec<ExprId>>,
pub guards: Guards,
pub exprs: Vec<ExprId>,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CRClause {
pub pat: PatId,
pub guards: Vec<Vec<ExprId>>,
pub guards: Guards,
pub exprs: Vec<ExprId>,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct IfClause {
pub guards: Vec<Vec<ExprId>>,
pub guards: Guards,
pub exprs: Vec<ExprId>,
}

Expand All @@ -404,7 +406,7 @@ pub struct CatchClause {
pub class: Option<PatId>,
pub reason: PatId,
pub stack: Option<PatId>,
pub guards: Vec<Vec<ExprId>>,
pub guards: Guards,
pub exprs: Vec<ExprId>,
}

Expand Down

0 comments on commit 623b635

Please sign in to comment.