mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25: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",
|
"Sort methods",
|
||||||
target,
|
target,
|
||||||
|builder| {
|
|builder| {
|
||||||
methods.into_iter().zip(sorted).for_each(|(old, new)| {
|
let methods =
|
||||||
ted::replace(builder.make_ast_mut(old).syntax(), new.clone_for_update().syntax())
|
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]
|
#[test]
|
||||||
fn reorder_impl_trait_methods() {
|
fn reorder_impl_trait_functions() {
|
||||||
check_assist(
|
check_assist(
|
||||||
reorder_impl,
|
reorder_impl,
|
||||||
r#"
|
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…
Add table
Add a link
Reference in a new issue