Skip to content

nonminimal_bool suggestion is inaccurate for macros #9428

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

Closed
dswij opened this issue Sep 5, 2022 · 1 comment · Fixed by #9457
Closed

nonminimal_bool suggestion is inaccurate for macros #9428

dswij opened this issue Sep 5, 2022 · 1 comment · Fixed by #9457
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@dswij
Copy link
Member

dswij commented Sep 5, 2022

Summary

Suggestion produced by nonminimal_bool is broken when it handles macros. It replaces the macro callsite with macro definition instead.

Reproducer

I tried this code:

if matches!(true, true) && true {
    println!("foo");
}

I expected to see this happen:
Suggestion does not expand macros

Instead, this happened:
It replace macros with its definition.

error: this boolean expression can be simplified
  --> $DIR/nonminimal_bool.rs:22:8
   |
LL |     if matches!(true, true) && true {}
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: try
   |
LL ~     if match $expression {
LL +             $( $pattern )|+ $( if $guard )? => true,
LL +             _ => false
LL ~         } {}
   |

Version

rustc 1.65.0-nightly (c07a8b4e0 2022-08-26)
binary: rustc
commit-hash: c07a8b4e09f356c7468b69c50cac7fc5b5000b8a
commit-date: 2022-08-26
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

Additional Labels

No response

@dswij dswij added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Sep 5, 2022
@dswij
Copy link
Member Author

dswij commented Sep 5, 2022

This won't be fixed by #9410, since the lint is not using Sugg helper when creating the suggestion.

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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant