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

Overly restrictive variance #32

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

Overly restrictive variance #32

lcnr opened this issue Mar 23, 2022 · 0 comments
Labels
A-generic-exprs Generic const expressions A-unification Unifying constants in the type system 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-blocked

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 23, 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

Currently all generic parameters used by constants in the type system are constrained
to be invariant. Looking at this example, that is unnecessary:

struct UsesRef<'a> {
    actual_ref: &'a (),
    in_anon_const: [u8; std::mem::size_of::<&'a ()>()],
}

Here 'a is forced to be invariant, as it is used in the anonymous constant, but
ideally it should be covariant.

How variance can influence CTFE

The most obvious example is TypeId::of which has to differ between for<'a> fn(&'a ()) and fn(&'static ()) and for<'a> fn(fn(&'a ()) and fn(fn(&'static ()).

Higher ranked types act different during candidate selection and can therefore not simply be ignored. We currently have a future compatability lint for this in #56105 which will probably get allowed in the future.

@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-blocked A-generic-exprs Generic const expressions A-unification Unifying constants in the type system labels Mar 23, 2022
@rust-lang rust-lang locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-generic-exprs Generic const expressions A-unification Unifying constants in the type system 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-blocked
Projects
None yet
Development

No branches or pull requests

1 participant