a-mir-formality icon indicating copy to clipboard operation
a-mir-formality copied to clipboard

Add `covering set` impl for generic version of trait when all values of a const are covered by impls

Open JulianKnodt opened this issue 2 years ago • 10 comments

When a trait contains a const: i.e. Foo<const C: bool>, if T : Foo<True>, T: Foo<False>, we should permit T : Foo<const C: bool> to be true. This can currently be emulated using specialization (altho how to do that I'm not sure), but this makes it unnecessary to use that feature to get this functionality.

I've currently only implemented it for bools (and I'm not sure if this implementation is sufficiently functional), but I'm not sure how generic it should be here

Is there a particular reason that an emoji is being used for the file extension?

p.s some changes are from running cargo fmt

JulianKnodt avatar Aug 03 '23 07:08 JulianKnodt

cross linking original Rust PR for easier discoverability: https://github.com/rust-lang/rust/pull/104803

oli-obk avatar Jan 15 '24 14:01 oli-obk

I've currently only implemented it for bools (and I'm not sure if this implementation is sufficiently functional), but I'm not sure how generic it should be here

if we have this feature it should work for arbitrary types

BoxyUwU avatar Jan 15 '24 15:01 BoxyUwU

if we have this feature it should work for arbitrary types

well, at least for types that match exhaustiveness can handle ^^

oli-obk avatar Jan 16 '24 10:01 oli-obk

all const generic types should have that property or else we've made a bit of a mess of the structuraleq thing i think haha

BoxyUwU avatar Jan 16 '24 12:01 BoxyUwU

I would appreciate some guidance on how to implement such things (or at least comment on what I've implemented), as this repo has poor documentation and uses esoteric syntax and vocabulary

JulianKnodt avatar Jan 30 '24 05:01 JulianKnodt

Who is actually reviewing this PR? Is it @nikomatsakis? How do I update tests so they do not use absolute paths in CI?

I would also note that there is no concept of structural equality or enums in this repo, so if you wanted me to add it for all kinds of ints, that would just be manually adding all of them.

Also adding in checks that fields of structs are all covered is also not something that is feasible in this repo since there are no existing tests with fields in structs.

If these points apply to the original PR, I'd appreciate if you could mark it there instead.

JulianKnodt avatar Feb 05 '24 01:02 JulianKnodt

I'll try assigning this review to those that provided feedback in #104803 (hope it helps to get some feedback). Please feel free to reassign, in case.

cc @lcnr

r? @oli-obk

apiraino avatar Jun 17 '24 13:06 apiraino

@JulianKnodt sorry I've let this sit so long! I can review it if you want to rebase, but I'd like to know a bit of context first. Is this something we've implemented in rustc already, or something you are proposing (for example)?

nikomatsakis avatar Jul 11 '24 13:07 nikomatsakis

It was implemented in rustc, but never landed due to concerns about generalizing it to types other than booleans: https://github.com/rust-lang/rust/pull/104803

oli-obk avatar Jul 11 '24 13:07 oli-obk

If you'd like to review it that'd be great. I haven't looked at this or rustc for a while, but I still think that adding this would be good (even if my recollection is that the impl is a bit naive or limited in scope). It's currently a feature for if a struct with a generic const struct Example<const B: bool> has the implementations impl Trait for Example<true> and impl Trait for Example<false>, it then generically implements the trait: Example<const B>: Trait.

The bool case is the most common, next may be enums, and then int would be next.

JulianKnodt avatar Jul 11 '24 19:07 JulianKnodt