diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-11-16 23:58:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-16 23:58:25 +0100 |
| commit | 3f550078c90909f4b23d93cd9302d1691579eb07 (patch) | |
| tree | 3eabb7ceb039ae5f7fc4d7215ef61c442a3215b8 /src/tools | |
| parent | eb9859f00d58d9bbed3db67952ef986e18277f01 (diff) | |
| parent | 2a82d1cd0c93b8d33c885734373bd7806725b37d (diff) | |
Rollup merge of #90935 - jhpratt:alphabetize-features, r=joshtriplett
Alphabetize language features This should significantly reduce the frequency of merge conflicts. r? ````@joshtriplett```` ````@rustbot```` label: +A-contributor-roadblock +S-waiting-on-review
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/tidy/src/features.rs | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 129237775fe..9b6037c6a4b 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -7,7 +7,7 @@ //! * Library features have at most one stability level. //! * Library features have at most one `since` value. //! * All unstable lang features have tests to ensure they are actually unstable. -//! * Language features in a group are sorted by `since` value. +//! * Language features in a group are sorted by feature name. use std::collections::HashMap; use std::fmt; @@ -258,7 +258,7 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features let mut next_feature_omits_tracking_issue = false; let mut in_feature_group = false; - let mut prev_since = None; + let mut prev_names = vec![]; contents .lines() @@ -291,11 +291,11 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features } in_feature_group = true; - prev_since = None; + prev_names = vec![]; return None; } else if line.starts_with(FEATURE_GROUP_END_PREFIX) { in_feature_group = false; - prev_since = None; + prev_names = vec![]; return None; } @@ -325,16 +325,49 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features } }; if in_feature_group { - if prev_since > since { + if prev_names.last() > Some(&name) { + // This assumes the user adds the feature name at the end of the list, as we're + // not looking ahead. + let correct_index = match prev_names.binary_search(&name) { + Ok(_) => { + // This only occurs when the feature name has already been declared. + tidy_error!( + bad, + "{}:{}: duplicate feature {}", + path.display(), + line_number, + name, + ); + // skip any additional checks for this line + return None; + } + Err(index) => index, + }; + + let correct_placement = if correct_index == 0 { + "at the beginning of the feature group".to_owned() + } else if correct_index == prev_names.len() { + // I don't believe this is reachable given the above assumption, but it + // doesn't hurt to be safe. + "at the end of the feature group".to_owned() + } else { + format!( + "between {} and {}", + prev_names[correct_index - 1], + prev_names[correct_index], + ) + }; + tidy_error!( bad, - "{}:{}: feature {} is not sorted by \"since\" (version number)", + "{}:{}: feature {} is not sorted by feature name (should be {})", path.display(), line_number, name, + correct_placement, ); } - prev_since = since; + prev_names.push(name); } let issue_str = parts.next().unwrap().trim(); |
