Skip to content
/ rust Public
forked from rust-lang/rust

Commit d78704a

Browse files
authored
Rollup merge of rust-lang#139151 - mejrs:underscore_to_dash, r=onur-ozkan
tidy: properly check for orphaned unstable_book pages This also recommends using underscores - something that took me a little bit too long to figure out. Note: this PR deletes the page `src/doc/unstable-book/src/library-features/c-variadic.md`. The page `src/doc/unstable-book/src/lang-features/c-variadic.md` remains.
2 parents 2f5d548 + 14e4f9f commit d78704a

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

src/doc/unstable-book/src/library-features/c-variadic.md

-26
This file was deleted.

src/tools/tidy/src/unstable_book.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ fn collect_unstable_book_lib_features_section_file_names(base_src_path: &Path) -
7272
collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
7373
}
7474

75+
/// Would switching underscores for dashes work?
76+
fn maybe_suggest_dashes(names: &BTreeSet<String>, feature_name: &str, bad: &mut bool) {
77+
let with_dashes = feature_name.replace('_', "-");
78+
if names.contains(&with_dashes) {
79+
tidy_error!(
80+
bad,
81+
"the file `{}.md` contains underscores; use dashes instead: `{}.md`",
82+
feature_name,
83+
with_dashes,
84+
);
85+
}
86+
}
87+
7588
pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
7689
let lang_features = features.lang;
7790
let lib_features = features
@@ -93,14 +106,13 @@ pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
93106
// Check for Unstable Book sections that don't have a corresponding unstable feature
94107
for feature_name in &unstable_book_lib_features_section_file_names - &unstable_lib_feature_names
95108
{
96-
if !unstable_lang_feature_names.contains(&feature_name) {
97-
tidy_error!(
98-
bad,
99-
"The Unstable Book has a 'library feature' section '{}' which doesn't \
109+
tidy_error!(
110+
bad,
111+
"The Unstable Book has a 'library feature' section '{}' which doesn't \
100112
correspond to an unstable library feature",
101-
feature_name
102-
);
103-
}
113+
feature_name
114+
);
115+
maybe_suggest_dashes(&unstable_lib_feature_names, &feature_name, bad);
104116
}
105117

106118
// Check for Unstable Book sections that don't have a corresponding unstable feature.
@@ -112,7 +124,8 @@ pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
112124
"The Unstable Book has a 'language feature' section '{}' which doesn't \
113125
correspond to an unstable language feature",
114126
feature_name
115-
)
127+
);
128+
maybe_suggest_dashes(&unstable_lang_feature_names, &feature_name, bad);
116129
}
117130

118131
// List unstable features that don't have Unstable Book sections.

0 commit comments

Comments
 (0)