Closed
Description
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 },
}
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: The lexing & parsing of Rust source code to an ASTArea: Trait systemArea: Type systemCategory: A feature request, i.e: not implemented / a PR.`#![feature(const_generics)]`Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.