mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
remove ast::*Kind enums
With the new owned trees, we don't need an indirection here
This commit is contained in:
parent
ba2836245b
commit
39e444d701
3 changed files with 398 additions and 391 deletions
File diff suppressed because it is too large
Load diff
|
@ -186,8 +186,8 @@ fn api_walkthrough() {
|
|||
// Let's fetch the `foo` function.
|
||||
let mut func = None;
|
||||
for item in file.items() {
|
||||
match item.kind() {
|
||||
ast::ModuleItemKind::FnDef(f) => func = Some(f),
|
||||
match item {
|
||||
ast::ModuleItem::FnDef(f) => func = Some(f),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -206,12 +206,12 @@ fn api_walkthrough() {
|
|||
let block: ast::Block = func.body().unwrap();
|
||||
let expr: ast::Expr = block.expr().unwrap();
|
||||
|
||||
// "Enum"-like nodes are represented using the "kind" pattern. It allows us
|
||||
// to match exhaustively against all flavors of nodes, while maintaining
|
||||
// internal representation flexibility. The drawback is that one can't write
|
||||
// nested matches as one pattern.
|
||||
let bin_expr: ast::BinExpr = match expr.kind() {
|
||||
ast::ExprKind::BinExpr(e) => e,
|
||||
// Enums are used to group related ast nodes together, and can be used for
|
||||
// matching. However, because there are no public fields, it's possible to
|
||||
// match only the top level enum: that is the price we pay for increased API
|
||||
// flexibility
|
||||
let bin_expr: &ast::BinExpr = match &expr {
|
||||
ast::Expr::BinExpr(e) => e,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue