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
We currently do not correctly deal with ambiguous generic arguments, preventing the following example from compiling:
struct N;
struct UsesParam<const M: usize>;
// `N` is both in the type and value namespace, so the compiler
// doesn't know whether `N` is a const or type parameter.
//
// For backwards compatibility, it always gets inferred to be a
// type parameter for now.
fn foo<const N: usize>() -> UsesParam<N> { UsesParam }
That's unfortunate and should be changed.
This also affects ()
, see rust-lang/rust#66615 for previous discussions about this.
This also affects unit structs, e.g. struct Empty;
, see rust-lang/rust#67075 for a previous discussion about this.
This also affects _
, currently unstable as feature(generic_arg_infer)
, tracked in rust-lang/rust#85077. The current implementation of that feature is somewhat brittle however.
While not strictly ambiguous, we also forbid multi-segment paths, see rust-lang/rust#77773 (comment) for context.