about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-02-12 20:48:05 +0000
committerbors <bors@rust-lang.org>2021-02-12 20:48:05 +0000
commit047f3e16bfc158717c6aeaa152a31eb42f3b9f04 (patch)
treeff96936da735095202299af89ef74dd05c07ef42
parent605e9ba3d7fa9e42afcdee5fd94c95f771693d07 (diff)
parent37f978299e514c977e747d0212fa72c2b1a86d11 (diff)
downloadrust-047f3e16bfc158717c6aeaa152a31eb42f3b9f04.tar.gz
rust-047f3e16bfc158717c6aeaa152a31eb42f3b9f04.zip
Auto merge of #6700 - daxpedda:panics-doc-unreachable, r=llogiq
Fix missing_panics_doc warning on `unreachable!`.

Fixes #6699.

Are there any other test-cases I should cover?

changelog: [`missing_panics_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc): No longer lints on [`unreachable!`](https://doc.rust-lang.org/std/macro.unreachable.html)
-rw-r--r--clippy_lints/src/doc.rs5
-rw-r--r--tests/ui/doc_panics.rs27
-rw-r--r--tests/ui/doc_panics.stderr21
3 files changed, 50 insertions, 3 deletions
diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs
index 1348f7530f4..ae06c2c60be 100644
--- a/clippy_lints/src/doc.rs
+++ b/clippy_lints/src/doc.rs
@@ -1,6 +1,6 @@
 use crate::utils::{
-    implements_trait, is_entrypoint_fn, is_type_diagnostic_item, match_panic_def_id, method_chain_args, return_ty,
-    span_lint, span_lint_and_note,
+    implements_trait, is_entrypoint_fn, is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args,
+    return_ty, span_lint, span_lint_and_note,
 };
 use if_chain::if_chain;
 use itertools::Itertools;
@@ -699,6 +699,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
             if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind;
             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();
             then {
                 self.panic_span = Some(expr.span);
             }
diff --git a/tests/ui/doc_panics.rs b/tests/ui/doc_panics.rs
index 7ef932f367b..3008c2d5b85 100644
--- a/tests/ui/doc_panics.rs
+++ b/tests/ui/doc_panics.rs
@@ -28,6 +28,15 @@ pub fn inner_body(opt: Option<u32>) {
     });
 }
 
+/// This needs to be documented
+pub fn unreachable_and_panic() {
+    if true {
+        unreachable!()
+    } else {
+        panic!()
+    }
+}
+
 /// This is documented
 ///
 /// # Panics
@@ -69,6 +78,19 @@ 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");
@@ -93,3 +115,8 @@ fn inner_body_private(opt: Option<u32>) {
         }
     });
 }
+
+/// 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
index c0c4e9e4fa7..287148690d2 100644
--- a/tests/ui/doc_panics.stderr
+++ b/tests/ui/doc_panics.stderr
@@ -63,5 +63,24 @@ LL |             panic!()
    |             ^^^^^^^^
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: aborting due to 4 previous errors
+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 {
+LL | |         unreachable!()
+LL | |     } else {
+LL | |         panic!()
+LL | |     }
+LL | | }
+   | |_^
+   |
+note: first possible panic found here
+  --> $DIR/doc_panics.rs:36:9
+   |
+LL |         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