Skip to content

Equality constraints on associated constants #70256

Closed
@Centril

Description

@Centril

We currently do not support any way to constrain an associated constant as needing to be equal to some constant value. The natural way to achieve this would be to, by analogy with e.g., Foo<0>, also allow Foo<ID = 0>. The same disambiguation rules would apply as for Foo<X> in terms of when a block { ... } is needed, e.g., Foo<ID = { N + 1 }>.

In compiler internal terms, we would redefine ast::AssocTyConstraintKind as:

/// The kinds of an `AssocConstraint`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum AssocConstraintKind {
    /// E.g., `A = Bar` in `Foo<A = Bar>`.
    EqualityTy { ty: P<Ty> },
    /// E.g., `A = 0` in `Foo<A = 0>`.
    EqualityConst { ct: AnonConst },
    /// E.g. `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`.
    Bound { bounds: GenericBounds },
}

cc @varkor @eddyb

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-parserArea: The lexing & parsing of Rust source code to an ASTA-trait-systemArea: Trait systemA-type-systemArea: Type systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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