aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/ast_transform.rs2
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs6
-rw-r--r--crates/ra_assists/src/handlers/expand_glob_import.rs2
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs5
-rw-r--r--crates/ra_assists/src/handlers/generate_function.rs2
-rw-r--r--crates/ra_assists/src/handlers/replace_if_let_with_match.rs2
-rw-r--r--crates/ra_assists/src/handlers/replace_let_with_if_let.rs4
-rw-r--r--crates/ra_assists/src/handlers/replace_unwrap_with_match.rs4
-rw-r--r--crates/ra_assists/src/utils.rs4
-rw-r--r--crates/ra_ide/src/diagnostics.rs10
-rw-r--r--crates/ra_syntax/src/ast/edit.rs2
-rw-r--r--crates/ra_syntax/src/ast/make.rs14
12 files changed, 29 insertions, 28 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 28f3f3546..15ec75c95 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -63,7 +63,7 @@ impl<'a> SubstituteTypeParams<'a> {
63 let default = k.default(source_scope.db)?; 63 let default = k.default(source_scope.db)?;
64 Some(( 64 Some((
65 k, 65 k,
66 ast::make::type_ref( 66 ast::make::ty(
67 &default 67 &default
68 .display_source_code(source_scope.db, source_scope.module()?.into()) 68 .display_source_code(source_scope.db, source_scope.module()?.into())
69 .ok()?, 69 .ok()?,
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs
index 69852b611..6816a2709 100644
--- a/crates/ra_assists/src/handlers/early_return.rs
+++ b/crates/ra_assists/src/handlers/early_return.rs
@@ -123,7 +123,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
123 let happy_arm = { 123 let happy_arm = {
124 let pat = make::tuple_struct_pat( 124 let pat = make::tuple_struct_pat(
125 path, 125 path,
126 once(make::bind_pat(make::name("it")).into()), 126 once(make::ident_pat(make::name("it")).into()),
127 ); 127 );
128 let expr = { 128 let expr = {
129 let name_ref = make::name_ref("it"); 129 let name_ref = make::name_ref("it");
@@ -136,7 +136,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
136 136
137 let sad_arm = make::match_arm( 137 let sad_arm = make::match_arm(
138 // FIXME: would be cool to use `None` or `Err(_)` if appropriate 138 // FIXME: would be cool to use `None` or `Err(_)` if appropriate
139 once(make::placeholder_pat().into()), 139 once(make::wildcard_pat().into()),
140 early_expression, 140 early_expression,
141 ); 141 );
142 142
@@ -144,7 +144,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
144 }; 144 };
145 145
146 let let_stmt = make::let_stmt( 146 let let_stmt = make::let_stmt(
147 make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(), 147 make::ident_pat(make::name(&bound_ident.syntax().to_string())).into(),
148 Some(match_expr), 148 Some(match_expr),
149 ); 149 );
150 let let_stmt = let_stmt.indent(if_indent_level); 150 let let_stmt = let_stmt.indent(if_indent_level);
diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs
index 69f6b3674..eb216a81a 100644
--- a/crates/ra_assists/src/handlers/expand_glob_import.rs
+++ b/crates/ra_assists/src/handlers/expand_glob_import.rs
@@ -173,7 +173,7 @@ fn replace_ast(
173 replace_node(replacement); 173 replace_node(replacement);
174 }, 174 },
175 ast::Use(use_item) => { 175 ast::Use(use_item) => {
176 builder.replace_ast(use_item, ast::make::use_item(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false)))); 176 builder.replace_ast(use_item, ast::make::use_(replacement.left_or_else(|ut| ast::make::use_tree(path, Some(ut), None, false))));
177 }, 177 },
178 _ => {}, 178 _ => {},
179 } 179 }
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index b2e14f9d7..6698d1a27 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -197,12 +197,11 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O
197 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though 197 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
198 let pat: ast::Pat = match var.source(db).value.kind() { 198 let pat: ast::Pat = match var.source(db).value.kind() {
199 ast::StructKind::Tuple(field_list) => { 199 ast::StructKind::Tuple(field_list) => {
200 let pats = 200 let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count());
201 iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count());
202 make::tuple_struct_pat(path, pats).into() 201 make::tuple_struct_pat(path, pats).into()
203 } 202 }
204 ast::StructKind::Record(field_list) => { 203 ast::StructKind::Record(field_list) => {
205 let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); 204 let pats = field_list.fields().map(|f| make::ident_pat(f.name().unwrap()).into());
206 make::record_pat(path, pats).into() 205 make::record_pat(path, pats).into()
207 } 206 }
208 ast::StructKind::Unit => make::path_pat(path), 207 ast::StructKind::Unit => make::path_pat(path),
diff --git a/crates/ra_assists/src/handlers/generate_function.rs b/crates/ra_assists/src/handlers/generate_function.rs
index 56510861d..acc97e648 100644
--- a/crates/ra_assists/src/handlers/generate_function.rs
+++ b/crates/ra_assists/src/handlers/generate_function.rs
@@ -142,7 +142,7 @@ impl FunctionBuilder {
142 let fn_body = make::block_expr(vec![], Some(placeholder_expr)); 142 let fn_body = make::block_expr(vec![], Some(placeholder_expr));
143 let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None }; 143 let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None };
144 let mut fn_def = 144 let mut fn_def =
145 make::fn_def(visibility, self.fn_name, self.type_params, self.params, fn_body); 145 make::fn_(visibility, self.fn_name, self.type_params, self.params, fn_body);
146 let leading_ws; 146 let leading_ws;
147 let trailing_ws; 147 let trailing_ws;
148 148
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
index b7e30a7f2..ecafb74a1 100644
--- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
@@ -65,7 +65,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
65 .type_of_pat(&pat) 65 .type_of_pat(&pat)
66 .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty)) 66 .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty))
67 .map(|it| it.sad_pattern()) 67 .map(|it| it.sad_pattern())
68 .unwrap_or_else(|| make::placeholder_pat().into()); 68 .unwrap_or_else(|| make::wildcard_pat().into());
69 let else_expr = unwrap_trivial_block(else_block); 69 let else_expr = unwrap_trivial_block(else_block);
70 make::match_arm(vec![pattern], else_expr) 70 make::match_arm(vec![pattern], else_expr)
71 }; 71 };
diff --git a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
index 64ad15a23..e4d436dec 100644
--- a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
+++ b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs
@@ -50,10 +50,10 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) ->
50 target, 50 target,
51 |edit| { 51 |edit| {
52 let with_placeholder: ast::Pat = match happy_variant { 52 let with_placeholder: ast::Pat = match happy_variant {
53 None => make::placeholder_pat().into(), 53 None => make::wildcard_pat().into(),
54 Some(var_name) => make::tuple_struct_pat( 54 Some(var_name) => make::tuple_struct_pat(
55 make::path_unqualified(make::path_segment(make::name_ref(var_name))), 55 make::path_unqualified(make::path_segment(make::name_ref(var_name))),
56 once(make::placeholder_pat().into()), 56 once(make::wildcard_pat().into()),
57 ) 57 )
58 .into(), 58 .into(),
59 }; 59 };
diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
index e5a4bb23c..d69f2c1b0 100644
--- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs
@@ -52,7 +52,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
52 target, 52 target,
53 |builder| { 53 |builder| {
54 let ok_path = make::path_unqualified(make::path_segment(make::name_ref(happy_variant))); 54 let ok_path = make::path_unqualified(make::path_segment(make::name_ref(happy_variant)));
55 let it = make::bind_pat(make::name("a")).into(); 55 let it = make::ident_pat(make::name("a")).into();
56 let ok_tuple = make::tuple_struct_pat(ok_path, iter::once(it)).into(); 56 let ok_tuple = make::tuple_struct_pat(ok_path, iter::once(it)).into();
57 57
58 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a"))); 58 let bind_path = make::path_unqualified(make::path_segment(make::name_ref("a")));
@@ -60,7 +60,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
60 60
61 let unreachable_call = make::expr_unreachable(); 61 let unreachable_call = make::expr_unreachable();
62 let err_arm = 62 let err_arm =
63 make::match_arm(iter::once(make::placeholder_pat().into()), unreachable_call); 63 make::match_arm(iter::once(make::wildcard_pat().into()), unreachable_call);
64 64
65 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]); 65 let match_arm_list = make::match_arm_list(vec![ok_arm, err_arm]);
66 let match_expr = make::expr_match(caller.clone(), match_arm_list) 66 let match_expr = make::expr_match(caller.clone(), match_arm_list)
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index 373de273c..54d5678d1 100644
--- a/crates/ra_assists/src/utils.rs
+++ b/crates/ra_assists/src/utils.rs
@@ -181,10 +181,10 @@ impl TryEnum {
181 match self { 181 match self {
182 TryEnum::Result => make::tuple_struct_pat( 182 TryEnum::Result => make::tuple_struct_pat(
183 make::path_unqualified(make::path_segment(make::name_ref("Err"))), 183 make::path_unqualified(make::path_segment(make::name_ref("Err"))),
184 iter::once(make::placeholder_pat().into()), 184 iter::once(make::wildcard_pat().into()),
185 ) 185 )
186 .into(), 186 .into(),
187 TryEnum::Option => make::bind_pat(make::name("None")).into(), 187 TryEnum::Option => make::ident_pat(make::name("None")).into(),
188 } 188 }
189 } 189 }
190 190
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index dd8a7ffd9..73c0b8275 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -78,8 +78,10 @@ pub(crate) fn diagnostics(
78 } else { 78 } else {
79 let mut field_list = d.ast(db); 79 let mut field_list = d.ast(db);
80 for f in d.missed_fields.iter() { 80 for f in d.missed_fields.iter() {
81 let field = 81 let field = make::record_expr_field(
82 make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); 82 make::name_ref(&f.to_string()),
83 Some(make::expr_unit()),
84 );
83 field_list = field_list.append_field(&field); 85 field_list = field_list.append_field(&field);
84 } 86 }
85 87
@@ -178,9 +180,9 @@ fn missing_struct_field_fix(
178 if new_field_type.is_unknown() { 180 if new_field_type.is_unknown() {
179 return None; 181 return None;
180 } 182 }
181 let new_field = make::record_field_def( 183 let new_field = make::record_field(
182 record_expr.field_name()?, 184 record_expr.field_name()?,
183 make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?), 185 make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
184 ); 186 );
185 187
186 let last_field = record_fields.fields().last()?; 188 let last_field = record_fields.fields().last()?;
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 667a9294f..5ed123f91 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -621,7 +621,7 @@ fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElemen
621#[test] 621#[test]
622fn test_increase_indent() { 622fn test_increase_indent() {
623 let arm_list = { 623 let arm_list = {
624 let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit()); 624 let arm = make::match_arm(iter::once(make::wildcard_pat().into()), make::expr_unit());
625 make::match_arm_list(vec![arm.clone(), arm]) 625 make::match_arm_list(vec![arm.clone(), arm])
626 }; 626 };
627 assert_eq!( 627 assert_eq!(
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 3cb1d35ee..254a37fe3 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -17,7 +17,7 @@ pub fn name_ref(text: &str) -> ast::NameRef {
17 ast_from_text(&format!("fn f() {{ {}; }}", text)) 17 ast_from_text(&format!("fn f() {{ {}; }}", text))
18} 18}
19 19
20pub fn type_ref(text: &str) -> ast::Type { 20pub fn ty(text: &str) -> ast::Type {
21 ast_from_text(&format!("impl {} for D {{}};", text)) 21 ast_from_text(&format!("impl {} for D {{}};", text))
22} 22}
23 23
@@ -60,11 +60,11 @@ pub fn use_tree_list(use_trees: impl IntoIterator<Item = ast::UseTree>) -> ast::
60 ast_from_text(&format!("use {{{}}};", use_trees)) 60 ast_from_text(&format!("use {{{}}};", use_trees))
61} 61}
62 62
63pub fn use_item(use_tree: ast::UseTree) -> ast::Use { 63pub fn use_(use_tree: ast::UseTree) -> ast::Use {
64 ast_from_text(&format!("use {};", use_tree)) 64 ast_from_text(&format!("use {};", use_tree))
65} 65}
66 66
67pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField { 67pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField {
68 return match expr { 68 return match expr {
69 Some(expr) => from_text(&format!("{}: {}", name, expr)), 69 Some(expr) => from_text(&format!("{}: {}", name, expr)),
70 None => from_text(&name.to_string()), 70 None => from_text(&name.to_string()),
@@ -75,7 +75,7 @@ pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordE
75 } 75 }
76} 76}
77 77
78pub fn record_field_def(name: ast::NameRef, ty: ast::Type) -> ast::RecordField { 78pub fn record_field(name: ast::NameRef, ty: ast::Type) -> ast::RecordField {
79 ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty)) 79 ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty))
80} 80}
81 81
@@ -148,7 +148,7 @@ pub fn condition(expr: ast::Expr, pattern: Option<ast::Pat>) -> ast::Condition {
148 } 148 }
149} 149}
150 150
151pub fn bind_pat(name: ast::Name) -> ast::IdentPat { 151pub fn ident_pat(name: ast::Name) -> ast::IdentPat {
152 return from_text(name.text()); 152 return from_text(name.text());
153 153
154 fn from_text(text: &str) -> ast::IdentPat { 154 fn from_text(text: &str) -> ast::IdentPat {
@@ -156,7 +156,7 @@ pub fn bind_pat(name: ast::Name) -> ast::IdentPat {
156 } 156 }
157} 157}
158 158
159pub fn placeholder_pat() -> ast::WildcardPat { 159pub fn wildcard_pat() -> ast::WildcardPat {
160 return from_text("_"); 160 return from_text("_");
161 161
162 fn from_text(text: &str) -> ast::WildcardPat { 162 fn from_text(text: &str) -> ast::WildcardPat {
@@ -288,7 +288,7 @@ pub fn visibility_pub_crate() -> ast::Visibility {
288 ast_from_text("pub(crate) struct S") 288 ast_from_text("pub(crate) struct S")
289} 289}
290 290
291pub fn fn_def( 291pub fn fn_(
292 visibility: Option<ast::Visibility>, 292 visibility: Option<ast::Visibility>,
293 fn_name: ast::Name, 293 fn_name: ast::Name,
294 type_params: Option<ast::GenericParamList>, 294 type_params: Option<ast::GenericParamList>,