Skip to content

Commit 2ec1032

Browse files
committed
Teach src/tools/lint-docs about some bootstrap conditionals
1 parent 4a47e8e commit 2ec1032

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/tools/lint-docs/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ impl<'a> LintExtractor<'a> {
206206
None => return Ok(lints),
207207
}
208208
};
209+
210+
fn strip_prefix_and_suffix<'a>(
211+
line: &'a str,
212+
prefix: &str,
213+
suffix: &str,
214+
) -> Option<&'a str> {
215+
line.strip_prefix(prefix)?.strip_suffix(suffix)
216+
}
217+
209218
// Read the lint.
210219
let mut doc_lines = Vec::new();
211220
let (doc, name) = loop {
@@ -216,6 +225,20 @@ impl<'a> LintExtractor<'a> {
216225
doc_lines.push(text.to_string());
217226
} else if line == "///" {
218227
doc_lines.push("".to_string());
228+
} else if let Some(_) = strip_prefix_and_suffix(
229+
line,
230+
r##"#[cfg_attr(bootstrap, doc = ""##,
231+
r##"")]"##,
232+
) {
233+
// Ignore bootstrap-only parts of the doc comment.
234+
continue;
235+
} else if let Some(text) = strip_prefix_and_suffix(
236+
line,
237+
r##"#[cfg_attr(not(bootstrap), doc = ""##,
238+
r##"")]"##,
239+
) {
240+
// Include not-bootstrap parts of the doc comment.
241+
doc_lines.push(text.to_string())
219242
} else if line.starts_with("// ") {
220243
// Ignore comments.
221244
continue;

0 commit comments

Comments
 (0)