Skip to content

Commit 1d0d686

Browse files
committed
Auto merge of rust-lang#10950 - KisaragiEffective:ignore_main_in_notest_doc_block, r=xFrednet
[`needless_doctest_main`]: ignore `main()` in `no_test` code fences close rust-lang#10491 *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`needless_doctest_main`]: ignore `main()` in `no_test` code fence
2 parents a59236f + 867bd15 commit 1d0d686

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clippy_lints/src/doc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
571571
let mut in_link = None;
572572
let mut in_heading = false;
573573
let mut is_rust = false;
574+
let mut no_test = false;
574575
let mut edition = None;
575576
let mut ticks_unbalanced = false;
576577
let mut text_to_check: Vec<(CowStr<'_>, Span)> = Vec::new();
@@ -584,6 +585,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
584585
if item == "ignore" {
585586
is_rust = false;
586587
break;
588+
} else if item == "no_test" {
589+
no_test = true;
587590
}
588591
if let Some(stripped) = item.strip_prefix("edition") {
589592
is_rust = true;
@@ -648,7 +651,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
648651
headers.errors |= in_heading && trimmed_text == "Errors";
649652
headers.panics |= in_heading && trimmed_text == "Panics";
650653
if in_code {
651-
if is_rust {
654+
if is_rust && !no_test {
652655
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
653656
check_code(cx, &text, edition, span);
654657
}

tests/ui/doc/needless_doctest_main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![warn(clippy::needless_doctest_main)]
2+
//! issue 10491:
3+
//! ```rust,no_test
4+
//! use std::collections::HashMap;
5+
//!
6+
//! fn main() {
7+
//! let mut m = HashMap::new();
8+
//! m.insert(1u32, 2u32);
9+
//! }
10+
//! ```
11+
12+
/// some description here
13+
/// ```rust,no_test
14+
/// fn main() {
15+
/// foo()
16+
/// }
17+
/// ```
18+
fn foo() {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)