Skip to content

Unnecessary assertion inside while i < *::MAX loop #75546

Closed
@MSxDOS

Description

@MSxDOS
pub fn test() {
    let mut i = 1u32;
    while i < u32::MAX {
        assert_ne!(i, 0, "No way...");
        i += 1;
    }
}

https://godbolt.org/z/oY5ra8

The assertion disappears when comparing against a non-MAX value for a given type, or with mir-opt-level 2 and above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions