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

Closed
tesuji opened this issue May 18, 2024 · 0 comments · Fixed by #12840
Closed

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

tesuji opened this issue May 18, 2024 · 0 comments · 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
bors added a commit that referenced this issue Jun 19, 2024
Don't lint `assertions-on-constants` on any const assertions

changelog: Don't lint `assertions-on-constants` on any const assertions
changelog: fix false-positive of `unnecessary-operation` lint in const contexts.

close #12816
close #12847
cc #12817
@bors bors closed this as completed in c412528 Jul 1, 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