Equality constraints on associated constants · Issue #70256 · rust-lang/rust (original) (raw)
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 },
/// E.g., A = 0
in Foo<A = 0>
.
EqualityConst { ct: AnonConst },
/// E.g. A: TraitA + TraitB
in Foo<A: TraitA + TraitB>
.
Bound { bounds: GenericBounds },
}