Skip to content

Commit d5ba6d4

Browse files
committed
Ensure language features in group are sorted by since
1 parent b7f55ca commit d5ba6d4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/tools/tidy/src/features.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! * Library features have at most one stability level.
88
//! * Library features have at most one `since` value.
99
//! * All unstable lang features have tests to ensure they are actually unstable.
10+
//! * Language features in a group are sorted by `since` value.
1011
1112
use std::collections::HashMap;
1213
use std::fmt;
@@ -198,6 +199,7 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
198199
let mut next_feature_omits_tracking_issue = false;
199200

200201
let mut next_feature_group = None;
202+
let mut prev_since = None;
201203

202204
contents.lines().zip(1..)
203205
.filter_map(|(line, line_number)| {
@@ -219,9 +221,11 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
219221
if line.starts_with(FEATURE_GROUP_START_PREFIX) {
220222
let group = line.trim_start_matches(FEATURE_GROUP_START_PREFIX).trim();
221223
next_feature_group = Some(group.to_owned());
224+
prev_since = None;
222225
return None;
223226
} else if line.starts_with(FEATURE_GROUP_END_PREFIX) {
224227
next_feature_group = None;
228+
prev_since = None;
225229
return None;
226230
}
227231

@@ -233,6 +237,7 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
233237
_ => return None,
234238
};
235239
let name = parts.next().unwrap().trim();
240+
236241
let since_str = parts.next().unwrap().trim().trim_matches('"');
237242
let since = match since_str.parse() {
238243
Ok(since) => Some(since),
@@ -247,6 +252,18 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
247252
None
248253
}
249254
};
255+
if next_feature_group.is_some() {
256+
if prev_since > since {
257+
tidy_error!(
258+
bad,
259+
"libsyntax/feature_gate.rs:{}: feature {} is not sorted by since",
260+
line_number,
261+
name,
262+
);
263+
}
264+
prev_since = since.clone();
265+
}
266+
250267
let issue_str = parts.next().unwrap().trim();
251268
let tracking_issue = if issue_str.starts_with("None") {
252269
if level == Status::Unstable && !next_feature_omits_tracking_issue {

0 commit comments

Comments
 (0)