@@ -8,7 +8,7 @@ use hir::Semantics;
8
8
use syntax:: {
9
9
algo,
10
10
ast:: { self , make, AstNode , HasAttrs , HasModuleItem , HasVisibility , PathSegmentKind } ,
11
- ted, AstToken , Direction , NodeOrToken , SyntaxNode , SyntaxToken ,
11
+ ted, Direction , NodeOrToken , SyntaxKind , SyntaxNode ,
12
12
} ;
13
13
14
14
use crate :: {
@@ -397,12 +397,16 @@ fn insert_use_(
397
397
}
398
398
399
399
// there are no imports in this file at all
400
+ // so put the import after all inner module attributes and possible license header comments
400
401
if let Some ( last_inner_element) = scope_syntax
401
402
. children_with_tokens ( )
402
- . filter ( |child| match child {
403
+ . take_while ( |child| match child {
403
404
NodeOrToken :: Node ( node) => is_inner_attribute ( node. clone ( ) ) ,
404
- NodeOrToken :: Token ( token) => is_comment ( token. clone ( ) ) ,
405
+ NodeOrToken :: Token ( token) => {
406
+ [ SyntaxKind :: WHITESPACE , SyntaxKind :: COMMENT ] . contains ( & token. kind ( ) )
407
+ }
405
408
} )
409
+ . filter ( |child| child. as_token ( ) . map_or ( true , |t| t. kind ( ) != SyntaxKind :: WHITESPACE ) )
406
410
. last ( )
407
411
{
408
412
cov_mark:: hit!( insert_empty_inner_attr) ;
@@ -439,7 +443,3 @@ fn insert_use_(
439
443
fn is_inner_attribute ( node : SyntaxNode ) -> bool {
440
444
ast:: Attr :: cast ( node) . map ( |attr| attr. kind ( ) ) == Some ( ast:: AttrKind :: Inner )
441
445
}
442
-
443
- fn is_comment ( token : SyntaxToken ) -> bool {
444
- ast:: Comment :: cast ( token) . is_some ( )
445
- }
0 commit comments