Merge pull request #20305 from Hmikihiro/Migrate_part_of_utils
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run

Migrate part of utils.rs to use SyntaxEditor
This commit is contained in:
Shoyu Vanilla (Flint) 2025-07-27 14:43:01 +00:00 committed by GitHub
commit 971c393ab3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,6 +27,7 @@ use syntax::{
make,
syntax_factory::SyntaxFactory,
},
syntax_editor::SyntaxEditor,
ted,
};
@ -329,7 +330,7 @@ fn invert_special_case(make: &SyntaxFactory, expr: &ast::Expr) -> Option<ast::Ex
fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
match expr {
ast::Expr::BinExpr(bin) => {
let bin = bin.clone_for_update();
let bin = bin.clone_subtree();
let op_token = bin.op_token()?;
let rev_token = match op_token.kind() {
T![==] => T![!=],
@ -345,8 +346,9 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
);
}
};
ted::replace(op_token, make::token(rev_token));
Some(bin.into())
let mut bin_editor = SyntaxEditor::new(bin.syntax().clone());
bin_editor.replace(op_token, make::token(rev_token));
ast::Expr::cast(bin_editor.finish().new_root().clone())
}
ast::Expr::MethodCallExpr(mce) => {
let receiver = mce.receiver()?;