@@ -15,7 +15,7 @@ use rustc_span::{
15
15
use crate :: comment:: combine_strs_with_missing_comments;
16
16
use crate :: config:: lists:: * ;
17
17
use crate :: config:: ImportGranularity ;
18
- use crate :: config:: { Edition , IndentStyle , Version } ;
18
+ use crate :: config:: { Edition , IndentStyle , StyleEdition } ;
19
19
use crate :: lists:: {
20
20
definitive_tactic, itemize_list, write_list, ListFormatting , ListItem , Separator ,
21
21
} ;
@@ -104,7 +104,7 @@ pub(crate) enum UseSegmentKind {
104
104
#[ derive( Clone , Eq , PartialEq ) ]
105
105
pub ( crate ) struct UseSegment {
106
106
pub ( crate ) kind : UseSegmentKind ,
107
- pub ( crate ) version : Version ,
107
+ pub ( crate ) style_edition : StyleEdition ,
108
108
}
109
109
110
110
#[ derive( Clone ) ]
@@ -149,7 +149,7 @@ impl UseSegment {
149
149
} ;
150
150
UseSegment {
151
151
kind,
152
- version : self . version ,
152
+ style_edition : self . style_edition ,
153
153
}
154
154
}
155
155
@@ -197,7 +197,7 @@ impl UseSegment {
197
197
198
198
Some ( UseSegment {
199
199
kind,
200
- version : context. config . version ( ) ,
200
+ style_edition : context. config . style_edition ( ) ,
201
201
} )
202
202
}
203
203
@@ -444,18 +444,21 @@ impl UseTree {
444
444
}
445
445
}
446
446
447
- let version = context. config . version ( ) ;
447
+ let style_edition = context. config . style_edition ( ) ;
448
448
449
449
match a. kind {
450
450
UseTreeKind :: Glob => {
451
451
// in case of a global path and the glob starts at the root, e.g., "::*"
452
452
if a. prefix . segments . len ( ) == 1 && leading_modsep {
453
453
let kind = UseSegmentKind :: Ident ( "" . to_owned ( ) , None ) ;
454
- result. path . push ( UseSegment { kind, version } ) ;
454
+ result. path . push ( UseSegment {
455
+ kind,
456
+ style_edition,
457
+ } ) ;
455
458
}
456
459
result. path . push ( UseSegment {
457
460
kind : UseSegmentKind :: Glob ,
458
- version ,
461
+ style_edition ,
459
462
} ) ;
460
463
}
461
464
UseTreeKind :: Nested {
@@ -480,7 +483,10 @@ impl UseTree {
480
483
// e.g., "::{foo, bar}"
481
484
if a. prefix . segments . len ( ) == 1 && leading_modsep {
482
485
let kind = UseSegmentKind :: Ident ( "" . to_owned ( ) , None ) ;
483
- result. path . push ( UseSegment { kind, version } ) ;
486
+ result. path . push ( UseSegment {
487
+ kind,
488
+ style_edition,
489
+ } ) ;
484
490
}
485
491
let kind = UseSegmentKind :: List (
486
492
list. iter ( )
@@ -490,7 +496,10 @@ impl UseTree {
490
496
} )
491
497
. collect ( ) ,
492
498
) ;
493
- result. path . push ( UseSegment { kind, version } ) ;
499
+ result. path . push ( UseSegment {
500
+ kind,
501
+ style_edition,
502
+ } ) ;
494
503
}
495
504
UseTreeKind :: Simple ( ref rename) => {
496
505
// If the path has leading double colons and is composed of only 2 segments, then we
@@ -519,7 +528,10 @@ impl UseTree {
519
528
_ => UseSegmentKind :: Ident ( name, alias) ,
520
529
} ;
521
530
522
- let segment = UseSegment { kind, version } ;
531
+ let segment = UseSegment {
532
+ kind,
533
+ style_edition,
534
+ } ;
523
535
524
536
// `name` is already in result.
525
537
result. path . pop ( ) ;
@@ -614,7 +626,7 @@ impl UseTree {
614
626
list. sort ( ) ;
615
627
last = UseSegment {
616
628
kind : UseSegmentKind :: List ( list) ,
617
- version : last. version ,
629
+ style_edition : last. style_edition ,
618
630
} ;
619
631
}
620
632
@@ -732,9 +744,12 @@ impl UseTree {
732
744
} ) = self . path . last ( )
733
745
{
734
746
let self_segment = self . path . pop ( ) . unwrap ( ) ;
735
- let version = self_segment. version ;
747
+ let style_edition = self_segment. style_edition ;
736
748
let kind = UseSegmentKind :: List ( vec ! [ UseTree :: from_path( vec![ self_segment] , DUMMY_SP ) ] ) ;
737
- self . path . push ( UseSegment { kind, version } ) ;
749
+ self . path . push ( UseSegment {
750
+ kind,
751
+ style_edition,
752
+ } ) ;
738
753
}
739
754
self
740
755
}
@@ -750,7 +765,7 @@ fn merge_rest(
750
765
return None ;
751
766
}
752
767
if a. len ( ) != len && b. len ( ) != len {
753
- let version = a[ len] . version ;
768
+ let style_edition = a[ len] . style_edition ;
754
769
if let UseSegmentKind :: List ( ref list) = a[ len] . kind {
755
770
let mut list = list. clone ( ) ;
756
771
merge_use_trees_inner (
@@ -760,7 +775,10 @@ fn merge_rest(
760
775
) ;
761
776
let mut new_path = b[ ..len] . to_vec ( ) ;
762
777
let kind = UseSegmentKind :: List ( list) ;
763
- new_path. push ( UseSegment { kind, version } ) ;
778
+ new_path. push ( UseSegment {
779
+ kind,
780
+ style_edition,
781
+ } ) ;
764
782
return Some ( new_path) ;
765
783
}
766
784
} else if len == 1 {
@@ -770,9 +788,12 @@ fn merge_rest(
770
788
( & b[ 0 ] , & a[ 1 ..] )
771
789
} ;
772
790
let kind = UseSegmentKind :: Slf ( common. get_alias ( ) . map ( ToString :: to_string) ) ;
773
- let version = a[ 0 ] . version ;
791
+ let style_edition = a[ 0 ] . style_edition ;
774
792
let mut list = vec ! [ UseTree :: from_path(
775
- vec![ UseSegment { kind, version } ] ,
793
+ vec![ UseSegment {
794
+ kind,
795
+ style_edition,
796
+ } ] ,
776
797
DUMMY_SP ,
777
798
) ] ;
778
799
match rest {
@@ -788,7 +809,7 @@ fn merge_rest(
788
809
b[ 0 ] . clone( ) ,
789
810
UseSegment {
790
811
kind: UseSegmentKind :: List ( list) ,
791
- version ,
812
+ style_edition ,
792
813
} ,
793
814
] ) ;
794
815
} else {
@@ -801,8 +822,11 @@ fn merge_rest(
801
822
list. sort ( ) ;
802
823
let mut new_path = b[ ..len] . to_vec ( ) ;
803
824
let kind = UseSegmentKind :: List ( list) ;
804
- let version = a[ 0 ] . version ;
805
- new_path. push ( UseSegment { kind, version } ) ;
825
+ let style_edition = a[ 0 ] . style_edition ;
826
+ new_path. push ( UseSegment {
827
+ kind,
828
+ style_edition,
829
+ } ) ;
806
830
Some ( new_path)
807
831
}
808
832
@@ -892,7 +916,7 @@ impl Ord for UseSegment {
892
916
| ( Super ( ref a) , Super ( ref b) )
893
917
| ( Crate ( ref a) , Crate ( ref b) ) => match ( a, b) {
894
918
( Some ( sa) , Some ( sb) ) => {
895
- if self . version == Version :: Two {
919
+ if self . style_edition >= StyleEdition :: Edition2024 {
896
920
sa. trim_start_matches ( "r#" ) . cmp ( sb. trim_start_matches ( "r#" ) )
897
921
} else {
898
922
a. cmp ( b)
@@ -902,7 +926,7 @@ impl Ord for UseSegment {
902
926
} ,
903
927
( Glob , Glob ) => Ordering :: Equal ,
904
928
( Ident ( ref pia, ref aa) , Ident ( ref pib, ref ab) ) => {
905
- let ( ia, ib) = if self . version == Version :: Two {
929
+ let ( ia, ib) = if self . style_edition >= StyleEdition :: Edition2024 {
906
930
( pia. trim_start_matches ( "r#" ) , pib. trim_start_matches ( "r#" ) )
907
931
} else {
908
932
( pia. as_str ( ) , pib. as_str ( ) )
@@ -928,7 +952,7 @@ impl Ord for UseSegment {
928
952
( None , Some ( _) ) => Ordering :: Less ,
929
953
( Some ( _) , None ) => Ordering :: Greater ,
930
954
( Some ( aas) , Some ( abs) ) => {
931
- if self . version == Version :: Two {
955
+ if self . style_edition >= StyleEdition :: Edition2024 {
932
956
aas. trim_start_matches ( "r#" )
933
957
. cmp ( abs. trim_start_matches ( "r#" ) )
934
958
} else {
@@ -1114,7 +1138,7 @@ mod test {
1114
1138
1115
1139
struct Parser < ' a > {
1116
1140
input : Peekable < Chars < ' a > > ,
1117
- version : Version ,
1141
+ style_edition : StyleEdition ,
1118
1142
}
1119
1143
1120
1144
impl < ' a > Parser < ' a > {
@@ -1132,35 +1156,47 @@ mod test {
1132
1156
buf : & mut String ,
1133
1157
alias_buf : & mut Option < String > ,
1134
1158
) {
1135
- let version = self . version ;
1159
+ let style_edition = self . style_edition ;
1136
1160
if !buf. is_empty ( ) {
1137
1161
let mut alias = None ;
1138
1162
swap ( alias_buf, & mut alias) ;
1139
1163
1140
1164
match buf. as_ref ( ) {
1141
1165
"self" => {
1142
1166
let kind = UseSegmentKind :: Slf ( alias) ;
1143
- result. push ( UseSegment { kind, version } ) ;
1167
+ result. push ( UseSegment {
1168
+ kind,
1169
+ style_edition,
1170
+ } ) ;
1144
1171
* buf = String :: new ( ) ;
1145
1172
* alias_buf = None ;
1146
1173
}
1147
1174
"super" => {
1148
1175
let kind = UseSegmentKind :: Super ( alias) ;
1149
- result. push ( UseSegment { kind, version } ) ;
1176
+ result. push ( UseSegment {
1177
+ kind,
1178
+ style_edition,
1179
+ } ) ;
1150
1180
* buf = String :: new ( ) ;
1151
1181
* alias_buf = None ;
1152
1182
}
1153
1183
"crate" => {
1154
1184
let kind = UseSegmentKind :: Crate ( alias) ;
1155
- result. push ( UseSegment { kind, version } ) ;
1185
+ result. push ( UseSegment {
1186
+ kind,
1187
+ style_edition,
1188
+ } ) ;
1156
1189
* buf = String :: new ( ) ;
1157
1190
* alias_buf = None ;
1158
1191
}
1159
1192
_ => {
1160
1193
let mut name = String :: new ( ) ;
1161
1194
swap ( buf, & mut name) ;
1162
1195
let kind = UseSegmentKind :: Ident ( name, alias) ;
1163
- result. push ( UseSegment { kind, version } ) ;
1196
+ result. push ( UseSegment {
1197
+ kind,
1198
+ style_edition,
1199
+ } ) ;
1164
1200
}
1165
1201
}
1166
1202
}
@@ -1178,7 +1214,7 @@ mod test {
1178
1214
let kind = UseSegmentKind :: List ( self . parse_list ( ) ) ;
1179
1215
result. push ( UseSegment {
1180
1216
kind,
1181
- version : self . version ,
1217
+ style_edition : self . style_edition ,
1182
1218
} ) ;
1183
1219
self . eat ( '}' ) ;
1184
1220
}
@@ -1188,7 +1224,7 @@ mod test {
1188
1224
let kind = UseSegmentKind :: Glob ;
1189
1225
result. push ( UseSegment {
1190
1226
kind,
1191
- version : self . version ,
1227
+ style_edition : self . style_edition ,
1192
1228
} ) ;
1193
1229
}
1194
1230
':' => {
@@ -1249,7 +1285,7 @@ mod test {
1249
1285
1250
1286
let mut parser = Parser {
1251
1287
input : s. chars ( ) . peekable ( ) ,
1252
- version : Version :: One ,
1288
+ style_edition : StyleEdition :: Edition2015 ,
1253
1289
} ;
1254
1290
parser. parse_in_list ( )
1255
1291
}
0 commit comments