1
+ //! Handle syntactic aspects of inserting a new `use`.
1
2
use std:: iter:: { self , successors} ;
2
3
3
4
use algo:: skip_trivia_token;
@@ -10,7 +11,6 @@ use syntax::{
10
11
ast:: { self , make, AstNode } ,
11
12
Direction , InsertPosition , SyntaxElement , SyntaxNode , T ,
12
13
} ;
13
-
14
14
use test_utils:: mark;
15
15
16
16
#[ derive( Debug ) ]
@@ -55,7 +55,7 @@ impl ImportScope {
55
55
fn first_insert_pos ( & self ) -> ( InsertPosition < SyntaxElement > , AddBlankLine ) {
56
56
match self {
57
57
ImportScope :: File ( _) => ( InsertPosition :: First , AddBlankLine :: AfterTwice ) ,
58
- // don't insert the impotrs before the item lists curly brace
58
+ // don't insert the imports before the item list's opening curly brace
59
59
ImportScope :: Module ( item_list) => item_list
60
60
. l_curly_token ( )
61
61
. map ( |b| ( InsertPosition :: After ( b. into ( ) ) , AddBlankLine :: Around ) )
@@ -64,7 +64,7 @@ impl ImportScope {
64
64
}
65
65
66
66
fn insert_pos_after_inner_attribute ( & self ) -> ( InsertPosition < SyntaxElement > , AddBlankLine ) {
67
- // check if the scope has a inner attributes, we dont want to insert in front of it
67
+ // check if the scope has inner attributes, we dont want to insert in front of them
68
68
match self
69
69
. as_syntax_node ( )
70
70
. children ( )
@@ -119,7 +119,7 @@ pub(crate) fn insert_use(
119
119
}
120
120
121
121
if let ident_level @ 1 ..=usize:: MAX = scope. indent_level ( ) . 0 as usize {
122
- // TODO : this alone doesnt properly re-align all cases
122
+ // FIXME : this alone doesnt properly re-align all cases
123
123
buf. push ( make:: tokens:: whitespace ( & " " . repeat ( 4 * ident_level) ) . into ( ) ) ;
124
124
}
125
125
buf. push ( use_item. syntax ( ) . clone ( ) . into ( ) ) ;
@@ -530,8 +530,6 @@ fn main() {}",
530
530
531
531
#[ test]
532
532
fn insert_after_inner_attr ( ) {
533
- // empty files will get two trailing newlines
534
- // this is due to the test case insert_no_imports above
535
533
check_full (
536
534
"foo::bar" ,
537
535
r"#![allow(unused_imports)]" ,
@@ -543,8 +541,6 @@ use foo::bar;",
543
541
544
542
#[ test]
545
543
fn insert_after_inner_attr2 ( ) {
546
- // empty files will get two trailing newlines
547
- // this is due to the test case insert_no_imports above
548
544
check_full (
549
545
"foo::bar" ,
550
546
r"#![allow(unused_imports)]
@@ -647,6 +643,16 @@ use std::io;",
647
643
)
648
644
}
649
645
646
+ #[ test]
647
+ fn merge_groups_skip_pub_crate ( ) {
648
+ check_full (
649
+ "std::io" ,
650
+ r"pub(crate) use std::fmt::{Result, Display};" ,
651
+ r"pub(crate) use std::fmt::{Result, Display};
652
+ use std::io;" ,
653
+ )
654
+ }
655
+
650
656
#[ test]
651
657
#[ ignore] // FIXME: Support this
652
658
fn split_out_merge ( ) {
0 commit comments