Skip to content

Partially const traits #103265

Description

@the8472

#102225 attempts to constify Iterator which would be a stepping stone towards for _ in iter loops in const fns.

The trouble there is that #[const_trait] requires that all trait methods are const and Iterator has an ever-growing set of methods which now all would have to be constified even though we only really need Iterator::next to be const to enable iterator loops.
And not only do those methods themselves have to be const but their return types must be const-constructable. So this property is quite viral.

Since most of the const trait syntax is still experimental and full of placeholders this may result in an unnecessarily large maintenance burden for the standard library. Additionally it can also hinder future API evolution because it rules out adding impossible-to-constify methods.

From a libs perspective partially const traits would allow us to constify the minimal necessary API surface to unlock further experimentation.

Prior zulip discussion in which the const_trait hackmd was brought up. My reading of it suggests that partially const traits were primarily removed due to open design questions, not due to fundamental impossibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)F-const_trait_impl`#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions