Skip to content

assertions_on_constants incorrectly lints indirect usage of cfg! #11964

Closed
@StackOverflowExcept1on

Description

@StackOverflowExcept1on

Summary

same as #7597 but with const in impl

Lint Name

assertions_on_constants

Reproducer

I tried this code:

pub fn f() {
    // const in impl
    struct Features;
    impl Features {
        const FOO: bool = cfg!(not(feature = "foo"));
    }
    assert!(Features::FOO);

    // const in trait
    trait MyTrait {
        const FOO: bool = cfg!(not(feature = "foo"));
    }
    impl MyTrait for () {}
    assert!(<()>::FOO);
}

I expected to see this happen: cfg!() is fixed

Instead, this happened:

warning: `assert!(true)` will be optimized out by the compiler
 --> src/lib.rs:7:5
  |
7 |     assert!(Features::FOO);
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |

Version

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions