Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing_panics_doc shouldn't warn on unreachable! #6699

Closed
daxpedda opened this issue Feb 8, 2021 · 0 comments · Fixed by #6700
Closed

missing_panics_doc shouldn't warn on unreachable! #6699

daxpedda opened this issue Feb 8, 2021 · 0 comments · Fixed by #6700

Comments

@daxpedda
Copy link
Contributor

daxpedda commented Feb 8, 2021

Lint name:
missing_panics_doc

I tried this code:

pub fn unreachable() {
    unreachable!("This function panics")
}

I expected to see this happen:
No warning.

As noted by @dtolnay in #1791 (comment):

I think requiring this when calling known-panicky functions is extreme. Often something is unwrapped because it is expected to never fail. That's not something you can explain to the caller. "This function panics if... the code is wrong"?

Requiring a "Panics" section if the function uses specifically panic! would be good. If it can panic, it should be documented. If it can't panic, they should have used unreachable! instead.

Instead, this happened:

Warnings:
error: docs for function which may panic missing `# Panics` section
  --> $DIR/doc_panics.rs:98:1
   |
LL | / pub fn unreachable() {
LL | |     unreachable!("This function panics")
LL | | }
   | |_^
   |
note: first possible panic found here
  --> $DIR/doc_panics.rs:99:5
   |
LL |     unreachable!("This function panics")
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Meta

  • cargo clippy -V: clippy 0.1.51 (3682750 2021-02-02)
  • rustc -Vv:
    rustc 1.51.0-nightly (368275062 2021-02-02)
    binary: rustc
    commit-hash: 368275062fb655c1f36e0398f88b15379a1f3c93
    commit-date: 2021-02-02
    host: x86_64-unknown-linux-gnu
    release: 1.51.0-nightly
    LLVM version: 11.0.1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant