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

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

Open
tesuji opened this issue May 18, 2024 · 0 comments · May be fixed by #12840
Open

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

tesuji opened this issue May 18, 2024 · 0 comments · May be fixed by #12840
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@tesuji
Copy link
Contributor

tesuji commented May 18, 2024

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

@tesuji tesuji added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 18, 2024
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-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant