8712: Map nodes to their mutable counterpart before mutating in reorder_impl r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Tobias Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-05-03 16:36:59 +00:00 committed by GitHub
commit 2493e039f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,9 +79,12 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
"Sort methods",
target,
|builder| {
methods.into_iter().zip(sorted).for_each(|(old, new)| {
ted::replace(builder.make_ast_mut(old).syntax(), new.clone_for_update().syntax())
});
let methods =
methods.into_iter().map(|fn_| builder.make_ast_mut(fn_)).collect::<Vec<_>>();
methods
.into_iter()
.zip(sorted)
.for_each(|(old, new)| ted::replace(old.syntax(), new.clone_for_update().syntax()));
},
)
}
@ -160,7 +163,7 @@ $0impl Bar for Foo {}
}
#[test]
fn reorder_impl_trait_methods() {
fn reorder_impl_trait_functions() {
check_assist(
reorder_impl,
r#"
@ -197,4 +200,33 @@ impl Bar for Foo {
"#,
)
}
#[test]
fn reorder_impl_trait_methods_uneven_ident_lengths() {
check_assist(
reorder_impl,
r#"
trait Bar {
fn foo(&mut self) {}
fn fooo(&mut self) {}
}
struct Foo;
impl Bar for Foo {
fn fooo(&mut self) {}
fn foo(&mut self) {$0}
}"#,
r#"
trait Bar {
fn foo(&mut self) {}
fn fooo(&mut self) {}
}
struct Foo;
impl Bar for Foo {
fn foo(&mut self) {}
fn fooo(&mut self) {}
}"#,
)
}
}