reformat the world

This commit is contained in:
Aleksey Kladov 2019-02-08 14:49:43 +03:00
parent 5cb1d41a30
commit 12e3b4c70b
129 changed files with 727 additions and 2509 deletions

View file

@ -121,9 +121,7 @@ impl BodySyntaxMapping {
}
pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> {
self.expr_syntax_mapping
.get(&SyntaxNodePtr::new(node.syntax()))
.cloned()
self.expr_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned()
}
pub fn pat_syntax(&self, pat: PatId) -> Option<SyntaxNodePtr> {
@ -135,9 +133,7 @@ impl BodySyntaxMapping {
}
pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> {
self.pat_syntax_mapping
.get(&SyntaxNodePtr::new(node.syntax()))
.cloned()
self.pat_syntax_mapping.get(&SyntaxNodePtr::new(node.syntax())).cloned()
}
pub fn body(&self) -> &Arc<Body> {
@ -262,11 +258,7 @@ pub struct StructLitField {
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Statement {
Let {
pat: PatId,
type_ref: Option<TypeRef>,
initializer: Option<ExprId>,
},
Let { pat: PatId, type_ref: Option<TypeRef>, initializer: Option<ExprId> },
Expr(ExprId),
}
@ -275,11 +267,7 @@ impl Expr {
match self {
Expr::Missing => {}
Expr::Path(_) => {}
Expr::If {
condition,
then_branch,
else_branch,
} => {
Expr::If { condition, then_branch, else_branch } => {
f(*condition);
f(*then_branch);
if let Some(else_branch) = else_branch {
@ -457,11 +445,7 @@ impl Pat {
args.iter().map(|pat| *pat).for_each(f);
}
Pat::Ref { pat, .. } => f(*pat),
Pat::Slice {
prefix,
rest,
suffix,
} => {
Pat::Slice { prefix, rest, suffix } => {
let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter());
total_iter.map(|pat| *pat).for_each(f);
}
@ -520,10 +504,7 @@ impl ExprCollector {
}
fn empty_block(&mut self) -> ExprId {
let block = Expr::Block {
statements: Vec::new(),
tail: None,
};
let block = Expr::Block { statements: Vec::new(), tail: None };
self.exprs.alloc(block)
}
@ -549,24 +530,10 @@ impl ExprCollector {
.unwrap_or_else(|| self.empty_block());
let placeholder_pat = self.pats.alloc(Pat::Missing);
let arms = vec![
MatchArm {
pats: vec![pat],
expr: then_branch,
guard: None,
},
MatchArm {
pats: vec![placeholder_pat],
expr: else_branch,
guard: None,
},
MatchArm { pats: vec![pat], expr: then_branch, guard: None },
MatchArm { pats: vec![placeholder_pat], expr: else_branch, guard: None },
];
self.alloc_expr(
Expr::Match {
expr: match_expr,
arms,
},
syntax_ptr,
)
self.alloc_expr(Expr::Match { expr: match_expr, arms }, syntax_ptr)
} else {
let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
let then_branch = self.collect_block_opt(e.then_branch());
@ -577,14 +544,7 @@ impl ExprCollector {
self.collect_expr(expr)
}
});
self.alloc_expr(
Expr::If {
condition,
then_branch,
else_branch,
},
syntax_ptr,
)
self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
}
}
ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()),
@ -610,14 +570,7 @@ impl ExprCollector {
let iterable = self.collect_expr_opt(e.iterable());
let pat = self.collect_pat_opt(e.pat());
let body = self.collect_block_opt(e.loop_body());
self.alloc_expr(
Expr::For {
iterable,
pat,
body,
},
syntax_ptr,
)
self.alloc_expr(Expr::For { iterable, pat, body }, syntax_ptr)
}
ast::ExprKind::CallExpr(e) => {
let callee = self.collect_expr_opt(e.expr());
@ -635,18 +588,8 @@ impl ExprCollector {
} else {
Vec::new()
};
let method_name = e
.name_ref()
.map(|nr| nr.as_name())
.unwrap_or_else(Name::missing);
self.alloc_expr(
Expr::MethodCall {
receiver,
method_name,
args,
},
syntax_ptr,
)
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
self.alloc_expr(Expr::MethodCall { receiver, method_name, args }, syntax_ptr)
}
ast::ExprKind::MatchExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
@ -668,11 +611,8 @@ impl ExprCollector {
self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr)
}
ast::ExprKind::PathExpr(e) => {
let path = e
.path()
.and_then(Path::from_ast)
.map(Expr::Path)
.unwrap_or(Expr::Missing);
let path =
e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing);
self.alloc_expr(path, syntax_ptr)
}
ast::ExprKind::ContinueExpr(_e) => {
@ -721,21 +661,11 @@ impl ExprCollector {
Vec::new()
};
let spread = e.spread().map(|s| self.collect_expr(s));
self.alloc_expr(
Expr::StructLit {
path,
fields,
spread,
},
syntax_ptr,
)
self.alloc_expr(Expr::StructLit { path, fields, spread }, syntax_ptr)
}
ast::ExprKind::FieldExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
let name = e
.name_ref()
.map(|nr| nr.as_name())
.unwrap_or_else(Name::missing);
let name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
}
ast::ExprKind::TryExpr(e) => {
@ -772,14 +702,7 @@ impl ExprCollector {
}
}
let body = self.collect_expr_opt(e.body());
self.alloc_expr(
Expr::Lambda {
args,
arg_types,
body,
},
syntax_ptr,
)
self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr)
}
ast::ExprKind::BinExpr(e) => {
let lhs = self.collect_expr_opt(e.lhs());
@ -804,9 +727,8 @@ impl ExprCollector {
let lit = match child.flavor() {
LiteralFlavor::IntNumber { suffix } => {
let known_name = suffix
.map(Name::new)
.and_then(|name| UncertainIntTy::from_name(&name));
let known_name =
suffix.map(Name::new).and_then(|name| UncertainIntTy::from_name(&name));
Literal::Int(
Default::default(),
@ -857,11 +779,7 @@ impl ExprCollector {
let pat = self.collect_pat_opt(stmt.pat());
let type_ref = stmt.type_ref().map(TypeRef::from_ast);
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
Statement::Let {
pat,
type_ref,
initializer,
}
Statement::Let { pat, type_ref, initializer }
}
ast::StmtKind::ExprStmt(stmt) => {
Statement::Expr(self.collect_expr_opt(stmt.expr()))
@ -869,10 +787,7 @@ impl ExprCollector {
})
.collect();
let tail = block.expr().map(|e| self.collect_expr(e));
self.alloc_expr(
Expr::Block { statements, tail },
SyntaxNodePtr::new(block.syntax()),
)
self.alloc_expr(Expr::Block { statements, tail }, SyntaxNodePtr::new(block.syntax()))
}
fn collect_block_opt(&mut self, block: Option<&ast::Block>) -> ExprId {
@ -886,17 +801,10 @@ impl ExprCollector {
fn collect_pat(&mut self, pat: &ast::Pat) -> PatId {
let pattern = match pat.kind() {
ast::PatKind::BindPat(bp) => {
let name = bp
.name()
.map(|nr| nr.as_name())
.unwrap_or_else(Name::missing);
let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref());
let subpat = bp.pat().map(|subpat| self.collect_pat(subpat));
Pat::Bind {
name,
mode: annotation,
subpat,
}
Pat::Bind { name, mode: annotation, subpat }
}
ast::PatKind::TupleStructPat(p) => {
let path = p.path().and_then(Path::from_ast);
@ -919,9 +827,8 @@ impl ExprCollector {
ast::PatKind::PlaceholderPat(_) => Pat::Wild,
ast::PatKind::StructPat(p) => {
let path = p.path().and_then(Path::from_ast);
let field_pat_list = p
.field_pat_list()
.expect("every struct should have a field list");
let field_pat_list =
p.field_pat_list().expect("every struct should have a field list");
let mut fields: Vec<_> = field_pat_list
.bind_pats()
.map(|bind_pat| {
@ -961,10 +868,7 @@ impl ExprCollector {
if let Some(param_list) = node.param_list() {
if let Some(self_param) = param_list.self_param() {
let self_param = SyntaxNodePtr::new(
self_param
.self_kw()
.expect("self param without self keyword")
.syntax(),
self_param.self_kw().expect("self param without self keyword").syntax(),
);
let param_pat = self.alloc_pat(
Pat::Bind {