Skip to content

Commit 31afdfc

Browse files
committed
missing_panics_doc: Ignore usage of debug_assert family
1 parent 1f95940 commit 31afdfc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clippy_lints/src/doc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
715715
if let Some(path_def_id) = path.res.opt_def_id();
716716
if match_panic_def_id(self.cx, path_def_id);
717717
if is_expn_of(expr.span, "unreachable").is_none();
718+
if !is_expn_of_debug_assertions(expr.span);
718719
then {
719720
self.panic_span = Some(expr.span);
720721
}
@@ -738,3 +739,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
738739
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
739740
}
740741
}
742+
743+
fn is_expn_of_debug_assertions(span: Span) -> bool {
744+
const MACRO_NAMES: &[&str] = &["debug_assert", "debug_assert_eq", "debug_assert_ne"];
745+
MACRO_NAMES.iter().any(|name| is_expn_of(span, name).is_some())
746+
}

tests/ui/missing_panics_doc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,11 @@ fn inner_body_private(opt: Option<u32>) {
112112
pub fn unreachable() {
113113
unreachable!("This function panics")
114114
}
115+
116+
/// #6970.
117+
/// This is okay because it is expansion of `debug_assert` family.
118+
pub fn debug_assertions() {
119+
debug_assert!(false);
120+
debug_assert_eq!(1, 2);
121+
debug_assert_ne!(1, 2);
122+
}

0 commit comments

Comments
 (0)