Skip to content

Commit a90fdfc

Browse files
committed
lint-docs: Use strip-prefix to simplify.
1 parent 228510b commit a90fdfc

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ impl<'a> LintExtractor<'a> {
142142
match lines.next() {
143143
Some((lineno, line)) => {
144144
let line = line.trim();
145-
if line.starts_with("/// ") {
146-
doc_lines.push(line.trim()[4..].to_string());
145+
if let Some(text) = line.strip_prefix("/// ") {
146+
doc_lines.push(text.trim().to_string());
147147
} else if line.starts_with("///") {
148148
doc_lines.push("".to_string());
149149
} else if line.starts_with("// ") {
@@ -347,8 +347,7 @@ impl<'a> LintExtractor<'a> {
347347
let mut source = String::new();
348348
let needs_main = !example.iter().any(|line| line.contains("fn main"));
349349
// Remove `# ` prefix for hidden lines.
350-
let unhidden =
351-
example.iter().map(|line| if line.starts_with("# ") { &line[2..] } else { line });
350+
let unhidden = example.iter().map(|line| line.strip_prefix("# ").unwrap_or(line));
352351
let mut lines = unhidden.peekable();
353352
while let Some(line) = lines.peek() {
354353
if line.starts_with("#!") {

0 commit comments

Comments
 (0)