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

Equality constraints on associated constants #70256

Closed
Centril opened this issue Mar 22, 2020 · 5 comments
Closed

Equality constraints on associated constants #70256

Centril opened this issue Mar 22, 2020 · 5 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-parser Area: The parsing of Rust source code to an AST A-traits Area: Trait system A-typesystem Area: The type system C-feature-request Category: A feature request, i.e: not implemented / a PR. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Mar 22, 2020

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 },
}

cc @varkor @eddyb

@Centril Centril added A-typesystem Area: The type system A-traits Area: Trait system A-parser Area: The parsing of Rust source code to an AST A-associated-items Area: Associated items (types, constants & functions) T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-const_generics `#![feature(const_generics)]` labels Mar 22, 2020
@Centril Centril self-assigned this Mar 22, 2020
@Centril
Copy link
Contributor Author

Centril commented Mar 22, 2020

I've assigned myself, as I will be fixing the parser / lowering aspects of this to start with.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2020
Move arg/constraint partition check to validation & improve recovery

- In the first commit, we move the check rejecting e.g., `<'a, Item = u8, String>` from the parser into AST validation.
- We then use this to improve the code for parsing generic arguments.
- And we add recovery for e.g., `<Item = >` (missing), `<Item = 42>` (constant), and `<Item = 'a>` (lifetime).

This is also preparatory work for supporting rust-lang#70256.

r? @varkor
@dr-orlovsky
Copy link

Any progress on this issue? I see the required changes were made in March, so it seems to be possible to add this feature for now?

@varkor
Copy link
Member

varkor commented Sep 27, 2020

I believe only (some of) the parsing aspects were addressed, and nothing more. There is still implementation left before this feature is even ready for a feature gate.

@Centril Centril removed their assignment Jul 14, 2021
@JulianKnodt
Copy link
Contributor

@varkor (cc @Centril) I can pick up the implementation of this (I actually ran into this issue within 2 hrs of starting a project), unless there's some reason otherwise.

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 18, 2022
…-obk

allow eq constraints on associated constants

Updates rust-lang#70256

(cc `@varkor,` `@Centril)`
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2022
…-obk

allow eq constraints on associated constants

Updates rust-lang#70256

(cc `@varkor,` `@Centril)`
@dtolnay dtolnay added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Mar 14, 2022
@dtolnay
Copy link
Member

dtolnay commented Mar 14, 2022

This has been implemented in nightly, so I am closing this feature request in favor of the tracking issue at #92827.

Per #92827 (comment), a lang team MCP is eventually going to be required, along with some medium sized doc explaining what is going on and why. @oli-obk will open a hackmd for folks to collaborate in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-parser Area: The parsing of Rust source code to an AST A-traits Area: Trait system A-typesystem Area: The type system C-feature-request Category: A feature request, i.e: not implemented / a PR. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants