From 1f95940c24c63b0d196b4f889a68baed2b123086 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Mon, 29 Mar 2021 16:19:52 +0900 Subject: Fix inconsistent test name --- tests/ui/doc_panics.rs | 114 ------------------------------------- tests/ui/doc_panics.stderr | 82 -------------------------- tests/ui/missing_panics_doc.rs | 114 +++++++++++++++++++++++++++++++++++++ tests/ui/missing_panics_doc.stderr | 82 ++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 196 deletions(-) delete mode 100644 tests/ui/doc_panics.rs delete mode 100644 tests/ui/doc_panics.stderr create mode 100644 tests/ui/missing_panics_doc.rs create mode 100644 tests/ui/missing_panics_doc.stderr diff --git a/tests/ui/doc_panics.rs b/tests/ui/doc_panics.rs deleted file mode 100644 index 17e72353f80..00000000000 --- a/tests/ui/doc_panics.rs +++ /dev/null @@ -1,114 +0,0 @@ -#![warn(clippy::missing_panics_doc)] -#![allow(clippy::option_map_unit_fn)] - -fn main() {} - -/// This needs to be documented -pub fn unwrap() { - let result = Err("Hi"); - result.unwrap() -} - -/// This needs to be documented -pub fn panic() { - panic!("This function panics") -} - -/// This needs to be documented -pub fn todo() { - todo!() -} - -/// This needs to be documented -pub fn inner_body(opt: Option) { - opt.map(|x| { - if x == 10 { - panic!() - } - }); -} - -/// This needs to be documented -pub fn unreachable_and_panic() { - if true { unreachable!() } else { panic!() } -} - -/// This is documented -/// -/// # Panics -/// -/// Panics if `result` if an error -pub fn unwrap_documented() { - let result = Err("Hi"); - result.unwrap() -} - -/// This is documented -/// -/// # Panics -/// -/// Panics just because -pub fn panic_documented() { - panic!("This function panics") -} - -/// This is documented -/// -/// # Panics -/// -/// Panics if `opt` is Just(10) -pub fn inner_body_documented(opt: Option) { - opt.map(|x| { - if x == 10 { - panic!() - } - }); -} - -/// This is documented -/// -/// # Panics -/// -/// We still need to do this part -pub fn todo_documented() { - todo!() -} - -/// This is documented -/// -/// # Panics -/// -/// We still need to do this part -pub fn unreachable_amd_panic_documented() { - if true { unreachable!() } else { panic!() } -} - -/// This is okay because it is private -fn unwrap_private() { - let result = Err("Hi"); - result.unwrap() -} - -/// This is okay because it is private -fn panic_private() { - panic!("This function panics") -} - -/// This is okay because it is private -fn todo_private() { - todo!() -} - -/// This is okay because it is private -fn inner_body_private(opt: Option) { - opt.map(|x| { - if x == 10 { - panic!() - } - }); -} - -/// This is okay because unreachable -pub fn unreachable() { - unreachable!("This function panics") -} diff --git a/tests/ui/doc_panics.stderr b/tests/ui/doc_panics.stderr deleted file mode 100644 index 2fa88a2f6ec..00000000000 --- a/tests/ui/doc_panics.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: docs for function which may panic missing `# Panics` section - --> $DIR/doc_panics.rs:7:1 - | -LL | / pub fn unwrap() { -LL | | let result = Err("Hi"); -LL | | result.unwrap() -LL | | } - | |_^ - | - = note: `-D clippy::missing-panics-doc` implied by `-D warnings` -note: first possible panic found here - --> $DIR/doc_panics.rs:9:5 - | -LL | result.unwrap() - | ^^^^^^^^^^^^^^^ - -error: docs for function which may panic missing `# Panics` section - --> $DIR/doc_panics.rs:13:1 - | -LL | / pub fn panic() { -LL | | panic!("This function panics") -LL | | } - | |_^ - | -note: first possible panic found here - --> $DIR/doc_panics.rs:14:5 - | -LL | panic!("This function panics") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: docs for function which may panic missing `# Panics` section - --> $DIR/doc_panics.rs:18:1 - | -LL | / pub fn todo() { -LL | | todo!() -LL | | } - | |_^ - | -note: first possible panic found here - --> $DIR/doc_panics.rs:19:5 - | -LL | todo!() - | ^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: docs for function which may panic missing `# Panics` section - --> $DIR/doc_panics.rs:23:1 - | -LL | / pub fn inner_body(opt: Option) { -LL | | opt.map(|x| { -LL | | if x == 10 { -LL | | panic!() -LL | | } -LL | | }); -LL | | } - | |_^ - | -note: first possible panic found here - --> $DIR/doc_panics.rs:26:13 - | -LL | panic!() - | ^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: docs for function which may panic missing `# Panics` section - --> $DIR/doc_panics.rs:32:1 - | -LL | / pub fn unreachable_and_panic() { -LL | | if true { unreachable!() } else { panic!() } -LL | | } - | |_^ - | -note: first possible panic found here - --> $DIR/doc_panics.rs:33:39 - | -LL | if true { unreachable!() } else { panic!() } - | ^^^^^^^^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 5 previous errors - diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs new file mode 100644 index 00000000000..17e72353f80 --- /dev/null +++ b/tests/ui/missing_panics_doc.rs @@ -0,0 +1,114 @@ +#![warn(clippy::missing_panics_doc)] +#![allow(clippy::option_map_unit_fn)] + +fn main() {} + +/// This needs to be documented +pub fn unwrap() { + let result = Err("Hi"); + result.unwrap() +} + +/// This needs to be documented +pub fn panic() { + panic!("This function panics") +} + +/// This needs to be documented +pub fn todo() { + todo!() +} + +/// This needs to be documented +pub fn inner_body(opt: Option) { + opt.map(|x| { + if x == 10 { + panic!() + } + }); +} + +/// This needs to be documented +pub fn unreachable_and_panic() { + if true { unreachable!() } else { panic!() } +} + +/// This is documented +/// +/// # Panics +/// +/// Panics if `result` if an error +pub fn unwrap_documented() { + let result = Err("Hi"); + result.unwrap() +} + +/// This is documented +/// +/// # Panics +/// +/// Panics just because +pub fn panic_documented() { + panic!("This function panics") +} + +/// This is documented +/// +/// # Panics +/// +/// Panics if `opt` is Just(10) +pub fn inner_body_documented(opt: Option) { + opt.map(|x| { + if x == 10 { + panic!() + } + }); +} + +/// This is documented +/// +/// # Panics +/// +/// We still need to do this part +pub fn todo_documented() { + todo!() +} + +/// This is documented +/// +/// # Panics +/// +/// We still need to do this part +pub fn unreachable_amd_panic_documented() { + if true { unreachable!() } else { panic!() } +} + +/// This is okay because it is private +fn unwrap_private() { + let result = Err("Hi"); + result.unwrap() +} + +/// This is okay because it is private +fn panic_private() { + panic!("This function panics") +} + +/// This is okay because it is private +fn todo_private() { + todo!() +} + +/// This is okay because it is private +fn inner_body_private(opt: Option) { + opt.map(|x| { + if x == 10 { + panic!() + } + }); +} + +/// This is okay because unreachable +pub fn unreachable() { + unreachable!("This function panics") +} diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr new file mode 100644 index 00000000000..37da6bfd92d --- /dev/null +++ b/tests/ui/missing_panics_doc.stderr @@ -0,0 +1,82 @@ +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:7:1 + | +LL | / pub fn unwrap() { +LL | | let result = Err("Hi"); +LL | | result.unwrap() +LL | | } + | |_^ + | + = note: `-D clippy::missing-panics-doc` implied by `-D warnings` +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:9:5 + | +LL | result.unwrap() + | ^^^^^^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:13:1 + | +LL | / pub fn panic() { +LL | | panic!("This function panics") +LL | | } + | |_^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:14:5 + | +LL | panic!("This function panics") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:18:1 + | +LL | / pub fn todo() { +LL | | todo!() +LL | | } + | |_^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:19:5 + | +LL | todo!() + | ^^^^^^^ + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:23:1 + | +LL | / pub fn inner_body(opt: Option) { +LL | | opt.map(|x| { +LL | | if x == 10 { +LL | | panic!() +LL | | } +LL | | }); +LL | | } + | |_^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:26:13 + | +LL | panic!() + | ^^^^^^^^ + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:32:1 + | +LL | / pub fn unreachable_and_panic() { +LL | | if true { unreachable!() } else { panic!() } +LL | | } + | |_^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:33:39 + | +LL | if true { unreachable!() } else { panic!() } + | ^^^^^^^^ + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 5 previous errors + -- cgit 1.4.1-3-g733a5 From 31afdfc12bbe1bd2681ac17bfb07134ffd3cf061 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Mon, 29 Mar 2021 17:19:05 +0900 Subject: missing_panics_doc: Ignore usage of debug_assert family --- clippy_lints/src/doc.rs | 6 ++++++ tests/ui/missing_panics_doc.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 14338ac8faf..69800f9d331 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -715,6 +715,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { if let Some(path_def_id) = path.res.opt_def_id(); if match_panic_def_id(self.cx, path_def_id); if is_expn_of(expr.span, "unreachable").is_none(); + if !is_expn_of_debug_assertions(expr.span); then { self.panic_span = Some(expr.span); } @@ -738,3 +739,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> { NestedVisitorMap::OnlyBodies(self.cx.tcx.hir()) } } + +fn is_expn_of_debug_assertions(span: Span) -> bool { + const MACRO_NAMES: &[&str] = &["debug_assert", "debug_assert_eq", "debug_assert_ne"]; + MACRO_NAMES.iter().any(|name| is_expn_of(span, name).is_some()) +} diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index 17e72353f80..3fe35c75799 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -112,3 +112,11 @@ fn inner_body_private(opt: Option) { pub fn unreachable() { unreachable!("This function panics") } + +/// #6970. +/// This is okay because it is expansion of `debug_assert` family. +pub fn debug_assertions() { + debug_assert!(false); + debug_assert_eq!(1, 2); + debug_assert_ne!(1, 2); +} -- cgit 1.4.1-3-g733a5