Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy: allow common lang+lib features #43247

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ pub struct Feature {
pub tracking_issue: Option<u32>,
}

impl Feature {
fn check_match(&self, other: &Feature)-> Result<(), Vec<&'static str>> {
let mut mismatches = Vec::new();
if self.level != other.level {
mismatches.push("stability level");
}
if self.level == Status::Stable || other.level == Status::Stable {
// As long as a feature is unstable, the since field tracks
// when the given part of the feature has been implemented.
// Mismatches are tolerable as features evolve and functionality
// gets added.
// Once a feature is stable, the since field tracks the first version
// it was part of the stable distribution, and mismatches are disallowed.
if self.since != other.since {
mismatches.push("since");
}
}
if self.tracking_issue != other.tracking_issue {
mismatches.push("tracking issue");
}
if mismatches.is_empty() {
Ok(())
} else {
Err(mismatches)
}
}
}

pub type Features = HashMap<String, Feature>;

pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
Expand Down Expand Up @@ -242,23 +270,20 @@ fn get_and_check_lib_features(base_src_path: &Path,
&mut |res, file, line| {
match res {
Ok((name, f)) => {
let mut err = |msg: &str| {
tidy_error!(bad, "{}:{}: {}", file.display(), line, msg);
};
if lang_features.contains_key(name) && name != "proc_macro" {
err("duplicating a lang feature");
}
if let Some(ref s) = lib_features.get(name) {
if s.level != f.level {
err("different stability level than before");
}
if s.since != f.since {
err("different `since` than before");
let mut check_features = |f: &Feature, list: &Features, display: &str| {
if let Some(ref s) = list.get(name) {
if let Err(m) = (&f).check_match(s) {
tidy_error!(bad,
"{}:{}: mismatches to {} in: {:?}",
file.display(),
line,
display,
&m);
}
}
if s.tracking_issue != f.tracking_issue {
err("different `tracking_issue` than before");
}
}
};
check_features(&f, &lang_features, "corresponding lang feature");
check_features(&f, &lib_features, "previous");
lib_features.insert(name.to_owned(), f);
},
Err(msg) => {
Expand Down