generated from rust-lang/project-group-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
A-generic-exprsGeneric const expressionsGeneric const expressionsA-unificationUnifying constants in the type systemUnifying constants in the type systemC-design-docsCategory: This is part of our design documentationCategory: This is part of our design documentationK-behaviorDocument Kind: regarding user visible behaviorDocument Kind: regarding user visible behaviorP-necessaryPriority: will be needed at some pointPriority: will be needed at some pointS-active
Description
What is this
This is a design document for const generics. Any discussions about its content should be on zulip. The conclusions of these discussions should then be edited back into this issue. Please do not post any comments directly in this issue.
Content
Given an impl, the compiler has to be able to decide the generic arguments used by that impl.
Consider the following snippet:
struct Weird<const N: usize>;
impl<const A: usize, const B: usize> Weird<{ A + B }> {
fn returns_a() -> usize {
A
}
}
When calling Weird::<3>::returns_a()
, there is no way to restrict the generic parameters A
or B
so this has to error.
If a generic parameter is used by an injective expression, then we could allow this. The most relevant case here are
constructors:
struct UsesOption<const N: Option<usize>>;
impl<const N: usize> UsesOption<{ Some(N) }> {}
Here it is very clear which N
we should use given UsesOption::<{ Some(3) }>
.
TODO: blocked on structural equality.
Metadata
Metadata
Assignees
Labels
A-generic-exprsGeneric const expressionsGeneric const expressionsA-unificationUnifying constants in the type systemUnifying constants in the type systemC-design-docsCategory: This is part of our design documentationCategory: This is part of our design documentationK-behaviorDocument Kind: regarding user visible behaviorDocument Kind: regarding user visible behaviorP-necessaryPriority: will be needed at some pointPriority: will be needed at some pointS-active