Skip to content

Migrate convert_from_to_tryfrom assist to SyntaxEditor API#21843

Merged
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
sengmonkham:gsoc/migrate-convert-from-to-tryfrom-syntax-editor
Mar 20, 2026
Merged

Migrate convert_from_to_tryfrom assist to SyntaxEditor API#21843
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
sengmonkham:gsoc/migrate-convert-from-to-tryfrom-syntax-editor

Conversation

@sengmonkham
Copy link
Contributor

@sengmonkham sengmonkham commented Mar 18, 2026

Part of #18285.

Migrates the convert_from_to_tryfrom assist from mutable syntax tree
editing (clone_for_update) to the SyntaxEditor / SyntaxFactory API.

Changes

  • Create SyntaxFactory::with_mappings() named make (following the
    migration guide in Migrate assists to SyntaxEditor #18285)
  • Replace make::ty() + .clone_for_update()make.ty()
  • Replace make::name() + .clone_for_update()make.name()
  • Replace make::ty_alias() + .clone_for_update()make.ty_alias()
  • Update wrap_ok() helper to accept &SyntaxFactory and use
    make.expr_call / make.arg_list / make.expr_path
  • Add editor.add_mappings(make.finish_with_mappings())

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 18, 2026
@sengmonkham sengmonkham force-pushed the gsoc/migrate-convert-from-to-tryfrom-syntax-editor branch from 1134d1c to 8f09c8e Compare March 18, 2026 17:38
use ide_db::{famous_defs::FamousDefs, traits::resolve_target_trait};
use syntax::ast::edit::IndentLevel;
use syntax::ast::{self, AstNode, HasGenericArgs, HasName, make};
use syntax::ast::{self, AstNode, HasGenericArgs, HasName, make, syntax_factory::SyntaxFactory};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove make and replace with methods from syntax_factory.

Copy link
Contributor Author

@sengmonkham sengmonkham Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed make import, please review.

Replace mutable syntax tree editing (clone_for_update + make::) with
the SyntaxFactory API, which is the preferred approach for avoiding
mutable tree operations.

Changes:
- Use SyntaxFactory::with_mappings() instead of bare make:: constructors
- Replace make::ty() + .clone_for_update() with make.ty()
- Replace make::name() + .clone_for_update() with make.name()
- Replace make::ty_alias() + .clone_for_update() with make.ty_alias()
- Update wrap_ok() helper to accept &SyntaxFactory and use make.expr_call/arg_list/expr_path
- Add editor.add_mappings(make.finish_with_mappings()) to register mappings
@sengmonkham sengmonkham force-pushed the gsoc/migrate-convert-from-to-tryfrom-syntax-editor branch from 8f09c8e to 9db0bd0 Compare March 19, 2026 06:46
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Mar 20, 2026
Merged via the queue into rust-lang:master with commit d4081f4 Mar 20, 2026
17 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants