Rollup merge of #63855 - killercup:refactor/feature-gates, r=Centril

Refactor feature gates

After #63824, this goes a few steps further by

- parsing doc comments in the macros to extract descriptions for feature gates, and
- introducing a common `Feature` type to replace the tuples used previously to improve readability.

The descriptions are not yet used, but I felt like this PR is a useful enough refactoring on its own.

r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2019-08-26 23:55:49 +02:00 committed by GitHub
commit b005a89dae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 419 additions and 309 deletions

View file

@ -176,7 +176,10 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) -> CollectedFeatures {
CollectedFeatures { lib: lib_features, lang: features }
}
fn format_features<'a>(features: &'a Features, family: &'a str) -> impl Iterator<Item = String> + 'a {
fn format_features<'a>(
features: &'a Features,
family: &'a str,
) -> impl Iterator<Item = String> + 'a {
features.iter().map(move |(name, feature)| {
format!("{:<32} {:<8} {:<12} {:<8}",
name,
@ -228,7 +231,8 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
}
fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features {
let contents = t!(fs::read_to_string(base.join("libsyntax/feature_gate").join(file)));
let path = base.join("libsyntax/feature_gate").join(file);
let contents = t!(fs::read_to_string(&path));
// We allow rustc-internal features to omit a tracking issue.
// To make tidy accept omitting a tracking issue, group the list of features
@ -259,8 +263,9 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
if in_feature_group {
tidy_error!(
bad,
// ignore-tidy-linelength
"libsyntax/feature_gate.rs:{}: new feature group is started without ending the previous one",
"{}:{}: \
new feature group is started without ending the previous one",
path.display(),
line_number,
);
}
@ -289,7 +294,8 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
Err(err) => {
tidy_error!(
bad,
"libsyntax/feature_gate.rs:{}: failed to parse since: {} ({:?})",
"{}:{}: failed to parse since: {} ({:?})",
path.display(),
line_number,
since_str,
err,
@ -301,7 +307,8 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
if prev_since > since {
tidy_error!(
bad,
"libsyntax/feature_gate.rs:{}: feature {} is not sorted by since",
"{}:{}: feature {} is not sorted by since",
path.display(),
line_number,
name,
);
@ -315,7 +322,8 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
*bad = true;
tidy_error!(
bad,
"libsyntax/feature_gate.rs:{}: no tracking issue for feature {}",
"{}:{}: no tracking issue for feature {}",
path.display(),
line_number,
name,
);