mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Various small code review improvements
This commit is contained in:
parent
8e3e5ab2c8
commit
e5a6cf8153
3 changed files with 27 additions and 26 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue