Skip to content

Commit

Permalink
Avoid needless_doctest_main on 'extern crate'
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Dec 24, 2019
1 parent 2730d64 commit 129d0cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clippy_lints/src/doc.rs
Expand Up @@ -390,8 +390,10 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
headers
}

static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate"];

fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) {
if text.contains("fn main() {") && !(text.contains("static") || text.contains("fn main() {}")) {
if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) {
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/needless_doc_main.rs
Expand Up @@ -25,6 +25,15 @@ fn bad_doctest() {}
/// assert_eq!(42, ANSWER);
/// }
/// ```
///
/// Neither should this lint because of `extern crate`:
/// ```
/// #![feature(test)]
/// extern crate test;
/// fn main() {
/// assert_eq(1u8, test::black_box(1));
/// }
/// ```
fn no_false_positives() {}

fn main() {
Expand Down

0 comments on commit 129d0cd

Please sign in to comment.