Skip to content

Commit e498d66

Browse files
authored
Unrolled build for #141530
Rollup merge of #141530 - ranger-ross:unstable-feature-doc-comments, r=Urgau Added unstable feature doc comments to unstable book This PR adds doc comments for unstables features in [compiler/rustc_feature/src/unstable.rs](https://github.com/rust-lang/rust/blob/d3a2440384b54664dddd56e0081ca094c444e869/compiler/rustc_feature/src/unstable.rs#L190-L191) to the unstable book feature pages. Fixes #141528 Example features rendered ![image](https://github.com/user-attachments/assets/2b65f534-26f8-441f-ba29-65554c9154b7) ![image](https://github.com/user-attachments/assets/6077491b-ddaf-447e-9519-0bc110c7a893) r? `@jyn514`
2 parents 88b3b52 + 3850b1f commit e498d66

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/tools/tidy/src/features.rs

Lines changed: 17 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,6 +297,7 @@ 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

@@ -332,6 +334,13 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
332334
continue;
333335
}
334336

337+
if in_feature_group {
338+
if let Some(doc_comment) = line.strip_prefix("///") {
339+
doc_comments.push(doc_comment.trim().to_string());
340+
continue;
341+
}
342+
}
343+
335344
let mut parts = line.split(',');
336345
let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
337346
Some("unstable") => Status::Unstable,
@@ -438,9 +447,15 @@ 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: if doc_comments.is_empty() {
451+
None
452+
} else {
453+
Some(doc_comments.join(" "))
454+
},
441455
});
442456
}
443457
}
458+
doc_comments.clear();
444459
}
445460
}
446461

@@ -564,6 +579,7 @@ fn map_lib_features(
564579
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
565580
file: file.to_path_buf(),
566581
line: i + 1,
582+
description: None,
567583
};
568584
mf(Ok((feature_name, feature)), file, i + 1);
569585
continue;
@@ -600,6 +616,7 @@ fn map_lib_features(
600616
tracking_issue,
601617
file: file.to_path_buf(),
602618
line: i + 1,
619+
description: None,
603620
};
604621
if line.contains(']') {
605622
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)