1 use std::collections::BTreeSet;
4 use crate::features::{collect_lang_features, collect_lib_features, Features, Status};
6 pub const PATH_STR: &str = "doc/unstable-book/src";
8 pub const COMPILER_FLAGS_DIR: &str = "compiler-flags";
10 pub const LANG_FEATURES_DIR: &str = "language-features";
12 pub const LIB_FEATURES_DIR: &str = "library-features";
14 /// Builds the path to the Unstable Book source directory from the Rust 'src' directory.
15 pub fn unstable_book_path(base_src_path: &path::Path) -> path::PathBuf {
16 base_src_path.join(PATH_STR)
19 /// Builds the path to the directory where the features are documented within the Unstable Book
21 pub fn unstable_book_lang_features_path(base_src_path: &path::Path) -> path::PathBuf {
22 unstable_book_path(base_src_path).join(LANG_FEATURES_DIR)
25 /// Builds the path to the directory where the features are documented within the Unstable Book
27 pub fn unstable_book_lib_features_path(base_src_path: &path::Path) -> path::PathBuf {
28 unstable_book_path(base_src_path).join(LIB_FEATURES_DIR)
31 /// Tests whether `DirEntry` is a file.
32 fn dir_entry_is_file(dir_entry: &fs::DirEntry) -> bool {
35 .expect("could not determine file type of directory entry")
39 /// Retrieves names of all unstable features.
40 pub fn collect_unstable_feature_names(features: &Features) -> BTreeSet<String> {
43 .filter(|&(_, ref f)| f.level == Status::Unstable)
44 .map(|(name, _)| name.replace('_', "-"))
48 pub fn collect_unstable_book_section_file_names(dir: &path::Path) -> BTreeSet<String> {
50 .expect("could not read directory")
51 .map(|entry| entry.expect("could not read directory entry"))
52 .filter(dir_entry_is_file)
53 .map(|entry| entry.path())
54 .filter(|path| path.extension().map(|e| e.to_str().unwrap()) == Some("md"))
55 .map(|path| path.file_stem().unwrap().to_str().unwrap().into())
59 /// Retrieves file names of all library feature sections in the Unstable Book with:
61 /// * hyphens replaced by underscores,
62 /// * the markdown suffix ('.md') removed.
63 fn collect_unstable_book_lang_features_section_file_names(base_src_path: &path::Path)
65 collect_unstable_book_section_file_names(&unstable_book_lang_features_path(base_src_path))
68 /// Retrieves file names of all language feature sections in the Unstable Book with:
70 /// * hyphens replaced by underscores,
71 /// * the markdown suffix ('.md') removed.
72 fn collect_unstable_book_lib_features_section_file_names(base_src_path: &path::Path)
74 collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
77 pub fn check(path: &path::Path, bad: &mut bool) {
80 let lang_features = collect_lang_features(path, bad);
81 let lib_features = collect_lib_features(path).into_iter().filter(|&(ref name, _)| {
82 !lang_features.contains_key(name)
86 let unstable_lib_feature_names = collect_unstable_feature_names(&lib_features);
87 let unstable_book_lib_features_section_file_names =
88 collect_unstable_book_lib_features_section_file_names(path);
91 let unstable_lang_feature_names = collect_unstable_feature_names(&lang_features);
92 let unstable_book_lang_features_section_file_names =
93 collect_unstable_book_lang_features_section_file_names(path);
95 // Check for Unstable Book sections that don't have a corresponding unstable feature
96 for feature_name in &unstable_book_lib_features_section_file_names -
97 &unstable_lib_feature_names {
98 if !unstable_lang_feature_names.contains(&feature_name) {
100 "The Unstable Book has a 'library feature' section '{}' which doesn't \
101 correspond to an unstable library feature",
106 // Check for Unstable Book sections that don't have a corresponding unstable feature.
107 for feature_name in &unstable_book_lang_features_section_file_names -
108 &unstable_lang_feature_names {
110 "The Unstable Book has a 'language feature' section '{}' which doesn't \
111 correspond to an unstable language feature",
115 // List unstable features that don't have Unstable Book sections.
116 // Remove the comment marker if you want the list printed.
118 println!("Lib features without unstable book sections:");
119 for feature_name in &unstable_lang_feature_names -
120 &unstable_book_lang_features_section_file_names {
121 println!(" * {} {:?}", feature_name, lib_features[&feature_name].tracking_issue);
124 println!("Lang features without unstable book sections:");
125 for feature_name in &unstable_lib_feature_names-
126 &unstable_book_lib_features_section_file_names {
127 println!(" * {} {:?}", feature_name, lang_features[&feature_name].tracking_issue);