diff options
| author | Yoshitomo Nakanishi <yurayura.rounin.3@gmail.com> | 2021-03-29 17:19:05 +0900 |
|---|---|---|
| committer | Yoshitomo Nakanishi <yurayura.rounin.3@gmail.com> | 2021-03-29 17:20:04 +0900 |
| commit | 31afdfc12bbe1bd2681ac17bfb07134ffd3cf061 (patch) | |
| tree | 2ad89b73d1183bc80070ae8e40f415e876c5e03c | |
| parent | 1f95940c24c63b0d196b4f889a68baed2b123086 (diff) | |
| download | rust-31afdfc12bbe1bd2681ac17bfb07134ffd3cf061.tar.gz rust-31afdfc12bbe1bd2681ac17bfb07134ffd3cf061.zip | |
missing_panics_doc: Ignore usage of debug_assert family
| -rw-r--r-- | clippy_lints/src/doc.rs | 6 | ||||
| -rw-r--r-- | tests/ui/missing_panics_doc.rs | 8 |
2 files changed, 14 insertions, 0 deletions
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<u32>) { 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); +} |
