Skip to content

saturating arithmetic methods don’t work in const fn #1349

@sbillig

Description

@sbillig

P2 Badge Keep saturating methods evaluable during CTFE

Replacing the per-type Fe implementations with calls to __saturating_* makes every const/array-length/other CTFE use of saturating_add/sub/mul hit an extern. CtfeInterpreter::eval_extern_const_fn only handles __as_bytes and __keccak256 (crates/hir/src/analysis/ty/ctfe.rs:1414), so expressions like const N: u8 = 255u8.saturating_add(1); now regress from being foldable to ConstEvalUnsupported. The old bodies in num.fe were plain Fe code, so this is a new user-visible loss of functionality in compile-time contexts.

Originally posted by @chatgpt-codex-connector[bot] in #1347 (comment)

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