aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/add_explicit_type.rs6
-rw-r--r--crates/ra_assists/src/add_missing_impl_members.rs24
-rw-r--r--crates/ra_assists/src/fill_match_arms.rs6
-rw-r--r--crates/ra_assists/src/inline_local_variable.rs50
-rw-r--r--crates/ra_assists/src/merge_match_arms.rs4
5 files changed, 45 insertions, 45 deletions
diff --git a/crates/ra_assists/src/add_explicit_type.rs b/crates/ra_assists/src/add_explicit_type.rs
index 88970929f..78f0f7f28 100644
--- a/crates/ra_assists/src/add_explicit_type.rs
+++ b/crates/ra_assists/src/add_explicit_type.rs
@@ -1,6 +1,6 @@
1use hir::{db::HirDatabase, HirDisplay, Ty}; 1use hir::{db::HirDatabase, HirDisplay, Ty};
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{AstNode, LetStmt, NameOwner, PatKind}, 3 ast::{self, AstNode, LetStmt, NameOwner},
4 T, 4 T,
5}; 5};
6 6
@@ -12,8 +12,8 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option<
12 let expr = stmt.initializer()?; 12 let expr = stmt.initializer()?;
13 let pat = stmt.pat()?; 13 let pat = stmt.pat()?;
14 // Must be a binding 14 // Must be a binding
15 let pat = match pat.kind() { 15 let pat = match pat {
16 PatKind::BindPat(bind_pat) => bind_pat, 16 ast::Pat::BindPat(bind_pat) => bind_pat,
17 _ => return None, 17 _ => return None,
18 }; 18 };
19 let pat_range = pat.syntax().text_range(); 19 let pat_range = pat.syntax().text_range();
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs
index 995e44d5e..31c7d4e80 100644
--- a/crates/ra_assists/src/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/add_missing_impl_members.rs
@@ -5,7 +5,7 @@ use crate::{
5 5
6use hir::{db::HirDatabase, HasSource}; 6use hir::{db::HirDatabase, HasSource};
7use ra_db::FilePosition; 7use ra_db::FilePosition;
8use ra_syntax::ast::{self, AstNode, ImplItemKind, NameOwner}; 8use ra_syntax::ast::{self, AstNode, NameOwner};
9use ra_syntax::SmolStr; 9use ra_syntax::SmolStr;
10 10
11#[derive(PartialEq)] 11#[derive(PartialEq)]
@@ -49,11 +49,11 @@ fn add_missing_impl_members_inner(
49 resolve_target_trait_def(ctx.db, &analyzer, &impl_node)? 49 resolve_target_trait_def(ctx.db, &analyzer, &impl_node)?
50 }; 50 };
51 51
52 let def_name = |kind| -> Option<SmolStr> { 52 let def_name = |item: &ast::ImplItem| -> Option<SmolStr> {
53 match kind { 53 match item {
54 ast::ImplItemKind::FnDef(def) => def.name(), 54 ast::ImplItem::FnDef(def) => def.name(),
55 ast::ImplItemKind::TypeAliasDef(def) => def.name(), 55 ast::ImplItem::TypeAliasDef(def) => def.name(),
56 ast::ImplItemKind::ConstDef(def) => def.name(), 56 ast::ImplItem::ConstDef(def) => def.name(),
57 } 57 }
58 .map(|it| it.text().clone()) 58 .map(|it| it.text().clone())
59 }; 59 };
@@ -62,15 +62,15 @@ fn add_missing_impl_members_inner(
62 let impl_items = impl_item_list.impl_items().collect::<Vec<_>>(); 62 let impl_items = impl_item_list.impl_items().collect::<Vec<_>>();
63 63
64 let missing_items: Vec<_> = trait_items 64 let missing_items: Vec<_> = trait_items
65 .filter(|t| def_name(t.kind()).is_some()) 65 .filter(|t| def_name(t).is_some())
66 .filter(|t| match t.kind() { 66 .filter(|t| match t {
67 ImplItemKind::FnDef(def) => match mode { 67 ast::ImplItem::FnDef(def) => match mode {
68 AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), 68 AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(),
69 AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), 69 AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(),
70 }, 70 },
71 _ => mode == AddMissingImplMembersMode::NoDefaultMethods, 71 _ => mode == AddMissingImplMembersMode::NoDefaultMethods,
72 }) 72 })
73 .filter(|t| impl_items.iter().all(|i| def_name(i.kind()) != def_name(t.kind()))) 73 .filter(|t| impl_items.iter().all(|i| def_name(i) != def_name(t)))
74 .collect(); 74 .collect();
75 if missing_items.is_empty() { 75 if missing_items.is_empty() {
76 return None; 76 return None;
@@ -78,8 +78,8 @@ fn add_missing_impl_members_inner(
78 78
79 ctx.add_action(AssistId(assist_id), label, |edit| { 79 ctx.add_action(AssistId(assist_id), label, |edit| {
80 let n_existing_items = impl_item_list.impl_items().count(); 80 let n_existing_items = impl_item_list.impl_items().count();
81 let items = missing_items.into_iter().map(|it| match it.kind() { 81 let items = missing_items.into_iter().map(|it| match it {
82 ImplItemKind::FnDef(def) => strip_docstring(add_body(def).into()), 82 ast::ImplItem::FnDef(def) => strip_docstring(add_body(def).into()),
83 _ => strip_docstring(it), 83 _ => strip_docstring(it),
84 }); 84 });
85 let mut ast_editor = AstEditor::new(impl_item_list); 85 let mut ast_editor = AstEditor::new(impl_item_list);
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs
index 939429892..85ff5c052 100644
--- a/crates/ra_assists/src/fill_match_arms.rs
+++ b/crates/ra_assists/src/fill_match_arms.rs
@@ -7,12 +7,12 @@ use ra_syntax::ast::{self, AstNode};
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
8 8
9fn is_trivial_arm(arm: &ast::MatchArm) -> bool { 9fn is_trivial_arm(arm: &ast::MatchArm) -> bool {
10 fn single_pattern(arm: &ast::MatchArm) -> Option<ast::PatKind> { 10 fn single_pattern(arm: &ast::MatchArm) -> Option<ast::Pat> {
11 let (pat,) = arm.pats().collect_tuple()?; 11 let (pat,) = arm.pats().collect_tuple()?;
12 Some(pat.kind()) 12 Some(pat)
13 } 13 }
14 match single_pattern(arm) { 14 match single_pattern(arm) {
15 Some(ast::PatKind::PlaceholderPat(..)) => true, 15 Some(ast::Pat::PlaceholderPat(..)) => true,
16 _ => false, 16 _ => false,
17 } 17 }
18} 18}
diff --git a/crates/ra_assists/src/inline_local_variable.rs b/crates/ra_assists/src/inline_local_variable.rs
index 82c4d54b0..eedb29199 100644
--- a/crates/ra_assists/src/inline_local_variable.rs
+++ b/crates/ra_assists/src/inline_local_variable.rs
@@ -1,6 +1,6 @@
1use hir::db::HirDatabase; 1use hir::db::HirDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, AstToken, ExprKind, PatKind}, 3 ast::{self, AstNode, AstToken},
4 TextRange, 4 TextRange,
5}; 5};
6 6
@@ -9,8 +9,8 @@ use crate::{Assist, AssistCtx, AssistId};
9 9
10pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 10pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
11 let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?; 11 let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?;
12 let bind_pat = match let_stmt.pat()?.kind() { 12 let bind_pat = match let_stmt.pat()? {
13 PatKind::BindPat(pat) => pat, 13 ast::Pat::BindPat(pat) => pat,
14 _ => return None, 14 _ => return None,
15 }; 15 };
16 if bind_pat.is_mutable() { 16 if bind_pat.is_mutable() {
@@ -48,28 +48,28 @@ pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Opt
48 } 48 }
49 }; 49 };
50 50
51 wrap_in_parens[i] = match (initializer_expr.kind(), usage_parent.kind()) { 51 wrap_in_parens[i] = match (&initializer_expr, usage_parent) {
52 (ExprKind::CallExpr(_), _) 52 (ast::Expr::CallExpr(_), _)
53 | (ExprKind::IndexExpr(_), _) 53 | (ast::Expr::IndexExpr(_), _)
54 | (ExprKind::MethodCallExpr(_), _) 54 | (ast::Expr::MethodCallExpr(_), _)
55 | (ExprKind::FieldExpr(_), _) 55 | (ast::Expr::FieldExpr(_), _)
56 | (ExprKind::TryExpr(_), _) 56 | (ast::Expr::TryExpr(_), _)
57 | (ExprKind::RefExpr(_), _) 57 | (ast::Expr::RefExpr(_), _)
58 | (ExprKind::Literal(_), _) 58 | (ast::Expr::Literal(_), _)
59 | (ExprKind::TupleExpr(_), _) 59 | (ast::Expr::TupleExpr(_), _)
60 | (ExprKind::ArrayExpr(_), _) 60 | (ast::Expr::ArrayExpr(_), _)
61 | (ExprKind::ParenExpr(_), _) 61 | (ast::Expr::ParenExpr(_), _)
62 | (ExprKind::PathExpr(_), _) 62 | (ast::Expr::PathExpr(_), _)
63 | (ExprKind::BlockExpr(_), _) 63 | (ast::Expr::BlockExpr(_), _)
64 | (_, ExprKind::CallExpr(_)) 64 | (_, ast::Expr::CallExpr(_))
65 | (_, ExprKind::TupleExpr(_)) 65 | (_, ast::Expr::TupleExpr(_))
66 | (_, ExprKind::ArrayExpr(_)) 66 | (_, ast::Expr::ArrayExpr(_))
67 | (_, ExprKind::ParenExpr(_)) 67 | (_, ast::Expr::ParenExpr(_))
68 | (_, ExprKind::ForExpr(_)) 68 | (_, ast::Expr::ForExpr(_))
69 | (_, ExprKind::WhileExpr(_)) 69 | (_, ast::Expr::WhileExpr(_))
70 | (_, ExprKind::BreakExpr(_)) 70 | (_, ast::Expr::BreakExpr(_))
71 | (_, ExprKind::ReturnExpr(_)) 71 | (_, ast::Expr::ReturnExpr(_))
72 | (_, ExprKind::MatchExpr(_)) => false, 72 | (_, ast::Expr::MatchExpr(_)) => false,
73 _ => true, 73 _ => true,
74 }; 74 };
75 } 75 }
diff --git a/crates/ra_assists/src/merge_match_arms.rs b/crates/ra_assists/src/merge_match_arms.rs
index bc5f6f17c..225a48d3a 100644
--- a/crates/ra_assists/src/merge_match_arms.rs
+++ b/crates/ra_assists/src/merge_match_arms.rs
@@ -30,8 +30,8 @@ pub(crate) fn merge_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<A
30 30
31 ctx.add_action(AssistId("merge_match_arms"), "merge match arms", |edit| { 31 ctx.add_action(AssistId("merge_match_arms"), "merge match arms", |edit| {
32 fn contains_placeholder(a: &MatchArm) -> bool { 32 fn contains_placeholder(a: &MatchArm) -> bool {
33 a.pats().any(|x| match x.kind() { 33 a.pats().any(|x| match x {
34 ra_syntax::ast::PatKind::PlaceholderPat(..) => true, 34 ra_syntax::ast::Pat::PlaceholderPat(..) => true,
35 _ => false, 35 _ => false,
36 }) 36 })
37 } 37 }