Skip to content

Commit 6c5c78d

Browse files
Collect features only once
1 parent ebbc662 commit 6c5c78d

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

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

+33-28
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,36 @@ pub struct Feature {
5050

5151
pub type Features = HashMap<String, Feature>;
5252

53-
pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
53+
pub struct CollectedFeatures {
54+
pub lib: Features,
55+
pub lang: Features,
56+
}
57+
58+
// Currently only used for unstable book generation
59+
pub fn collect_lib_features(base_src_path: &Path) -> Features {
60+
let mut lib_features = Features::new();
61+
62+
// This library feature is defined in the `compiler_builtins` crate, which
63+
// has been moved out-of-tree. Now it can no longer be auto-discovered by
64+
// `tidy`, because we need to filter out its (submodule) directory. Manually
65+
// add it to the set of known library features so we can still generate docs.
66+
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
67+
level: Status::Unstable,
68+
since: None,
69+
has_gate_test: false,
70+
tracking_issue: None,
71+
});
72+
73+
map_lib_features(base_src_path,
74+
&mut |res, _, _| {
75+
if let Ok((name, feature)) = res {
76+
lib_features.insert(name.to_owned(), feature);
77+
}
78+
});
79+
lib_features
80+
}
81+
82+
pub fn check(path: &Path, bad: &mut bool, verbose: bool) -> CollectedFeatures {
5483
let mut features = collect_lang_features(path, bad);
5584
assert!(!features.is_empty());
5685

@@ -125,7 +154,7 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
125154
}
126155

127156
if *bad {
128-
return;
157+
return CollectedFeatures { lib: lib_features, lang: features };
129158
}
130159

131160
if verbose {
@@ -140,6 +169,8 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
140169
} else {
141170
println!("* {} features", features.len());
142171
}
172+
173+
CollectedFeatures { lib: lib_features, lang: features }
143174
}
144175

145176
fn format_features<'a>(features: &'a Features, family: &'a str) -> impl Iterator<Item = String> + 'a {
@@ -303,32 +334,6 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
303334
.collect()
304335
}
305336

306-
pub fn collect_lib_features(base_src_path: &Path) -> Features {
307-
let mut lib_features = Features::new();
308-
309-
// This library feature is defined in the `compiler_builtins` crate, which
310-
// has been moved out-of-tree. Now it can no longer be auto-discovered by
311-
// `tidy`, because we need to filter out its (submodule) directory. Manually
312-
// add it to the set of known library features so we can still generate docs.
313-
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
314-
level: Status::Unstable,
315-
since: None,
316-
has_gate_test: false,
317-
tracking_issue: None,
318-
});
319-
320-
map_lib_features(base_src_path,
321-
&mut |res, _, _| {
322-
if let Ok((name, feature)) = res {
323-
if lib_features.contains_key(name) {
324-
return;
325-
}
326-
lib_features.insert(name.to_owned(), feature);
327-
}
328-
});
329-
lib_features
330-
}
331-
332337
fn get_and_check_lib_features(base_src_path: &Path,
333338
bad: &mut bool,
334339
lang_features: &Features) -> Features {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fn main() {
2424
style::check(&path, &mut bad);
2525
errors::check(&path, &mut bad);
2626
cargo::check(&path, &mut bad);
27-
features::check(&path, &mut bad, verbose);
27+
let collected = features::check(&path, &mut bad, verbose);
2828
pal::check(&path, &mut bad);
29-
unstable_book::check(&path, &mut bad);
29+
unstable_book::check(&path, collected, &mut bad);
3030
libcoretest::check(&path, &mut bad);
3131
if !args.iter().any(|s| *s == "--no-vendor") {
3232
deps::check(&path, &mut bad);

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeSet;
22
use std::fs;
33
use std::path::{PathBuf, Path};
4-
use crate::features::{collect_lang_features, collect_lib_features, Features, Status};
4+
use crate::features::{CollectedFeatures, Features, Feature, Status};
55

66
pub const PATH_STR: &str = "doc/unstable-book";
77

@@ -73,13 +73,22 @@ fn collect_unstable_book_lib_features_section_file_names(base_src_path: &Path) -
7373
collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
7474
}
7575

76-
pub fn check(path: &Path, bad: &mut bool) {
77-
// Library features
78-
79-
let lang_features = collect_lang_features(path, bad);
80-
let lib_features = collect_lib_features(path).into_iter().filter(|&(ref name, _)| {
76+
pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
77+
let lang_features = features.lang;
78+
let mut lib_features = features.lib.into_iter().filter(|&(ref name, _)| {
8179
!lang_features.contains_key(name)
82-
}).collect();
80+
}).collect::<Features>();
81+
82+
// This library feature is defined in the `compiler_builtins` crate, which
83+
// has been moved out-of-tree. Now it can no longer be auto-discovered by
84+
// `tidy`, because we need to filter out its (submodule) directory. Manually
85+
// add it to the set of known library features so we can still generate docs.
86+
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
87+
level: Status::Unstable,
88+
since: None,
89+
has_gate_test: false,
90+
tracking_issue: None,
91+
});
8392

8493
// Library features
8594
let unstable_lib_feature_names = collect_unstable_feature_names(&lib_features);

0 commit comments

Comments
 (0)