From 73cd2cde8b96b31b423a33e06dafa0e71e9f2589 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Fri, 16 Jun 2023 16:37:19 +0900 Subject: [PATCH] merge test --- tests/ui/doc/missing_panics_doc.rs | 31 ----------- tests/ui/doc/missing_panics_doc.stderr | 75 -------------------------- tests/ui/missing_panics_doc.rs | 32 +++++++++++ tests/ui/missing_panics_doc.stderr | 74 ++++++++++++++++++++++++- 4 files changed, 105 insertions(+), 107 deletions(-) delete mode 100644 tests/ui/doc/missing_panics_doc.rs delete mode 100644 tests/ui/doc/missing_panics_doc.stderr diff --git a/tests/ui/doc/missing_panics_doc.rs b/tests/ui/doc/missing_panics_doc.rs deleted file mode 100644 index 5cb8a9691..000000000 --- a/tests/ui/doc/missing_panics_doc.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![warn(clippy::missing_panics_doc)] - -pub fn option_unwrap(v: &[T]) -> &T { - let o: Option<&T> = v.last(); - o.unwrap() -} - -pub fn option_expect(v: &[T]) -> &T { - let o: Option<&T> = v.last(); - o.expect("passed an empty thing") -} - -pub fn result_unwrap(v: &[T]) -> &T { - let res: Result<&T, &str> = v.last().ok_or("oh noes"); - res.unwrap() -} - -pub fn result_expect(v: &[T]) -> &T { - let res: Result<&T, &str> = v.last().ok_or("oh noes"); - res.expect("passed an empty thing") -} - -pub fn last_unwrap(v: &[u32]) -> u32 { - *v.last().unwrap() -} - -pub fn last_expect(v: &[u32]) -> u32 { - *v.last().expect("passed an empty thing") -} - -fn main() {} diff --git a/tests/ui/doc/missing_panics_doc.stderr b/tests/ui/doc/missing_panics_doc.stderr deleted file mode 100644 index f3e613bc7..000000000 --- a/tests/ui/doc/missing_panics_doc.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:3:1 - | -LL | pub fn option_unwrap(v: &[T]) -> &T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:5:5 - | -LL | o.unwrap() - | ^^^^^^^^^^ - = note: `-D clippy::missing-panics-doc` implied by `-D warnings` - -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:8:1 - | -LL | pub fn option_expect(v: &[T]) -> &T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:10:5 - | -LL | o.expect("passed an empty thing") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:13:1 - | -LL | pub fn result_unwrap(v: &[T]) -> &T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:15:5 - | -LL | res.unwrap() - | ^^^^^^^^^^^^ - -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:18:1 - | -LL | pub fn result_expect(v: &[T]) -> &T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:20:5 - | -LL | res.expect("passed an empty thing") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:23:1 - | -LL | pub fn last_unwrap(v: &[u32]) -> u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:24:6 - | -LL | *v.last().unwrap() - | ^^^^^^^^^^^^^^^^^ - -error: docs for function which may panic missing `# Panics` section - --> $DIR/missing_panics_doc.rs:27:1 - | -LL | pub fn last_expect(v: &[u32]) -> u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first possible panic found here - --> $DIR/missing_panics_doc.rs:28:6 - | -LL | *v.last().expect("passed an empty thing") - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index 10aa436d6..d544a0b1a 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -151,3 +151,35 @@ pub fn debug_assertions() { debug_assert_eq!(1, 2); debug_assert_ne!(1, 2); } + +// all function must be triggered the lint. +// `pub` is required, because the lint does not consider unreachable items +pub mod issue10240 { + pub fn option_unwrap(v: &[T]) -> &T { + let o: Option<&T> = v.last(); + o.unwrap() + } + + pub fn option_expect(v: &[T]) -> &T { + let o: Option<&T> = v.last(); + o.expect("passed an empty thing") + } + + pub fn result_unwrap(v: &[T]) -> &T { + let res: Result<&T, &str> = v.last().ok_or("oh noes"); + res.unwrap() + } + + pub fn result_expect(v: &[T]) -> &T { + let res: Result<&T, &str> = v.last().ok_or("oh noes"); + res.expect("passed an empty thing") + } + + pub fn last_unwrap(v: &[u32]) -> u32 { + *v.last().unwrap() + } + + pub fn last_expect(v: &[u32]) -> u32 { + *v.last().expect("passed an empty thing") + } +} diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 183c262ce..39d97f083 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -83,5 +83,77 @@ note: first possible panic found here LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:158:5 + | +LL | pub fn option_unwrap(v: &[T]) -> &T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:160:9 + | +LL | o.unwrap() + | ^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:163:5 + | +LL | pub fn option_expect(v: &[T]) -> &T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:165:9 + | +LL | o.expect("passed an empty thing") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:168:5 + | +LL | pub fn result_unwrap(v: &[T]) -> &T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:170:9 + | +LL | res.unwrap() + | ^^^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:173:5 + | +LL | pub fn result_expect(v: &[T]) -> &T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:175:9 + | +LL | res.expect("passed an empty thing") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:178:5 + | +LL | pub fn last_unwrap(v: &[u32]) -> u32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:179:10 + | +LL | *v.last().unwrap() + | ^^^^^^^^^^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> $DIR/missing_panics_doc.rs:182:5 + | +LL | pub fn last_expect(v: &[u32]) -> u32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first possible panic found here + --> $DIR/missing_panics_doc.rs:183:10 + | +LL | *v.last().expect("passed an empty thing") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 13 previous errors