@@ -4,8 +4,8 @@ use camino::Utf8Path;
4
4
use semver:: Version ;
5
5
6
6
use super :: {
7
- DirectivesCache , EarlyProps , extract_llvm_version , extract_version_range , iter_directives ,
8
- parse_normalize_rule,
7
+ DirectivesCache , EarlyProps , Edition , EditionRange , extract_llvm_version ,
8
+ extract_version_range , iter_directives , parse_normalize_rule,
9
9
} ;
10
10
use crate :: common:: { Config , Debugger , TestMode } ;
11
11
use crate :: executor:: { CollectedTestDesc , ShouldPanic } ;
@@ -71,6 +71,7 @@ fn test_parse_normalize_rule() {
71
71
struct ConfigBuilder {
72
72
mode : Option < String > ,
73
73
channel : Option < String > ,
74
+ edition : Option < String > ,
74
75
host : Option < String > ,
75
76
target : Option < String > ,
76
77
stage : Option < u32 > ,
@@ -94,6 +95,11 @@ impl ConfigBuilder {
94
95
self
95
96
}
96
97
98
+ fn edition ( & mut self , s : & str ) -> & mut Self {
99
+ self . edition = Some ( s. to_owned ( ) ) ;
100
+ self
101
+ }
102
+
97
103
fn host ( & mut self , s : & str ) -> & mut Self {
98
104
self . host = Some ( s. to_owned ( ) ) ;
99
105
self
@@ -181,6 +187,10 @@ impl ConfigBuilder {
181
187
] ;
182
188
let mut args: Vec < String > = args. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
183
189
190
+ if let Some ( edition) = & self . edition {
191
+ args. push ( format ! ( "--edition={edition}" ) ) ;
192
+ }
193
+
184
194
if let Some ( ref llvm_version) = self . llvm_version {
185
195
args. push ( "--llvm-version" . to_owned ( ) ) ;
186
196
args. push ( llvm_version. clone ( ) ) ;
@@ -939,3 +949,138 @@ fn test_needs_target_std() {
939
949
let config = cfg ( ) . target ( "x86_64-unknown-linux-gnu" ) . build ( ) ;
940
950
assert ! ( !check_ignore( & config, "//@ needs-target-std" ) ) ;
941
951
}
952
+
953
+ fn y ( year : u32 ) -> Edition {
954
+ Edition :: Year ( year)
955
+ }
956
+
957
+ fn parse_edition_range ( line : & str ) -> Option < EditionRange > {
958
+ let config = cfg ( ) . build ( ) ;
959
+ super :: parse_edition_range ( & config, line, "tmp.rs" . into ( ) , 0 )
960
+ }
961
+
962
+ #[ test]
963
+ fn test_parse_edition_range ( ) {
964
+ assert_eq ! ( None , parse_edition_range( "hello-world" ) ) ;
965
+ assert_eq ! ( None , parse_edition_range( "edition" ) ) ;
966
+
967
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2018 ) ) ) , parse_edition_range( "edition: 2018" ) ) ;
968
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2021 ) ) ) , parse_edition_range( "edition:2021" ) ) ;
969
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2024 ) ) ) , parse_edition_range( "edition: 2024 " ) ) ;
970
+ assert_eq ! ( Some ( EditionRange :: Exact ( Edition :: Future ) ) , parse_edition_range( "edition: future" ) ) ;
971
+
972
+ assert_eq ! (
973
+ Some ( EditionRange :: GreaterEqualThan ( y( 2018 ) ) ) ,
974
+ parse_edition_range( "edition: 2018.." )
975
+ ) ;
976
+ assert_eq ! (
977
+ Some ( EditionRange :: GreaterEqualThan ( y( 2021 ) ) ) ,
978
+ parse_edition_range( "edition:2021 .." )
979
+ ) ;
980
+ assert_eq ! (
981
+ Some ( EditionRange :: GreaterEqualThan ( y( 2024 ) ) ) ,
982
+ parse_edition_range( "edition: 2024 .. " )
983
+ ) ;
984
+ assert_eq ! (
985
+ Some ( EditionRange :: GreaterEqualThan ( Edition :: Future ) ) ,
986
+ parse_edition_range( "edition: future.. " )
987
+ ) ;
988
+
989
+ assert_eq ! (
990
+ Some ( EditionRange :: Range { greater_equal_than: y( 2018 ) , lower_than: y( 2024 ) } ) ,
991
+ parse_edition_range( "edition: 2018..2024" )
992
+ ) ;
993
+ assert_eq ! (
994
+ Some ( EditionRange :: Range { greater_equal_than: y( 2015 ) , lower_than: y( 2021 ) } ) ,
995
+ parse_edition_range( "edition:2015 .. 2021 " )
996
+ ) ;
997
+ assert_eq ! (
998
+ Some ( EditionRange :: Range { greater_equal_than: y( 2021 ) , lower_than: y( 2027 ) } ) ,
999
+ parse_edition_range( "edition: 2021 .. 2027 " )
1000
+ ) ;
1001
+ assert_eq ! (
1002
+ Some ( EditionRange :: Range { greater_equal_than: y( 2021 ) , lower_than: Edition :: Future } ) ,
1003
+ parse_edition_range( "edition: 2021..future" )
1004
+ ) ;
1005
+ }
1006
+
1007
+ #[ test]
1008
+ #[ should_panic = "empty directive value detected" ]
1009
+ fn test_parse_edition_range_empty ( ) {
1010
+ parse_edition_range ( "edition:" ) ;
1011
+ }
1012
+
1013
+ #[ test]
1014
+ #[ should_panic = "'hello' doesn't look like an edition" ]
1015
+ fn test_parse_edition_range_invalid_edition ( ) {
1016
+ parse_edition_range ( "edition: hello" ) ;
1017
+ }
1018
+
1019
+ #[ test]
1020
+ #[ should_panic = "'..' is not a supported range in //@ edition" ]
1021
+ fn test_parse_edition_range_double_dots ( ) {
1022
+ parse_edition_range ( "edition: .." ) ;
1023
+ }
1024
+
1025
+ #[ test]
1026
+ #[ should_panic = "the left side of `//@ edition` cannot be higher than the right side" ]
1027
+ fn test_parse_edition_range_inverted_range ( ) {
1028
+ parse_edition_range ( "edition: 2021..2015" ) ;
1029
+ }
1030
+
1031
+ #[ test]
1032
+ #[ should_panic = "the left side of `//@ edition` cannot be higher than the right side" ]
1033
+ fn test_parse_edition_range_inverted_range_future ( ) {
1034
+ parse_edition_range ( "edition: future..2015" ) ;
1035
+ }
1036
+
1037
+ #[ test]
1038
+ #[ should_panic = "the left side of `//@ edition` cannot be equal to the right side" ]
1039
+ fn test_parse_edition_range_empty_range ( ) {
1040
+ parse_edition_range ( "edition: 2021..2021" ) ;
1041
+ }
1042
+
1043
+ #[ track_caller]
1044
+ fn assert_edition_to_test (
1045
+ expected : impl Into < Edition > ,
1046
+ range : EditionRange ,
1047
+ default : Option < & str > ,
1048
+ ) {
1049
+ let mut cfg = cfg ( ) ;
1050
+ if let Some ( default) = default {
1051
+ cfg. edition ( default) ;
1052
+ }
1053
+ assert_eq ! ( expected. into( ) , range. edition_to_test( & cfg. build( ) ) ) ;
1054
+ }
1055
+
1056
+ #[ test]
1057
+ fn test_edition_range_edition_to_test ( ) {
1058
+ let exact = EditionRange :: Exact ( y ( 2021 ) ) ;
1059
+ assert_edition_to_test ( 2021 , exact, None ) ;
1060
+ assert_edition_to_test ( 2021 , exact, Some ( "2018" ) ) ;
1061
+ assert_edition_to_test ( 2021 , exact, Some ( "future" ) ) ;
1062
+
1063
+ assert_edition_to_test ( Edition :: Future , EditionRange :: Exact ( Edition :: Future ) , None ) ;
1064
+
1065
+ let greater_equal_than = EditionRange :: GreaterEqualThan ( y ( 2021 ) ) ;
1066
+ assert_edition_to_test ( 2021 , greater_equal_than, None ) ;
1067
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2015" ) ) ;
1068
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2018" ) ) ;
1069
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2021" ) ) ;
1070
+ assert_edition_to_test ( 2024 , greater_equal_than, Some ( "2024" ) ) ;
1071
+ assert_edition_to_test ( Edition :: Future , greater_equal_than, Some ( "future" ) ) ;
1072
+
1073
+ let range = EditionRange :: Range { greater_equal_than : y ( 2018 ) , lower_than : y ( 2024 ) } ;
1074
+ assert_edition_to_test ( 2018 , range, None ) ;
1075
+ assert_edition_to_test ( 2018 , range, Some ( "2015" ) ) ;
1076
+ assert_edition_to_test ( 2018 , range, Some ( "2018" ) ) ;
1077
+ assert_edition_to_test ( 2021 , range, Some ( "2021" ) ) ;
1078
+ assert_edition_to_test ( 2018 , range, Some ( "2024" ) ) ;
1079
+ assert_edition_to_test ( 2018 , range, Some ( "future" ) ) ;
1080
+ }
1081
+
1082
+ #[ test]
1083
+ #[ should_panic = "'not an edition' doesn't look like an edition" ]
1084
+ fn test_edition_range_edition_to_test_bad_cli ( ) {
1085
+ assert_edition_to_test ( 2021 , EditionRange :: Exact ( y ( 2021 ) ) , Some ( "not an edition" ) ) ;
1086
+ }
0 commit comments