You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trait solver fails to see trait is implemented for all values of const generic param #145133
traitRandomTrait{typeItem;}structBoolWrapper<constVAL:bool>;implRandomTraitforBoolWrapper<true>{typeItem = String;}implRandomTraitforBoolWrapper<false>{typeItem = i32;}// RandomTrait is now implemented for all possible values// of the constant generic parameter of BoolWrapper. There// exists no bool X for which BoolWrapper<X> does not// implement RandomTrait.//// And yet...traitBoolWrapperTypeConstructor{typeOf<constVAL:bool>:RandomTrait;}structBoolWrapperFamily;implBoolWrapperTypeConstructorforBoolWrapperFamily{typeOf<constVAL:bool> = BoolWrapper<VAL>;}
I expected the code to compile, as RandomTrait is implemented for all 'flavors' of BoolWrapper.
Instead, the trait solver does not recognize that true and false are the only possible values a bool can have, and assumes that RandomTrait is not implemented for all possible types constructable by BoolWrapper.
This surprises me since a match expression can, in fact, recognize at compile-time whether all possible variants/values of a type are handled, in even more sophisticated ways than possible with const generics.
I'm inclined to close this as a duplicate of rust-lang/project-const-generics#26 but on the other hand it'd be nice if we had a corresp. r-l/r issue, wouldn't it?
Activity
fmease commentedon Aug 8, 2025
I'm not sure if we have a r-l/r issue for this but this is basically a duplicate of / tracked in rust-lang/project-const-generics#26.
CC #104803, rust-lang/a-mir-formality#132.
fmease commentedon Aug 8, 2025
I'm inclined to close this as a duplicate of rust-lang/project-const-generics#26 but on the other hand it'd be nice if we had a corresp. r-l/r issue, wouldn't it?