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

if-then-panic suggestion discards comments #7730

Closed
ghost opened this issue Sep 28, 2021 · 0 comments · Fixed by #9479
Closed

if-then-panic suggestion discards comments #7730

ghost opened this issue Sep 28, 2021 · 0 comments · Fixed by #9479
Labels
C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ghost
Copy link

ghost commented Sep 28, 2021

I tried this code:

#![warn(clippy::if_then_panic)]

fn main() {
    if false { 
        // comment
        panic!("ABC"); 
    };
}

I expected to see this happen: The suggestion would preserve the comment somehow.

Instead, this happened: The suggestion discarded the comment.

warning: only a `panic!` in `if`-then statement
 --> src/main.rs:5:5
  |
5 | /     if false { 
6 | |         // comment
7 | |         panic!("ABC"); 
8 | |     };
  | |_____^ help: try: `assert!(!false, "ABC");`
  |

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (fdf65053e 2021-09-07)
binary: rustc
commit-hash: fdf65053e99e8966f9bd83b5a8491326cb33d638
commit-date: 2021-09-07
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot label +L-suggestion

@ghost ghost added the C-bug Category: Clippy is not doing the correct thing label Sep 28, 2021
@rustbot rustbot added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Sep 28, 2021
@bors bors closed this as completed in 11a6d19 Oct 2, 2022
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 L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant