Skip to content

Make clippy less noisy when asserting in const fn context #11963

@StackOverflowExcept1on

Description

@StackOverflowExcept1on

Description

This code gets 2 warnings:

  1. constant is not used even if it is actually used in the const assert!()
  2. clippy found that the assertion is always true and can be optimized, although this code can be used as a replacement for static_assertions (which has not been updated for 4 years)
const X: usize = 5;

#[allow(dead_code, clippy::assertions_on_constants)]
const _: () = assert!(X % 5 == 0);
// ^ equivalent of static_assertions

Version

No response

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions