Various small code review improvements

This commit is contained in:
Florian Diebold 2019-01-06 00:33:58 +01:00
parent 8e3e5ab2c8
commit e5a6cf8153
3 changed files with 27 additions and 26 deletions

View file

@ -1,3 +1,4 @@
use std::ops::Index;
use std::sync::Arc;
use rustc_hash::FxHashMap;
@ -44,14 +45,6 @@ pub struct BodySyntaxMapping {
}
impl Body {
pub fn expr(&self, expr: ExprId) -> &Expr {
&self.exprs[expr]
}
pub fn pat(&self, pat: PatId) -> &Pat {
&self.pats[pat]
}
pub fn args(&self) -> &[PatId] {
&self.args
}
@ -61,6 +54,22 @@ impl Body {
}
}
impl Index<ExprId> for Body {
type Output = Expr;
fn index(&self, expr: ExprId) -> &Expr {
&self.exprs[expr]
}
}
impl Index<PatId> for Body {
type Output = Pat;
fn index(&self, pat: PatId) -> &Pat {
&self.pats[pat]
}
}
impl BodySyntaxMapping {
pub fn expr_syntax(&self, expr: ExprId) -> Option<LocalSyntaxPtr> {
self.expr_syntax_mapping_back.get(&expr).cloned()
@ -377,11 +386,7 @@ impl ExprCollector {
syntax_ptr,
)
} else {
let condition = if let Some(condition) = e.condition() {
self.collect_expr_opt(condition.expr())
} else {
self.exprs.alloc(Expr::Missing)
};
let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
let then_branch = self.collect_block_opt(e.then_branch());
let else_branch = e.else_branch().map(|e| self.collect_block(e));
self.alloc_expr(