mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
remove ast::*Kind from hir
This commit is contained in:
parent
39e444d701
commit
b50a04827c
6 changed files with 86 additions and 83 deletions
|
@ -602,8 +602,8 @@ where
|
||||||
|
|
||||||
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
|
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
|
||||||
let syntax_ptr = SyntaxNodePtr::new(expr.syntax());
|
let syntax_ptr = SyntaxNodePtr::new(expr.syntax());
|
||||||
match expr.kind() {
|
match expr {
|
||||||
ast::ExprKind::IfExpr(e) => {
|
ast::Expr::IfExpr(e) => {
|
||||||
let then_branch = self.collect_block_opt(e.then_branch());
|
let then_branch = self.collect_block_opt(e.then_branch());
|
||||||
|
|
||||||
let else_branch = e.else_branch().map(|b| match b {
|
let else_branch = e.else_branch().map(|b| match b {
|
||||||
|
@ -639,16 +639,16 @@ where
|
||||||
|
|
||||||
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::TryBlockExpr(e) => {
|
ast::Expr::TryBlockExpr(e) => {
|
||||||
let body = self.collect_block_opt(e.try_body());
|
let body = self.collect_block_opt(e.try_body());
|
||||||
self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
|
self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()),
|
ast::Expr::BlockExpr(e) => self.collect_block_opt(e.block()),
|
||||||
ast::ExprKind::LoopExpr(e) => {
|
ast::Expr::LoopExpr(e) => {
|
||||||
let body = self.collect_block_opt(e.loop_body());
|
let body = self.collect_block_opt(e.loop_body());
|
||||||
self.alloc_expr(Expr::Loop { body }, syntax_ptr)
|
self.alloc_expr(Expr::Loop { body }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::WhileExpr(e) => {
|
ast::Expr::WhileExpr(e) => {
|
||||||
let body = self.collect_block_opt(e.loop_body());
|
let body = self.collect_block_opt(e.loop_body());
|
||||||
|
|
||||||
let condition = match e.condition() {
|
let condition = match e.condition() {
|
||||||
|
@ -675,13 +675,13 @@ where
|
||||||
|
|
||||||
self.alloc_expr(Expr::While { condition, body }, syntax_ptr)
|
self.alloc_expr(Expr::While { condition, body }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::ForExpr(e) => {
|
ast::Expr::ForExpr(e) => {
|
||||||
let iterable = self.collect_expr_opt(e.iterable());
|
let iterable = self.collect_expr_opt(e.iterable());
|
||||||
let pat = self.collect_pat_opt(e.pat());
|
let pat = self.collect_pat_opt(e.pat());
|
||||||
let body = self.collect_block_opt(e.loop_body());
|
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) => {
|
ast::Expr::CallExpr(e) => {
|
||||||
let callee = self.collect_expr_opt(e.expr());
|
let callee = self.collect_expr_opt(e.expr());
|
||||||
let args = if let Some(arg_list) = e.arg_list() {
|
let args = if let Some(arg_list) = e.arg_list() {
|
||||||
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
||||||
|
@ -690,7 +690,7 @@ where
|
||||||
};
|
};
|
||||||
self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
|
self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::MethodCallExpr(e) => {
|
ast::Expr::MethodCallExpr(e) => {
|
||||||
let receiver = self.collect_expr_opt(e.expr());
|
let receiver = self.collect_expr_opt(e.expr());
|
||||||
let args = if let Some(arg_list) = e.arg_list() {
|
let args = if let Some(arg_list) = e.arg_list() {
|
||||||
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
arg_list.args().map(|e| self.collect_expr(e)).collect()
|
||||||
|
@ -704,7 +704,7 @@ where
|
||||||
syntax_ptr,
|
syntax_ptr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ast::ExprKind::MatchExpr(e) => {
|
ast::Expr::MatchExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
let arms = if let Some(match_arm_list) = e.match_arm_list() {
|
let arms = if let Some(match_arm_list) = e.match_arm_list() {
|
||||||
match_arm_list
|
match_arm_list
|
||||||
|
@ -723,30 +723,30 @@ where
|
||||||
};
|
};
|
||||||
self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr)
|
self.alloc_expr(Expr::Match { expr, arms }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::PathExpr(e) => {
|
ast::Expr::PathExpr(e) => {
|
||||||
let path =
|
let path =
|
||||||
e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing);
|
e.path().and_then(Path::from_ast).map(Expr::Path).unwrap_or(Expr::Missing);
|
||||||
self.alloc_expr(path, syntax_ptr)
|
self.alloc_expr(path, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::ContinueExpr(_e) => {
|
ast::Expr::ContinueExpr(_e) => {
|
||||||
// FIXME: labels
|
// FIXME: labels
|
||||||
self.alloc_expr(Expr::Continue, syntax_ptr)
|
self.alloc_expr(Expr::Continue, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::BreakExpr(e) => {
|
ast::Expr::BreakExpr(e) => {
|
||||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||||
self.alloc_expr(Expr::Break { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Break { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::ParenExpr(e) => {
|
ast::Expr::ParenExpr(e) => {
|
||||||
let inner = self.collect_expr_opt(e.expr());
|
let inner = self.collect_expr_opt(e.expr());
|
||||||
// make the paren expr point to the inner expression as well
|
// make the paren expr point to the inner expression as well
|
||||||
self.source_map.expr_map.insert(syntax_ptr, inner);
|
self.source_map.expr_map.insert(syntax_ptr, inner);
|
||||||
inner
|
inner
|
||||||
}
|
}
|
||||||
ast::ExprKind::ReturnExpr(e) => {
|
ast::Expr::ReturnExpr(e) => {
|
||||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||||
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::StructLit(e) => {
|
ast::Expr::StructLit(e) => {
|
||||||
let path = e.path().and_then(Path::from_ast);
|
let path = e.path().and_then(Path::from_ast);
|
||||||
let mut field_ptrs = Vec::new();
|
let mut field_ptrs = Vec::new();
|
||||||
let struct_lit = if let Some(nfl) = e.named_field_list() {
|
let struct_lit = if let Some(nfl) = e.named_field_list() {
|
||||||
|
@ -787,7 +787,7 @@ where
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
ast::ExprKind::FieldExpr(e) => {
|
ast::Expr::FieldExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
let name = match e.field_access() {
|
let name = match e.field_access() {
|
||||||
Some(kind) => kind.as_name(),
|
Some(kind) => kind.as_name(),
|
||||||
|
@ -795,25 +795,25 @@ where
|
||||||
};
|
};
|
||||||
self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
|
self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::AwaitExpr(e) => {
|
ast::Expr::AwaitExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
self.alloc_expr(Expr::Await { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Await { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::TryExpr(e) => {
|
ast::Expr::TryExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
self.alloc_expr(Expr::Try { expr }, syntax_ptr)
|
self.alloc_expr(Expr::Try { expr }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::CastExpr(e) => {
|
ast::Expr::CastExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
let type_ref = TypeRef::from_ast_opt(e.type_ref());
|
let type_ref = TypeRef::from_ast_opt(e.type_ref());
|
||||||
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
|
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::RefExpr(e) => {
|
ast::Expr::RefExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
let mutability = Mutability::from_mutable(e.is_mut());
|
let mutability = Mutability::from_mutable(e.is_mut());
|
||||||
self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr)
|
self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::PrefixExpr(e) => {
|
ast::Expr::PrefixExpr(e) => {
|
||||||
let expr = self.collect_expr_opt(e.expr());
|
let expr = self.collect_expr_opt(e.expr());
|
||||||
if let Some(op) = e.op_kind() {
|
if let Some(op) = e.op_kind() {
|
||||||
self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr)
|
self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr)
|
||||||
|
@ -821,7 +821,7 @@ where
|
||||||
self.alloc_expr(Expr::Missing, syntax_ptr)
|
self.alloc_expr(Expr::Missing, syntax_ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ExprKind::LambdaExpr(e) => {
|
ast::Expr::LambdaExpr(e) => {
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
let mut arg_types = Vec::new();
|
let mut arg_types = Vec::new();
|
||||||
if let Some(pl) = e.param_list() {
|
if let Some(pl) = e.param_list() {
|
||||||
|
@ -835,18 +835,18 @@ where
|
||||||
let body = self.collect_expr_opt(e.body());
|
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) => {
|
ast::Expr::BinExpr(e) => {
|
||||||
let lhs = self.collect_expr_opt(e.lhs());
|
let lhs = self.collect_expr_opt(e.lhs());
|
||||||
let rhs = self.collect_expr_opt(e.rhs());
|
let rhs = self.collect_expr_opt(e.rhs());
|
||||||
let op = e.op_kind().map(BinaryOp::from);
|
let op = e.op_kind().map(BinaryOp::from);
|
||||||
self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
|
self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::TupleExpr(e) => {
|
ast::Expr::TupleExpr(e) => {
|
||||||
let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
|
let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
|
||||||
self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
|
self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::ExprKind::ArrayExpr(e) => {
|
ast::Expr::ArrayExpr(e) => {
|
||||||
let kind = e.kind();
|
let kind = e.kind();
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
|
@ -865,7 +865,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::ExprKind::Literal(e) => {
|
ast::Expr::Literal(e) => {
|
||||||
let lit = match e.kind() {
|
let lit = match e.kind() {
|
||||||
LiteralKind::IntNumber { suffix } => {
|
LiteralKind::IntNumber { suffix } => {
|
||||||
let known_name = suffix
|
let known_name = suffix
|
||||||
|
@ -895,16 +895,16 @@ where
|
||||||
};
|
};
|
||||||
self.alloc_expr(Expr::Literal(lit), syntax_ptr)
|
self.alloc_expr(Expr::Literal(lit), syntax_ptr)
|
||||||
}
|
}
|
||||||
ast::ExprKind::IndexExpr(e) => {
|
ast::Expr::IndexExpr(e) => {
|
||||||
let base = self.collect_expr_opt(e.base());
|
let base = self.collect_expr_opt(e.base());
|
||||||
let index = self.collect_expr_opt(e.index());
|
let index = self.collect_expr_opt(e.index());
|
||||||
self.alloc_expr(Expr::Index { base, index }, syntax_ptr)
|
self.alloc_expr(Expr::Index { base, index }, syntax_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME implement HIR for these:
|
// FIXME implement HIR for these:
|
||||||
ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
|
ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
|
||||||
ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
|
ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
|
||||||
ast::ExprKind::MacroCall(e) => {
|
ast::Expr::MacroCall(e) => {
|
||||||
let ast_id = self
|
let ast_id = self
|
||||||
.db
|
.db
|
||||||
.ast_id_map(self.current_file_id)
|
.ast_id_map(self.current_file_id)
|
||||||
|
@ -945,16 +945,14 @@ where
|
||||||
fn collect_block(&mut self, block: ast::Block) -> ExprId {
|
fn collect_block(&mut self, block: ast::Block) -> ExprId {
|
||||||
let statements = block
|
let statements = block
|
||||||
.statements()
|
.statements()
|
||||||
.map(|s| match s.kind() {
|
.map(|s| match s {
|
||||||
ast::StmtKind::LetStmt(stmt) => {
|
ast::Stmt::LetStmt(stmt) => {
|
||||||
let pat = self.collect_pat_opt(stmt.pat());
|
let pat = self.collect_pat_opt(stmt.pat());
|
||||||
let type_ref = stmt.ascribed_type().map(TypeRef::from_ast);
|
let type_ref = stmt.ascribed_type().map(TypeRef::from_ast);
|
||||||
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
|
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) => {
|
ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())),
|
||||||
Statement::Expr(self.collect_expr_opt(stmt.expr()))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let tail = block.expr().map(|e| self.collect_expr(e));
|
let tail = block.expr().map(|e| self.collect_expr(e));
|
||||||
|
@ -970,33 +968,33 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
|
fn collect_pat(&mut self, pat: ast::Pat) -> PatId {
|
||||||
let pattern = match pat.kind() {
|
let pattern = match &pat {
|
||||||
ast::PatKind::BindPat(bp) => {
|
ast::Pat::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 annotation = BindingAnnotation::new(bp.is_mutable(), bp.is_ref());
|
||||||
let subpat = bp.pat().map(|subpat| self.collect_pat(subpat));
|
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) => {
|
ast::Pat::TupleStructPat(p) => {
|
||||||
let path = p.path().and_then(Path::from_ast);
|
let path = p.path().and_then(Path::from_ast);
|
||||||
let args = p.args().map(|p| self.collect_pat(p)).collect();
|
let args = p.args().map(|p| self.collect_pat(p)).collect();
|
||||||
Pat::TupleStruct { path, args }
|
Pat::TupleStruct { path, args }
|
||||||
}
|
}
|
||||||
ast::PatKind::RefPat(p) => {
|
ast::Pat::RefPat(p) => {
|
||||||
let pat = self.collect_pat_opt(p.pat());
|
let pat = self.collect_pat_opt(p.pat());
|
||||||
let mutability = Mutability::from_mutable(p.is_mut());
|
let mutability = Mutability::from_mutable(p.is_mut());
|
||||||
Pat::Ref { pat, mutability }
|
Pat::Ref { pat, mutability }
|
||||||
}
|
}
|
||||||
ast::PatKind::PathPat(p) => {
|
ast::Pat::PathPat(p) => {
|
||||||
let path = p.path().and_then(Path::from_ast);
|
let path = p.path().and_then(Path::from_ast);
|
||||||
path.map(Pat::Path).unwrap_or(Pat::Missing)
|
path.map(Pat::Path).unwrap_or(Pat::Missing)
|
||||||
}
|
}
|
||||||
ast::PatKind::TuplePat(p) => {
|
ast::Pat::TuplePat(p) => {
|
||||||
let args = p.args().map(|p| self.collect_pat(p)).collect();
|
let args = p.args().map(|p| self.collect_pat(p)).collect();
|
||||||
Pat::Tuple(args)
|
Pat::Tuple(args)
|
||||||
}
|
}
|
||||||
ast::PatKind::PlaceholderPat(_) => Pat::Wild,
|
ast::Pat::PlaceholderPat(_) => Pat::Wild,
|
||||||
ast::PatKind::StructPat(p) => {
|
ast::Pat::StructPat(p) => {
|
||||||
let path = p.path().and_then(Path::from_ast);
|
let path = p.path().and_then(Path::from_ast);
|
||||||
let field_pat_list =
|
let field_pat_list =
|
||||||
p.field_pat_list().expect("every struct should have a field list");
|
p.field_pat_list().expect("every struct should have a field list");
|
||||||
|
@ -1022,8 +1020,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: implement
|
// FIXME: implement
|
||||||
ast::PatKind::LiteralPat(_) => Pat::Missing,
|
ast::Pat::LiteralPat(_) => Pat::Missing,
|
||||||
ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing,
|
ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,
|
||||||
};
|
};
|
||||||
let ptr = AstPtr::new(&pat);
|
let ptr = AstPtr::new(&pat);
|
||||||
self.alloc_pat(pattern, Either::A(ptr))
|
self.alloc_pat(pattern, Either::A(ptr))
|
||||||
|
|
|
@ -137,8 +137,8 @@ impl GenericParams {
|
||||||
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
|
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
|
||||||
let path = bound
|
let path = bound
|
||||||
.type_ref()
|
.type_ref()
|
||||||
.and_then(|tr| match tr.kind() {
|
.and_then(|tr| match tr {
|
||||||
ast::TypeRefKind::PathType(path) => path.path(),
|
ast::TypeRef::PathType(path) => path.path(),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.and_then(Path::from_ast);
|
.and_then(Path::from_ast);
|
||||||
|
|
|
@ -131,10 +131,10 @@ impl ImplData {
|
||||||
let items = if let Some(item_list) = node.item_list() {
|
let items = if let Some(item_list) = node.item_list() {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| match item_node.kind() {
|
.map(|item_node| match item_node {
|
||||||
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -207,24 +207,24 @@ impl RawItemsCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
|
fn add_item(&mut self, current_module: Option<Module>, item: ast::ModuleItem) {
|
||||||
let (kind, name) = match item.kind() {
|
let (kind, name) = match item {
|
||||||
ast::ModuleItemKind::Module(module) => {
|
ast::ModuleItem::Module(module) => {
|
||||||
self.add_module(current_module, module);
|
self.add_module(current_module, module);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::UseItem(use_item) => {
|
ast::ModuleItem::UseItem(use_item) => {
|
||||||
self.add_use_item(current_module, use_item);
|
self.add_use_item(current_module, use_item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::ExternCrateItem(extern_crate) => {
|
ast::ModuleItem::ExternCrateItem(extern_crate) => {
|
||||||
self.add_extern_crate_item(current_module, extern_crate);
|
self.add_extern_crate_item(current_module, extern_crate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::ImplBlock(_) => {
|
ast::ModuleItem::ImplBlock(_) => {
|
||||||
// impls don't participate in name resolution
|
// impls don't participate in name resolution
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::StructDef(it) => {
|
ast::ModuleItem::StructDef(it) => {
|
||||||
let id = self.source_ast_id_map.ast_id(&it);
|
let id = self.source_ast_id_map.ast_id(&it);
|
||||||
let name = it.name();
|
let name = it.name();
|
||||||
if it.is_union() {
|
if it.is_union() {
|
||||||
|
@ -233,22 +233,22 @@ impl RawItemsCollector {
|
||||||
(DefKind::Struct(id), name)
|
(DefKind::Struct(id), name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::EnumDef(it) => {
|
ast::ModuleItem::EnumDef(it) => {
|
||||||
(DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::FnDef(it) => {
|
ast::ModuleItem::FnDef(it) => {
|
||||||
(DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::TraitDef(it) => {
|
ast::ModuleItem::TraitDef(it) => {
|
||||||
(DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::TypeAliasDef(it) => {
|
ast::ModuleItem::TypeAliasDef(it) => {
|
||||||
(DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::ConstDef(it) => {
|
ast::ModuleItem::ConstDef(it) => {
|
||||||
(DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
ast::ModuleItemKind::StaticDef(it) => {
|
ast::ModuleItem::StaticDef(it) => {
|
||||||
(DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
|
(DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,10 +30,10 @@ impl TraitData {
|
||||||
let items = if let Some(item_list) = src.ast.item_list() {
|
let items = if let Some(item_list) = src.ast.item_list() {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| match item_node.kind() {
|
.map(|item_node| match item_node {
|
||||||
ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
|
||||||
ast::ImplItemKind::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
ast::ImplItem::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -57,28 +57,33 @@ pub enum TypeRef {
|
||||||
impl TypeRef {
|
impl TypeRef {
|
||||||
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
|
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
|
||||||
pub(crate) fn from_ast(node: ast::TypeRef) -> Self {
|
pub(crate) fn from_ast(node: ast::TypeRef) -> Self {
|
||||||
use ra_syntax::ast::TypeRefKind::*;
|
match node {
|
||||||
match node.kind() {
|
ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
||||||
ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
ast::TypeRef::TupleType(inner) => {
|
||||||
TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()),
|
TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect())
|
||||||
NeverType(..) => TypeRef::Never,
|
}
|
||||||
PathType(inner) => {
|
ast::TypeRef::NeverType(..) => TypeRef::Never,
|
||||||
|
ast::TypeRef::PathType(inner) => {
|
||||||
inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error)
|
inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error)
|
||||||
}
|
}
|
||||||
PointerType(inner) => {
|
ast::TypeRef::PointerType(inner) => {
|
||||||
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
|
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
|
||||||
let mutability = Mutability::from_mutable(inner.is_mut());
|
let mutability = Mutability::from_mutable(inner.is_mut());
|
||||||
TypeRef::RawPtr(Box::new(inner_ty), mutability)
|
TypeRef::RawPtr(Box::new(inner_ty), mutability)
|
||||||
}
|
}
|
||||||
ArrayType(inner) => TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))),
|
ast::TypeRef::ArrayType(inner) => {
|
||||||
SliceType(inner) => TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))),
|
TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref())))
|
||||||
ReferenceType(inner) => {
|
}
|
||||||
|
ast::TypeRef::SliceType(inner) => {
|
||||||
|
TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref())))
|
||||||
|
}
|
||||||
|
ast::TypeRef::ReferenceType(inner) => {
|
||||||
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
|
let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
|
||||||
let mutability = Mutability::from_mutable(inner.is_mut());
|
let mutability = Mutability::from_mutable(inner.is_mut());
|
||||||
TypeRef::Reference(Box::new(inner_ty), mutability)
|
TypeRef::Reference(Box::new(inner_ty), mutability)
|
||||||
}
|
}
|
||||||
PlaceholderType(_inner) => TypeRef::Placeholder,
|
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
|
||||||
FnPointerType(inner) => {
|
ast::TypeRef::FnPointerType(inner) => {
|
||||||
let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref()));
|
let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref()));
|
||||||
let mut params = if let Some(pl) = inner.param_list() {
|
let mut params = if let Some(pl) = inner.param_list() {
|
||||||
pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect()
|
pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect()
|
||||||
|
@ -89,9 +94,9 @@ impl TypeRef {
|
||||||
TypeRef::Fn(params)
|
TypeRef::Fn(params)
|
||||||
}
|
}
|
||||||
// for types are close enough for our purposes to the inner type for now...
|
// for types are close enough for our purposes to the inner type for now...
|
||||||
ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
|
||||||
ImplTraitType(_inner) => TypeRef::Error,
|
ast::TypeRef::ImplTraitType(_inner) => TypeRef::Error,
|
||||||
DynTraitType(_inner) => TypeRef::Error,
|
ast::TypeRef::DynTraitType(_inner) => TypeRef::Error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue