@@ -10,6 +10,7 @@ use std::collections::VecDeque;
10
10
use std:: fmt:: { self , Display , Write } ;
11
11
use std:: iter;
12
12
13
+ use arrayvec:: ArrayVec ;
13
14
use rustc_data_structures:: fx:: FxIndexMap ;
14
15
use rustc_lexer:: { Cursor , FrontmatterAllowed , LiteralKind , TokenKind } ;
15
16
use rustc_span:: edition:: Edition ;
@@ -818,7 +819,7 @@ impl<'src> Classifier<'src> {
818
819
}
819
820
820
821
/// Concatenate colons and idents as one when possible.
821
- fn get_full_ident_path ( & mut self ) -> Vec < ( TokenKind , usize , usize ) > {
822
+ fn get_full_ident_path ( & mut self ) -> ArrayVec < ( TokenKind , usize , usize ) , 2 > {
822
823
let start = self . byte_pos as usize ;
823
824
let mut pos = start;
824
825
let mut has_ident = false ;
@@ -832,13 +833,16 @@ impl<'src> Classifier<'src> {
832
833
// Ident path can start with "::" but if we already have content in the ident path,
833
834
// the "::" is mandatory.
834
835
if has_ident && nb == 0 {
835
- return vec ! [ ( TokenKind :: Ident , start, pos) ] ;
836
+ return ArrayVec :: from_iter ( [ ( TokenKind :: Ident , start, pos) ] ) ;
836
837
} else if nb != 0 && nb != 2 {
837
- if has_ident {
838
- return vec ! [ ( TokenKind :: Ident , start, pos) , ( TokenKind :: Colon , pos, pos + nb) ] ;
838
+ return if has_ident {
839
+ ArrayVec :: from_iter ( [
840
+ ( TokenKind :: Ident , start, pos) ,
841
+ ( TokenKind :: Colon , pos, pos + nb) ,
842
+ ] )
839
843
} else {
840
- return vec ! [ ( TokenKind :: Colon , start, pos + nb) ] ;
841
- }
844
+ ArrayVec :: from_iter ( [ ( TokenKind :: Colon , start, pos + nb) ] )
845
+ } ;
842
846
}
843
847
844
848
if let Some ( ( None , text) ) = self . tokens . peek ( ) . map ( |( token, text) | {
@@ -854,15 +858,21 @@ impl<'src> Classifier<'src> {
854
858
pos += text. len ( ) + nb;
855
859
has_ident = true ;
856
860
self . tokens . next ( ) ;
857
- } else if nb > 0 && has_ident {
858
- return vec ! [ ( TokenKind :: Ident , start, pos) , ( TokenKind :: Colon , pos, pos + nb) ] ;
861
+ continue ;
862
+ }
863
+
864
+ return if nb > 0 && has_ident {
865
+ ArrayVec :: from_iter ( [
866
+ ( TokenKind :: Ident , start, pos) ,
867
+ ( TokenKind :: Colon , pos, pos + nb) ,
868
+ ] )
859
869
} else if nb > 0 {
860
- return vec ! [ ( TokenKind :: Colon , start, start + nb) ] ;
870
+ ArrayVec :: from_iter ( [ ( TokenKind :: Colon , start, start + nb) ] )
861
871
} else if has_ident {
862
- return vec ! [ ( TokenKind :: Ident , start, pos) ] ;
872
+ ArrayVec :: from_iter ( [ ( TokenKind :: Ident , start, pos) ] )
863
873
} else {
864
- return Vec :: new ( ) ;
865
- }
874
+ ArrayVec :: new ( )
875
+ } ;
866
876
}
867
877
}
868
878
@@ -903,8 +913,7 @@ impl<'src> Classifier<'src> {
903
913
if self
904
914
. tokens
905
915
. peek ( )
906
- . map ( |t| matches ! ( t. 0 , TokenKind :: Colon | TokenKind :: Ident ) )
907
- . unwrap_or ( false )
916
+ . is_some_and ( |( kind, _) | matches ! ( kind, TokenKind :: Colon | TokenKind :: Ident ) )
908
917
{
909
918
let tokens = self . get_full_ident_path ( ) ;
910
919
for ( token, start, end) in & tokens {
0 commit comments