Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clippy_lints/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clippy_utils::macros::{is_panic, root_macro_call_first_node};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::visitors::Visitable;
use clippy_utils::{is_entrypoint_fn, is_trait_impl_item, method_chain_args};
use clippy_utils::{is_trait_impl_item, method_chain_args};
use pulldown_cmark::Event::{
Code, DisplayMath, End, FootnoteReference, HardBreak, Html, InlineHtml, InlineMath, Rule, SoftBreak, Start,
TaskListMarker, Text,
Expand Down Expand Up @@ -658,9 +658,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
);
match item.kind {
ItemKind::Fn { sig, body: body_id, .. } => {
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id())
|| item.span.in_external_macro(cx.tcx.sess.source_map()))
{
if !(item.span.in_external_macro(cx.tcx.sess.source_map())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems the extra parentheses () is unnecessary here.

Suggested change
if !(item.span.in_external_macro(cx.tcx.sess.source_map())) {
if !item.span.in_external_macro(cx.tcx.sess.source_map()) {

let body = cx.tcx.hir_body(body_id);

let panic_info = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(item.owner_id), body.value);
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/issue_14491.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@aux-build:macro_rules.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd prefer to have this test together in tests/ui/missing_panics_doc.rs.

#![deny(clippy::missing_panics_doc)]
#![deny(clippy::missing_errors_doc)]
#![deny(clippy::allow_attributes)]

use std::env::var;

pub fn f() -> Result<(), &'static str> {
//~^ missing_errors_doc
match "test" {
"hello" => Ok(()),
_ => Err("Oh no"),
}
}

pub fn g() {
//~^ missing_panics_doc
panic!();
}

#[expect(clippy::missing_panics_doc)]
#[expect(clippy::missing_errors_doc)]
pub fn main() -> Result<(), &'static str> {
let val = var("Hello").unwrap();
match val.as_str() {
"hello" => Ok(()),
_ => Err("Oh no"),
}
}
31 changes: 31 additions & 0 deletions tests/ui/issue_14491.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error: docs for function returning `Result` missing `# Errors` section
--> tests/ui/issue_14491.rs:8:1
|
LL | pub fn f() -> Result<(), &'static str> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> tests/ui/issue_14491.rs:3:9
|
LL | #![deny(clippy::missing_errors_doc)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for function which may panic missing `# Panics` section
--> tests/ui/issue_14491.rs:16:1
|
LL | pub fn g() {
| ^^^^^^^^^^
|
note: first possible panic found here
--> tests/ui/issue_14491.rs:18:5
|
LL | panic!();
| ^^^^^^^^
note: the lint level is defined here
--> tests/ui/issue_14491.rs:2:9
|
LL | #![deny(clippy::missing_panics_doc)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors