Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous generic arguments #42

Open
lcnr opened this issue Mar 24, 2022 · 0 comments
Open

Ambiguous generic arguments #42

lcnr opened this issue Mar 24, 2022 · 0 comments
Labels
C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-optional Priority: not strictly required S-active

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 24, 2022

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.

@lcnr lcnr added C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-optional Priority: not strictly required S-active labels Mar 24, 2022
@rust-lang rust-lang locked and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-design-docs Category: This is part of our design documentation K-behavior Document Kind: regarding user visible behavior P-optional Priority: not strictly required S-active
Projects
None yet
Development

No branches or pull requests

1 participant