Skip to content

nonminimal_bool suggestion is inaccurate for macros #9428

Closed
@dswij

Description

@dswij

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions