Skip to content

Commit 4169af7

Browse files
committed
feat(unstable-book): Added unstable feature doc comments as feature descriptions
1 parent 3d86494 commit 4169af7

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/tools/tidy/src/features.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct Feature {
5454
pub tracking_issue: Option<NonZeroU32>,
5555
pub file: PathBuf,
5656
pub line: usize,
57+
pub description: Option<String>,
5758
}
5859
impl Feature {
5960
fn tracking_issue_display(&self) -> impl fmt::Display {
@@ -296,9 +297,17 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
296297
let mut prev_names = vec![];
297298

298299
let lines = contents.lines().zip(1..);
300+
let mut doc_comments: Vec<String> = Vec::new();
299301
for (line, line_number) in lines {
300302
let line = line.trim();
301303

304+
if in_feature_group {
305+
if let Some(doc_comment) = line.strip_prefix("///") {
306+
doc_comments.push(doc_comment.trim().to_string());
307+
continue;
308+
}
309+
}
310+
302311
// Within -start and -end, the tracking issue can be omitted.
303312
match line {
304313
"// no-tracking-issue-start" => {
@@ -438,9 +447,13 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
438447
tracking_issue,
439448
file: path.to_path_buf(),
440449
line: line_number,
450+
description: {
451+
if doc_comments.is_empty() { None } else { Some(doc_comments.join(" ")) }
452+
},
441453
});
442454
}
443455
}
456+
doc_comments.clear();
444457
}
445458
}
446459

@@ -564,6 +577,7 @@ fn map_lib_features(
564577
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
565578
file: file.to_path_buf(),
566579
line: i + 1,
580+
description: None,
567581
};
568582
mf(Ok((feature_name, feature)), file, i + 1);
569583
continue;
@@ -600,6 +614,7 @@ fn map_lib_features(
600614
tracking_issue,
601615
file: file.to_path_buf(),
602616
line: i + 1,
617+
description: None,
603618
};
604619
if line.contains(']') {
605620
mf(Ok((feature_name, feature)), file, i + 1);

src/tools/unstable-book-gen/src/main.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ use tidy::unstable_book::{
1212
collect_unstable_feature_names,
1313
};
1414

15-
fn generate_stub_issue(path: &Path, name: &str, issue: u32) {
16-
let content = format!(include_str!("stub-issue.md"), name = name, issue = issue);
15+
fn generate_stub_issue(path: &Path, name: &str, issue: u32, description: &str) {
16+
let content = format!(
17+
include_str!("stub-issue.md"),
18+
name = name,
19+
issue = issue,
20+
description = description
21+
);
1722
t!(write(path, content), path);
1823
}
1924

20-
fn generate_stub_no_issue(path: &Path, name: &str) {
21-
let content = format!(include_str!("stub-no-issue.md"), name = name);
25+
fn generate_stub_no_issue(path: &Path, name: &str, description: &str) {
26+
let content = format!(include_str!("stub-no-issue.md"), name = name, description = description);
2227
t!(write(path, content), path);
2328
}
2429

@@ -58,11 +63,17 @@ fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
5863
let file_name = format!("{feature_name}.md");
5964
let out_file_path = out.join(&file_name);
6065
let feature = &features[&feature_name_underscore];
66+
let description = feature.description.as_deref().unwrap_or_default();
6167

6268
if let Some(issue) = feature.tracking_issue {
63-
generate_stub_issue(&out_file_path, &feature_name_underscore, issue.get());
69+
generate_stub_issue(
70+
&out_file_path,
71+
&feature_name_underscore,
72+
issue.get(),
73+
&description,
74+
);
6475
} else {
65-
generate_stub_no_issue(&out_file_path, &feature_name_underscore);
76+
generate_stub_no_issue(&out_file_path, &feature_name_underscore, &description);
6677
}
6778
}
6879
}

src/tools/unstable-book-gen/src/stub-issue.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `{name}`
22

3+
{description}
4+
35
The tracking issue for this feature is: [#{issue}]
46

57
[#{issue}]: https://github.com/rust-lang/rust/issues/{issue}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `{name}`
22

3+
{description}
4+
35
This feature has no tracking issue, and is therefore likely internal to the compiler, not being intended for general use.
46

57
------------------------

0 commit comments

Comments
 (0)