Auto merge of #10950 - KisaragiEffective:ignore_main_in_notest_doc_block, r=xFrednet

[`needless_doctest_main`]: ignore `main()` in `no_test` code fences

close #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
This commit is contained in:
bors 2023-06-14 10:09:57 +00:00
commit 1d0d686f10
2 changed files with 24 additions and 1 deletions

View file

@ -571,6 +571,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
let mut in_link = None;
let mut in_heading = false;
let mut is_rust = false;
let mut no_test = false;
let mut edition = None;
let mut ticks_unbalanced = false;
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
if item == "ignore" {
is_rust = false;
break;
} else if item == "no_test" {
no_test = true;
}
if let Some(stripped) = item.strip_prefix("edition") {
is_rust = true;
@ -648,7 +651,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
headers.errors |= in_heading && trimmed_text == "Errors";
headers.panics |= in_heading && trimmed_text == "Panics";
if in_code {
if is_rust {
if is_rust && !no_test {
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
check_code(cx, &text, edition, span);
}

View file

@ -0,0 +1,20 @@
#![warn(clippy::needless_doctest_main)]
//! issue 10491:
//! ```rust,no_test
//! use std::collections::HashMap;
//!
//! fn main() {
//! let mut m = HashMap::new();
//! m.insert(1u32, 2u32);
//! }
//! ```
/// some description here
/// ```rust,no_test
/// fn main() {
/// foo()
/// }
/// ```
fn foo() {}
fn main() {}