diff options
| author | Eric Huss <eric@huss.org> | 2020-11-29 07:57:55 -0800 |
|---|---|---|
| committer | Eric Huss <eric@huss.org> | 2020-11-29 07:57:55 -0800 |
| commit | a90fdfc70178038599bfc7247aedc83bfe2e88f0 (patch) | |
| tree | d4bb042949ea88b53846e86f578faf2df3f5b540 | |
| parent | 228510b0ec9447df6ee84450f8e3fc9b5a018745 (diff) | |
| download | rust-a90fdfc70178038599bfc7247aedc83bfe2e88f0.tar.gz rust-a90fdfc70178038599bfc7247aedc83bfe2e88f0.zip | |
lint-docs: Use strip-prefix to simplify.
| -rw-r--r-- | src/tools/lint-docs/src/lib.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs index dc878b718ad..326b7948098 100644 --- a/src/tools/lint-docs/src/lib.rs +++ b/src/tools/lint-docs/src/lib.rs @@ -142,8 +142,8 @@ impl<'a> LintExtractor<'a> { match lines.next() { Some((lineno, line)) => { let line = line.trim(); - if line.starts_with("/// ") { - doc_lines.push(line.trim()[4..].to_string()); + if let Some(text) = line.strip_prefix("/// ") { + doc_lines.push(text.trim().to_string()); } else if line.starts_with("///") { doc_lines.push("".to_string()); } else if line.starts_with("// ") { @@ -347,8 +347,7 @@ impl<'a> LintExtractor<'a> { let mut source = String::new(); let needs_main = !example.iter().any(|line| line.contains("fn main")); // Remove `# ` prefix for hidden lines. - let unhidden = - example.iter().map(|line| if line.starts_with("# ") { &line[2..] } else { line }); + let unhidden = example.iter().map(|line| line.strip_prefix("# ").unwrap_or(line)); let mut lines = unhidden.peekable(); while let Some(line) = lines.peek() { if line.starts_with("#!") { |
