mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Don't mutate the tree while traversing in reorder_impl
This commit is contained in:
parent
544a93ee08
commit
3d6d4e9855
1 changed files with 36 additions and 4 deletions
|
@ -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) {}
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue