mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Rename expr -> tail_expr
This commit is contained in:
parent
5c10f2f705
commit
f9707cde68
18 changed files with 34 additions and 29 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1804,9 +1804,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
|||
|
||||
[[package]]
|
||||
name = "ungrammar"
|
||||
version = "1.5.0"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c11bffada52edc8f2a56160b286ea4640acf90ffcb21bded361ccb8ed43a1457"
|
||||
checksum = "f96cc1b6938f7c548fbcc630bac5c896ae77a130909829ab18b8eab78c51b7ee"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
|
|||
|
||||
let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?;
|
||||
|
||||
if parent_block.expr()? != if_expr.clone().into() {
|
||||
if parent_block.tail_expr()? != if_expr.clone().into() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,10 +117,14 @@ fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &Va
|
|||
.into_iter()
|
||||
.filter(|(_, def)| match def {
|
||||
// only check type-namespace
|
||||
hir::ScopeDef::ModuleDef(def) => matches!(def,
|
||||
ModuleDef::Module(_) | ModuleDef::Adt(_) |
|
||||
ModuleDef::Variant(_) | ModuleDef::Trait(_) |
|
||||
ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_)
|
||||
hir::ScopeDef::ModuleDef(def) => matches!(
|
||||
def,
|
||||
ModuleDef::Module(_)
|
||||
| ModuleDef::Adt(_)
|
||||
| ModuleDef::Variant(_)
|
||||
| ModuleDef::Trait(_)
|
||||
| ModuleDef::TypeAlias(_)
|
||||
| ModuleDef::BuiltinType(_)
|
||||
),
|
||||
_ => false,
|
||||
})
|
||||
|
|
|
@ -139,7 +139,7 @@ impl Anchor {
|
|||
fn from(to_extract: &ast::Expr) -> Option<Anchor> {
|
||||
to_extract.syntax().ancestors().find_map(|node| {
|
||||
if let Some(expr) =
|
||||
node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr())
|
||||
node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.tail_expr())
|
||||
{
|
||||
if expr.syntax() == &node {
|
||||
mark::hit!(test_extract_var_last_expr);
|
||||
|
|
|
@ -89,7 +89,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla
|
|||
let body = closure.body()?;
|
||||
let body_start = body.syntax().first_token()?.text_range().start();
|
||||
let (tail_expr, wrap_expr) = match body {
|
||||
ast::Expr::BlockExpr(block) => (block.expr()?, false),
|
||||
ast::Expr::BlockExpr(block) => (block.tail_expr()?, false),
|
||||
body => (body, true),
|
||||
};
|
||||
|
||||
|
@ -101,7 +101,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla
|
|||
let action = ret_ty_to_action(func.ret_type(), rparen_pos)?;
|
||||
|
||||
let body = func.body()?;
|
||||
let tail_expr = body.expr()?;
|
||||
let tail_expr = body.tail_expr()?;
|
||||
|
||||
let ret_range_end = body.l_curly_token()?.text_range().start();
|
||||
let ret_range = TextRange::new(rparen_pos, ret_range_end);
|
||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) fn inline_function(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
|||
statements.extend(body.statements());
|
||||
|
||||
let original_indentation = call.indent_level();
|
||||
let replacement = make::block_expr(statements, body.expr())
|
||||
let replacement = make::block_expr(statements, body.tail_expr())
|
||||
.reset_indent()
|
||||
.indent(original_indentation);
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
|
|||
let mut replace_node = None;
|
||||
let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| {
|
||||
let block_expr = BlockExpr::cast(arm_body.syntax().clone())?;
|
||||
if let Expr::IfExpr(e) = block_expr.expr()? {
|
||||
if let Expr::IfExpr(e) = block_expr.tail_expr()? {
|
||||
replace_node = Some(block_expr.syntax().clone());
|
||||
Some(e)
|
||||
} else {
|
||||
|
@ -128,7 +128,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
|
|||
|edit| {
|
||||
let then_only_expr = then_block.statements().next().is_none();
|
||||
|
||||
match &then_block.expr() {
|
||||
match &then_block.tail_expr() {
|
||||
Some(then_expr) if then_only_expr => {
|
||||
edit.replace(replace_node.text_range(), then_expr.syntax().text())
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ fn exprify_block(
|
|||
sema: &hir::Semantics<ide_db::RootDatabase>,
|
||||
name: &ast::Expr,
|
||||
) -> Option<ast::BlockExpr> {
|
||||
if block.expr().is_some() {
|
||||
if block.tail_expr().is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext)
|
|||
};
|
||||
let else_expr = match else_expr {
|
||||
ast::Expr::BlockExpr(block)
|
||||
if block.statements().count() == 0 && block.expr().is_none() =>
|
||||
if block.statements().count() == 0 && block.tail_expr().is_none() =>
|
||||
{
|
||||
None
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ impl TailReturnCollector {
|
|||
}
|
||||
|
||||
// Browse tail expressions for each block
|
||||
if let Some(expr) = block_expr.expr() {
|
||||
if let Some(expr) = block_expr.tail_expr() {
|
||||
if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
|
||||
for last_expr in last_exprs {
|
||||
let last_expr = match last_expr {
|
||||
|
@ -170,7 +170,7 @@ impl TailReturnCollector {
|
|||
}
|
||||
|
||||
fn collect_tail_exprs(&mut self, block: &BlockExpr) {
|
||||
if let Some(expr) = block.expr() {
|
||||
if let Some(expr) = block.tail_expr() {
|
||||
self.handle_exprs(&expr, true);
|
||||
self.fetch_tail_exprs(&expr);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
|
|||
Expr::IfExpr(if_expr) => {
|
||||
let mut nodes = vec![];
|
||||
for block in if_expr.blocks() {
|
||||
if let Some(block_expr) = block.expr() {
|
||||
if let Some(block_expr) = block.tail_expr() {
|
||||
if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) {
|
||||
nodes.extend(tail_exprs);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
|
|||
while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)])
|
||||
}
|
||||
Expr::BlockExpr(block_expr) => {
|
||||
block_expr.expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())])
|
||||
block_expr.tail_expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())])
|
||||
}
|
||||
Expr::MatchExpr(match_expr) => {
|
||||
let arm_list = match_expr.match_arm_list()?;
|
||||
|
|
|
@ -37,7 +37,7 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
|
|||
non_trivial_children.next().is_some()
|
||||
};
|
||||
|
||||
if let Some(expr) = block.expr() {
|
||||
if let Some(expr) = block.tail_expr() {
|
||||
if has_anything_else(expr.syntax()) {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -458,7 +458,7 @@ impl<'a> CompletionContext<'a> {
|
|||
}
|
||||
if let Some(block) = ast::BlockExpr::cast(node) {
|
||||
return Some(
|
||||
block.expr().map(|e| e.syntax().text_range())
|
||||
block.tail_expr().map(|e| e.syntax().text_range())
|
||||
== Some(name_ref.syntax().text_range()),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1642,9 +1642,10 @@ impl Type {
|
|||
}
|
||||
|
||||
pub fn is_fn(&self) -> bool {
|
||||
matches!(&self.ty.value,
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. }) |
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. })
|
||||
matches!(
|
||||
&self.ty.value,
|
||||
Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. })
|
||||
| Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. })
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -695,7 +695,7 @@ impl ExprCollector<'_> {
|
|||
self.collect_stmts_items(block.statements());
|
||||
let statements =
|
||||
block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect();
|
||||
let tail = block.expr().map(|e| self.collect_expr(e));
|
||||
let tail = block.tail_expr().map(|e| self.collect_expr(e));
|
||||
self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr)
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ pub enum DisplayTarget {
|
|||
|
||||
impl DisplayTarget {
|
||||
fn is_source_code(&self) -> bool {
|
||||
matches!(self, Self::SourceCode {..})
|
||||
matches!(self, Self::SourceCode { .. })
|
||||
}
|
||||
fn is_test(&self) -> bool {
|
||||
matches!(self, Self::Test)
|
||||
|
|
|
@ -484,7 +484,7 @@ impl ast::AttrsOwner for BlockExpr {}
|
|||
impl BlockExpr {
|
||||
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
|
||||
pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
|
||||
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn tail_expr(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
|
|
@ -290,7 +290,7 @@ fn api_walkthrough() {
|
|||
|
||||
// Let's get the `1 + 1` expression!
|
||||
let body: ast::BlockExpr = func.body().unwrap();
|
||||
let expr: ast::Expr = body.expr().unwrap();
|
||||
let expr: ast::Expr = body.tail_expr().unwrap();
|
||||
|
||||
// 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
|
||||
|
|
|
@ -15,7 +15,7 @@ flate2 = "1.0"
|
|||
pico-args = "0.3.1"
|
||||
proc-macro2 = "1.0.8"
|
||||
quote = "1.0.2"
|
||||
ungrammar = "1.5"
|
||||
ungrammar = "1.6"
|
||||
walkdir = "2.3.1"
|
||||
write-json = "0.1.0"
|
||||
xshell = "0.1"
|
||||
|
|
Loading…
Reference in a new issue