@@ -138,7 +138,7 @@ pub(crate) fn insert_use(
138138 algo:: insert_children ( scope. as_syntax_node ( ) , insert_position, to_insert)
139139}
140140
141- fn try_merge_imports (
141+ pub ( crate ) fn try_merge_imports (
142142 old : & ast:: Use ,
143143 new : & ast:: Use ,
144144 merge_behaviour : MergeBehaviour ,
@@ -161,7 +161,7 @@ fn use_tree_list_is_nested(tl: &ast::UseTreeList) -> bool {
161161}
162162
163163// FIXME: currently this merely prepends the new tree into old, ideally it would insert the items in a sorted fashion
164- pub fn try_merge_trees (
164+ pub ( crate ) fn try_merge_trees (
165165 old : & ast:: UseTree ,
166166 new : & ast:: UseTree ,
167167 merge_behaviour : MergeBehaviour ,
@@ -278,7 +278,8 @@ fn first_path(path: &ast::Path) -> ast::Path {
278278}
279279
280280fn segment_iter ( path : & ast:: Path ) -> impl Iterator < Item = ast:: PathSegment > + Clone {
281- path. syntax ( ) . children ( ) . flat_map ( ast:: PathSegment :: cast)
281+ // cant make use of SyntaxNode::siblings, because the returned Iterator is not clone
282+ successors ( first_segment ( path) , |p| p. parent_path ( ) . parent_path ( ) . and_then ( |p| p. segment ( ) ) )
282283}
283284
284285#[ derive( PartialEq , Eq ) ]
@@ -684,8 +685,18 @@ use std::io;",
684685 check_last (
685686 "foo::bar" ,
686687 r"use foo::bar::baz::Qux;" ,
687- r"use foo::bar::baz::Qux;
688- use foo::bar;" ,
688+ r"use foo::bar;
689+ use foo::bar::baz::Qux;" ,
690+ ) ;
691+ }
692+
693+ #[ test]
694+ fn insert_short_before_long ( ) {
695+ check_none (
696+ "foo::bar" ,
697+ r"use foo::bar::baz::Qux;" ,
698+ r"use foo::bar;
699+ use foo::bar::baz::Qux;" ,
689700 ) ;
690701 }
691702
0 commit comments