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

panic_in_result_fn cannot be allowed for a single statement or block #10493

Closed
SanchithHegde opened this issue Mar 12, 2023 · 1 comment
Closed
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@SanchithHegde
Copy link

Summary

It seems the panic_in_result_fn lint cannot be allowed for a single statement or block of code, and must be allowed for the entire function. I'd like to know if this is intentional behavior, or is there a possibility of having it ignored for a specific block of code?

I noticed this after a "fake return edge" was added to the instrument macro in the tracing-attributes crate (tokio-rs/tracing#2270) which triggers the panic_in_result_fn clippy lint in our codebase. I tried to allow the lint for only that block of code, but it seems that the lint can only be allowed for the entire function, which I'd prefer not to do, as it would allow calling panicking code elsewhere in the function. (I'd opened tokio-rs/tracing#2498 on the tracing repo, was suggested that I open an issue here.)

I'm not sure if this specific scenario should be ignored by clippy, as it is triggered by code generated by an external attribute macro.

Reproducer

I tried these code snippets (similar to the code found in tracing):

#![warn(clippy::panic_in_result_fn)]

fn main() -> Result<(), ()> {
    if false {
        #[allow(clippy::panic_in_result_fn)]
        unreachable!();
    }
    
    Ok(())
}
#![warn(clippy::panic_in_result_fn)]

fn main() -> Result<(), ()> {
    #[allow(clippy::panic_in_result_fn)]
    if false {
        unreachable!();
    }
    
    Ok(())
}

I expected that clippy would ignore the lint for the specific statement and/or if block.

Instead, clippy still emits the panic_in_result_fn warning.

The only way I'm able to allow the lint is to allow it for the entire function:

#![warn(clippy::panic_in_result_fn)]

#[allow(clippy::panic_in_result_fn)]
fn main() -> Result<(), ()> {
    if false {
        unreachable!();
    }
    
    Ok(())
}

Version

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: aarch64-apple-darwin
release: 1.68.0
LLVM version: 15.0.6

Additional Labels

No response

@SanchithHegde SanchithHegde added the C-bug Category: Clippy is not doing the correct thing label Mar 12, 2023
@SanchithHegde
Copy link
Author

The problem I faced with the tracing-attributes crate has been fixed in the Rust 1.73 clippy update, by #11123. Closing this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant