Unnamed repository; edit this file 'description' to name the repository.
remove make from move_bound
bit-aloo 7 weeks ago
parent 52511b7 · commit 776dfd7
-rw-r--r--crates/ide-assists/src/handlers/move_bounds.rs15
-rw-r--r--crates/syntax/src/ast/syntax_factory/constructors.rs10
2 files changed, 17 insertions, 8 deletions
diff --git a/crates/ide-assists/src/handlers/move_bounds.rs b/crates/ide-assists/src/handlers/move_bounds.rs
index e5425abab0..e9b77a7294 100644
--- a/crates/ide-assists/src/handlers/move_bounds.rs
+++ b/crates/ide-assists/src/handlers/move_bounds.rs
@@ -3,7 +3,7 @@ use syntax::{
ast::{
self, AstNode, HasName, HasTypeBounds,
edit_in_place::{GenericParamsOwnerEdit, Removable},
- make,
+ syntax_factory::SyntaxFactory,
},
match_ast,
};
@@ -50,6 +50,7 @@ pub(crate) fn move_bounds_to_where_clause(
|edit| {
let type_param_list = edit.make_mut(type_param_list);
let parent = edit.make_syntax_mut(parent);
+ let make = SyntaxFactory::without_mappings();
let where_clause: ast::WhereClause = match_ast! {
match parent {
@@ -70,7 +71,7 @@ pub(crate) fn move_bounds_to_where_clause(
ast::GenericParam::ConstParam(_) => continue,
};
if let Some(tbl) = param.type_bound_list() {
- if let Some(predicate) = build_predicate(generic_param) {
+ if let Some(predicate) = build_predicate(generic_param, &make) {
where_clause.add_predicate(predicate)
}
tbl.remove()
@@ -80,15 +81,13 @@ pub(crate) fn move_bounds_to_where_clause(
)
}
-fn build_predicate(param: ast::GenericParam) -> Option<ast::WherePred> {
+fn build_predicate(param: ast::GenericParam, make: &SyntaxFactory) -> Option<ast::WherePred> {
let target = match &param {
- ast::GenericParam::TypeParam(t) => {
- Either::Right(make::ty_path(make::ext::ident_path(&t.name()?.to_string())))
- }
+ ast::GenericParam::TypeParam(t) => Either::Right(make.ty(&t.name()?.to_string())),
ast::GenericParam::LifetimeParam(l) => Either::Left(l.lifetime()?),
ast::GenericParam::ConstParam(_) => return None,
};
- let predicate = make::where_pred(
+ let predicate = make.where_pred(
target,
match param {
ast::GenericParam::TypeParam(t) => t.type_bound_list()?,
@@ -97,7 +96,7 @@ fn build_predicate(param: ast::GenericParam) -> Option<ast::WherePred> {
}
.bounds(),
);
- Some(predicate.clone_for_update())
+ Some(predicate)
}
#[cfg(test)]
diff --git a/crates/syntax/src/ast/syntax_factory/constructors.rs b/crates/syntax/src/ast/syntax_factory/constructors.rs
index 1601ff3174..f50cd90ce9 100644
--- a/crates/syntax/src/ast/syntax_factory/constructors.rs
+++ b/crates/syntax/src/ast/syntax_factory/constructors.rs
@@ -1,4 +1,6 @@
//! Wrappers over [`make`] constructors
+use either::Either;
+
use crate::{
AstNode, NodeOrToken, SyntaxKind, SyntaxNode, SyntaxToken,
ast::{
@@ -124,6 +126,14 @@ impl SyntaxFactory {
make::ty_fn_ptr(is_unsafe, abi, params, ret_type).clone_for_update()
}
+ pub fn where_pred(
+ &self,
+ path: Either<ast::Lifetime, ast::Type>,
+ bounds: impl IntoIterator<Item = ast::TypeBound>,
+ ) -> ast::WherePred {
+ make::where_pred(path, bounds).clone_for_update()
+ }
+
pub fn expr_field(&self, receiver: ast::Expr, field: &str) -> ast::FieldExpr {
let ast::Expr::FieldExpr(ast) =
make::expr_field(receiver.clone(), field).clone_for_update()