Skip to content

Commit 28486e7

Browse files
committed
Auto merge of #43247 - est31:master, r=alexcrichton
Tidy: allow common lang+lib features This allows changes to the Rust language that have both library and language components share one feature gate. The feature gates need to be "about the same change", so that both library and language components must either be both unstable, or both stable, and share the tracking issue. Removes the ugly "proc_macro" exception added by #40939. Closes #43089
2 parents 582af6e + 94fc09c commit 28486e7

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

Diff for: src/tools/tidy/src/features.rs

+41-16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ pub struct Feature {
5050
pub tracking_issue: Option<u32>,
5151
}
5252

53+
impl Feature {
54+
fn check_match(&self, other: &Feature)-> Result<(), Vec<&'static str>> {
55+
let mut mismatches = Vec::new();
56+
if self.level != other.level {
57+
mismatches.push("stability level");
58+
}
59+
if self.level == Status::Stable || other.level == Status::Stable {
60+
// As long as a feature is unstable, the since field tracks
61+
// when the given part of the feature has been implemented.
62+
// Mismatches are tolerable as features evolve and functionality
63+
// gets added.
64+
// Once a feature is stable, the since field tracks the first version
65+
// it was part of the stable distribution, and mismatches are disallowed.
66+
if self.since != other.since {
67+
mismatches.push("since");
68+
}
69+
}
70+
if self.tracking_issue != other.tracking_issue {
71+
mismatches.push("tracking issue");
72+
}
73+
if mismatches.is_empty() {
74+
Ok(())
75+
} else {
76+
Err(mismatches)
77+
}
78+
}
79+
}
80+
5381
pub type Features = HashMap<String, Feature>;
5482

5583
pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
@@ -242,23 +270,20 @@ fn get_and_check_lib_features(base_src_path: &Path,
242270
&mut |res, file, line| {
243271
match res {
244272
Ok((name, f)) => {
245-
let mut err = |msg: &str| {
246-
tidy_error!(bad, "{}:{}: {}", file.display(), line, msg);
247-
};
248-
if lang_features.contains_key(name) && name != "proc_macro" {
249-
err("duplicating a lang feature");
250-
}
251-
if let Some(ref s) = lib_features.get(name) {
252-
if s.level != f.level {
253-
err("different stability level than before");
254-
}
255-
if s.since != f.since {
256-
err("different `since` than before");
273+
let mut check_features = |f: &Feature, list: &Features, display: &str| {
274+
if let Some(ref s) = list.get(name) {
275+
if let Err(m) = (&f).check_match(s) {
276+
tidy_error!(bad,
277+
"{}:{}: mismatches to {} in: {:?}",
278+
file.display(),
279+
line,
280+
display,
281+
&m);
282+
}
257283
}
258-
if s.tracking_issue != f.tracking_issue {
259-
err("different `tracking_issue` than before");
260-
}
261-
}
284+
};
285+
check_features(&f, &lang_features, "corresponding lang feature");
286+
check_features(&f, &lib_features, "previous");
262287
lib_features.insert(name.to_owned(), f);
263288
},
264289
Err(msg) => {

0 commit comments

Comments
 (0)