Skip to content

Commit 9cc93f2

Browse files
committed
Address review comments
1 parent 714f2ca commit 9cc93f2

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::directives::directive_names::{
1818
use crate::directives::needs::CachedNeedsConditions;
1919
use crate::errors::ErrorKind;
2020
use crate::executor::{CollectedTestDesc, ShouldPanic};
21-
use crate::help;
2221
use crate::util::static_regex;
22+
use crate::{fatal, help};
2323

2424
pub(crate) mod auxiliary;
2525
mod cfg;
@@ -1790,23 +1790,35 @@ fn parse_edition_range(
17901790
) -> Option<EditionRange> {
17911791
let raw = config.parse_name_value_directive(line, "edition", testfile, line_number)?;
17921792

1793-
if let Some((greter_equal_than, lower_than)) = raw.split_once("..") {
1794-
Some(match (maybe_parse_edition(greter_equal_than), maybe_parse_edition(lower_than)) {
1795-
(Some(greater_equal_than), Some(lower_than)) if lower_than < greater_equal_than => {
1793+
// Edition range is half-open: `[lower_bound, upper_bound)`
1794+
if let Some((lower_bound, upper_bound)) = raw.split_once("..") {
1795+
Some(match (maybe_parse_edition(lower_bound), maybe_parse_edition(upper_bound)) {
1796+
(Some(lower_bound), Some(upper_bound)) if upper_bound < lower_bound => {
17961797
panic!("the left side of `//@ edition` cannot be higher than the right side");
17971798
}
1798-
(Some(greater_equal_than), Some(lower_than)) if lower_than == greater_equal_than => {
1799+
(Some(lower_bound), Some(upper_bound)) if upper_bound == lower_bound => {
17991800
panic!("the left side of `//@ edition` cannot be equal to the right side");
18001801
}
1801-
(Some(greater_equal_than), Some(lower_than)) => {
1802-
EditionRange::Range { greater_equal_than, lower_than }
1802+
(Some(lower_bound), Some(upper_bound)) => {
1803+
EditionRange::Range { lower_bound, upper_bound }
1804+
}
1805+
(Some(lower_bound), None) => EditionRange::RangeFrom(lower_bound),
1806+
(None, Some(_)) => {
1807+
fatal!(
1808+
"{testfile}:{line_number}: ..edition is not a supported range in //@ edition"
1809+
);
1810+
}
1811+
(None, None) => {
1812+
fatal!("{testfile}:{line_number}: '..' is not a supported range in //@ edition");
18031813
}
1804-
(Some(greater_equal_than), None) => EditionRange::GreaterEqualThan(greater_equal_than),
1805-
(None, Some(_)) => panic!("..edition is not a supported range in //@ edition"),
1806-
(None, None) => panic!("'..' is not a supported range in //@ edition"),
18071814
})
18081815
} else {
1809-
Some(EditionRange::Exact(maybe_parse_edition(&raw).expect("empty value for //@ edition")))
1816+
match maybe_parse_edition(&raw) {
1817+
Some(edition) => Some(EditionRange::Exact(edition)),
1818+
None => {
1819+
fatal!("{testfile}:{line_number}: empty value for //@ edition");
1820+
}
1821+
}
18101822
}
18111823
}
18121824

@@ -1852,8 +1864,12 @@ impl From<u32> for Edition {
18521864
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18531865
enum EditionRange {
18541866
Exact(Edition),
1855-
GreaterEqualThan(Edition),
1856-
Range { greater_equal_than: Edition, lower_than: Edition },
1867+
RangeFrom(Edition),
1868+
/// Half-open range: `[lower_bound, upper_bound)`
1869+
Range {
1870+
lower_bound: Edition,
1871+
upper_bound: Edition,
1872+
},
18571873
}
18581874

18591875
impl EditionRange {
@@ -1864,18 +1880,18 @@ impl EditionRange {
18641880

18651881
match *self {
18661882
EditionRange::Exact(exact) => exact,
1867-
EditionRange::GreaterEqualThan(greater_equal_than) => {
1868-
if requested >= greater_equal_than {
1883+
EditionRange::RangeFrom(lower_bound) => {
1884+
if requested >= lower_bound {
18691885
requested
18701886
} else {
1871-
greater_equal_than // Lower bound
1887+
lower_bound
18721888
}
18731889
}
1874-
EditionRange::Range { greater_equal_than, lower_than } => {
1875-
if requested >= greater_equal_than && requested < lower_than {
1890+
EditionRange::Range { lower_bound, upper_bound } => {
1891+
if requested >= lower_bound && requested < upper_bound {
18761892
requested
18771893
} else {
1878-
greater_equal_than // Lower bound
1894+
lower_bound
18791895
}
18801896
}
18811897
}

src/tools/compiletest/src/directives/tests.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -969,73 +969,64 @@ fn test_parse_edition_range() {
969969
assert_eq!(Some(EditionRange::Exact(y(2024))), parse_edition_range("edition: 2024 "));
970970
assert_eq!(Some(EditionRange::Exact(Edition::Future)), parse_edition_range("edition: future"));
971971

972+
assert_eq!(Some(EditionRange::RangeFrom(y(2018))), parse_edition_range("edition: 2018.."));
973+
assert_eq!(Some(EditionRange::RangeFrom(y(2021))), parse_edition_range("edition:2021 .."));
974+
assert_eq!(Some(EditionRange::RangeFrom(y(2024))), parse_edition_range("edition: 2024 .. "));
972975
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)),
976+
Some(EditionRange::RangeFrom(Edition::Future)),
986977
parse_edition_range("edition: future.. ")
987978
);
988979

989980
assert_eq!(
990-
Some(EditionRange::Range { greater_equal_than: y(2018), lower_than: y(2024) }),
981+
Some(EditionRange::Range { lower_bound: y(2018), upper_bound: y(2024) }),
991982
parse_edition_range("edition: 2018..2024")
992983
);
993984
assert_eq!(
994-
Some(EditionRange::Range { greater_equal_than: y(2015), lower_than: y(2021) }),
985+
Some(EditionRange::Range { lower_bound: y(2015), upper_bound: y(2021) }),
995986
parse_edition_range("edition:2015 .. 2021 ")
996987
);
997988
assert_eq!(
998-
Some(EditionRange::Range { greater_equal_than: y(2021), lower_than: y(2027) }),
989+
Some(EditionRange::Range { lower_bound: y(2021), upper_bound: y(2027) }),
999990
parse_edition_range("edition: 2021 .. 2027 ")
1000991
);
1001992
assert_eq!(
1002-
Some(EditionRange::Range { greater_equal_than: y(2021), lower_than: Edition::Future }),
993+
Some(EditionRange::Range { lower_bound: y(2021), upper_bound: Edition::Future }),
1003994
parse_edition_range("edition: 2021..future")
1004995
);
1005996
}
1006997

1007998
#[test]
1008-
#[should_panic = "empty directive value detected"]
999+
#[should_panic]
10091000
fn test_parse_edition_range_empty() {
10101001
parse_edition_range("edition:");
10111002
}
10121003

10131004
#[test]
1014-
#[should_panic = "'hello' doesn't look like an edition"]
1005+
#[should_panic]
10151006
fn test_parse_edition_range_invalid_edition() {
10161007
parse_edition_range("edition: hello");
10171008
}
10181009

10191010
#[test]
1020-
#[should_panic = "'..' is not a supported range in //@ edition"]
1011+
#[should_panic]
10211012
fn test_parse_edition_range_double_dots() {
10221013
parse_edition_range("edition: ..");
10231014
}
10241015

10251016
#[test]
1026-
#[should_panic = "the left side of `//@ edition` cannot be higher than the right side"]
1017+
#[should_panic]
10271018
fn test_parse_edition_range_inverted_range() {
10281019
parse_edition_range("edition: 2021..2015");
10291020
}
10301021

10311022
#[test]
1032-
#[should_panic = "the left side of `//@ edition` cannot be higher than the right side"]
1023+
#[should_panic]
10331024
fn test_parse_edition_range_inverted_range_future() {
10341025
parse_edition_range("edition: future..2015");
10351026
}
10361027

10371028
#[test]
1038-
#[should_panic = "the left side of `//@ edition` cannot be equal to the right side"]
1029+
#[should_panic]
10391030
fn test_parse_edition_range_empty_range() {
10401031
parse_edition_range("edition: 2021..2021");
10411032
}
@@ -1062,15 +1053,15 @@ fn test_edition_range_edition_to_test() {
10621053

10631054
assert_edition_to_test(Edition::Future, EditionRange::Exact(Edition::Future), None);
10641055

1065-
let greater_equal_than = EditionRange::GreaterEqualThan(y(2021));
1056+
let greater_equal_than = EditionRange::RangeFrom(y(2021));
10661057
assert_edition_to_test(2021, greater_equal_than, None);
10671058
assert_edition_to_test(2021, greater_equal_than, Some("2015"));
10681059
assert_edition_to_test(2021, greater_equal_than, Some("2018"));
10691060
assert_edition_to_test(2021, greater_equal_than, Some("2021"));
10701061
assert_edition_to_test(2024, greater_equal_than, Some("2024"));
10711062
assert_edition_to_test(Edition::Future, greater_equal_than, Some("future"));
10721063

1073-
let range = EditionRange::Range { greater_equal_than: y(2018), lower_than: y(2024) };
1064+
let range = EditionRange::Range { lower_bound: y(2018), upper_bound: y(2024) };
10741065
assert_edition_to_test(2018, range, None);
10751066
assert_edition_to_test(2018, range, Some("2015"));
10761067
assert_edition_to_test(2018, range, Some("2018"));
@@ -1080,7 +1071,7 @@ fn test_edition_range_edition_to_test() {
10801071
}
10811072

10821073
#[test]
1083-
#[should_panic = "'not an edition' doesn't look like an edition"]
1074+
#[should_panic]
10841075
fn test_edition_range_edition_to_test_bad_cli() {
10851076
assert_edition_to_test(2021, EditionRange::Exact(y(2021)), Some("not an edition"));
10861077
}

0 commit comments

Comments
 (0)