Skip to content

assertions-on-constants incorrectly fails on const blocks #12816

Closed

Description

@tesuji

Summary

In ffi code, sometimes std defines types that may have incompatible layout with third-party codes (windows-sys).
To be more safe, one has to check the layout of a std type and another correspond type has the same layout.

Lint Name

assertions_on_constants

Reproducer

I tried this code:

const _: () = {
    assert!(8 == (7+1));
    // let std_layout = Layout::new::<RawHandle>();
    // let win_sys_layout = Layout::new::<HANDLE>();
    // assert!(std_layout.size() == win_sys_layout.size())
    // assert!(std_layout.align() == win_sys_layout.align())
};

I saw this happen:

error: `assert!(true)` will be optimized out by the compiler
  --> src/internals/c.rs:53:5
   |
53 |     assert!(8 == (7+1));
   |     ^^^^^^^^^^^^^^^^^^^
   |
   = help: remove it

I expected to see this happen: Don't lint.

Version

rustc 1.80.0-nightly (1a7397988 2024-05-17)
binary: rustc
commit-hash: 1a7397988684934ae01a71f524bdfff24895d8cc
commit-date: 2024-05-17
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on May 18, 2024
  2. added a commit that references this issue on Jun 19, 2024
    7de2cd7
  3. added a commit that references this issue on Jul 1, 2024
    c412528
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions