From 776dfd7abe577ae32b07b2fce3cbcb9ce39e9b4e Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Mon, 2 Mar 2026 23:22:37 +0530 Subject: [PATCH] remove make from move_bound --- crates/ide-assists/src/handlers/move_bounds.rs | 15 +++++++-------- .../syntax/src/ast/syntax_factory/constructors.rs | 10 ++++++++++ 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 { +fn build_predicate(param: ast::GenericParam, make: &SyntaxFactory) -> Option { let target = match ¶m { - 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 { } .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, + bounds: impl IntoIterator, + ) -> 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()