1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std::collections::BTreeSet;
14 use features::{collect_lang_features, collect_lib_features, Features, Status};
16 pub const PATH_STR: &str = "doc/unstable-book/src";
18 pub const COMPILER_FLAGS_DIR: &str = "compiler-flags";
20 pub const LANG_FEATURES_DIR: &str = "language-features";
22 pub const LIB_FEATURES_DIR: &str = "library-features";
24 /// Build the path to the Unstable Book source directory from the Rust 'src' directory
25 pub fn unstable_book_path(base_src_path: &path::Path) -> path::PathBuf {
26 base_src_path.join(PATH_STR)
29 /// Directory where the features are documented within the Unstable Book source directory
30 pub fn unstable_book_lang_features_path(base_src_path: &path::Path) -> path::PathBuf {
31 unstable_book_path(base_src_path).join(LANG_FEATURES_DIR)
34 /// Directory where the features are documented within the Unstable Book source directory
35 pub fn unstable_book_lib_features_path(base_src_path: &path::Path) -> path::PathBuf {
36 unstable_book_path(base_src_path).join(LIB_FEATURES_DIR)
39 /// Test to determine if DirEntry is a file
40 fn dir_entry_is_file(dir_entry: &fs::DirEntry) -> bool {
43 .expect("could not determine file type of directory entry")
47 /// Retrieve names of all unstable features
48 pub fn collect_unstable_feature_names(features: &Features) -> BTreeSet<String> {
51 .filter(|&(_, ref f)| f.level == Status::Unstable)
52 .map(|(name, _)| name.replace('_', "-"))
56 pub fn collect_unstable_book_section_file_names(dir: &path::Path) -> BTreeSet<String> {
58 .expect("could not read directory")
60 .map(|entry| entry.expect("could not read directory entry"))
61 .filter(dir_entry_is_file)
62 .map(|entry| entry.file_name().into_string().unwrap())
63 .map(|n| n.trim_right_matches(".md").to_owned())
67 /// Retrieve file names of all library feature sections in the Unstable Book with:
69 /// * hyphens replaced by underscores
70 /// * the markdown suffix ('.md') removed
71 fn collect_unstable_book_lang_features_section_file_names(base_src_path: &path::Path)
73 collect_unstable_book_section_file_names(&unstable_book_lang_features_path(base_src_path))
76 /// Retrieve file names of all language feature sections in the Unstable Book with:
78 /// * hyphens replaced by underscores
79 /// * the markdown suffix ('.md') removed
80 fn collect_unstable_book_lib_features_section_file_names(base_src_path: &path::Path)
82 collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
85 pub fn check(path: &path::Path, bad: &mut bool) {
89 let lang_features = collect_lang_features(path, bad);
90 let lib_features = collect_lib_features(path).into_iter().filter(|&(ref name, _)| {
91 !lang_features.contains_key(name)
94 let unstable_lib_feature_names = collect_unstable_feature_names(&lib_features);
95 let unstable_book_lib_features_section_file_names =
96 collect_unstable_book_lib_features_section_file_names(path);
98 // Check for Unstable Book sections that don't have a corresponding unstable feature
99 for feature_name in &unstable_book_lib_features_section_file_names -
100 &unstable_lib_feature_names {
102 "The Unstable Book has a 'library feature' section '{}' which doesn't \
103 correspond to an unstable library feature",
109 let unstable_lang_feature_names = collect_unstable_feature_names(&lang_features);
110 let unstable_book_lang_features_section_file_names =
111 collect_unstable_book_lang_features_section_file_names(path);
113 // Check for Unstable Book sections that don't have a corresponding unstable feature
114 for feature_name in &unstable_book_lang_features_section_file_names -
115 &unstable_lang_feature_names {
117 "The Unstable Book has a 'language feature' section '{}' which doesn't \
118 correspond to an unstable language feature",
122 // List unstable features that don't have Unstable Book sections
123 // Remove the comment marker if you want the list printed
125 println!("Lib features without unstable book sections:");
126 for feature_name in &unstable_lang_feature_names -
127 &unstable_book_lang_features_section_file_names {
128 println!(" * {} {:?}", feature_name, lib_features[&feature_name].tracking_issue);
131 println!("Lang features without unstable book sections:");
132 for feature_name in &unstable_lib_feature_names-
133 &unstable_book_lib_features_section_file_names {
134 println!(" * {} {:?}", feature_name, lang_features[&feature_name].tracking_issue);