-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
anonymous constants are overly restrictive wrt variance #90629
Comments
@rustbot label +A-variance |
The current plan as I understand it is for these to continue to be allowed: impl SadBee for for<'a> fn(&'a ()) {
const ASSOC: usize = 0;
}
// This `impl` is more generic than your but still covers fn(`&'static ()`)
// (and any other `fn(&'concrete_lifetime U)`)
impl<T> SadBee for fn(T) {
const ASSOC: usize = 100;
} But I'm unsure if that's a problem for you or not. |
yeah, subtyping also impacts struct UsesRef<'a> {
actual_ref: &'a (),
in_anon_const: [u8; std::mem::size_of::<&'a ()>()],
} but that requires a bunch of additional design so I will only track that in rust-lang/project-const-generics#32 Thanks for reminding me that this issue exists 😅 |
cc #89829 (comment)
this currently causes an error as
'a
is considered invariant because it is used in an anonymous constant.This shouldn't actually be needed for
std::mem::size_of
as it doesn't care about variance.Once stuff like the following causes an error (instead of a future imcompat lint, cc #56105), subtyping should not be able to influence const eval, so we could allow lifetimes used in constants to remain bivariant. It is not clear that we should do that, as this restriction on subtyping is definitely not obvious or even necessarily desirable.
The text was updated successfully, but these errors were encountered: