Skip to content

Commit

Permalink
missing_panics_doc: Ignore usage of debug_assert family
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 29, 2021
1 parent 1f95940 commit 31afdfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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())
}
8 changes: 8 additions & 0 deletions tests/ui/missing_panics_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 31afdfc

Please sign in to comment.