-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
CTFE keeps values in padding, breaking structural equality of const generic args. #70889
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-valtreeArea: Value trees or fixed by value treesArea: Value trees or fixed by value treesC-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-valtreeArea: Value trees or fixed by value treesArea: Value trees or fixed by value treesC-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This example should do one of these three things, but it doesn't (playground):
PADDED == FILLEDafter all, field-wise)FILLED's definition (due to evaluated constant not fitting type)FILLEDis used as an argument toPhantomInstead,
Phantom<PADDED>andPhantom<FILLED>are considered different types.If we want to make it compile, we could normalize
FILLEDto also have that padding byte marked as "undef", but I'm not sure if we can do this normalization if the values were behind a reference.So we might want to error if e.g.
&[0u8; 4]was transmuted to&(u8, u16), because normalizing it would change what runtime code would see. Again, we have two places where we can error.If we want to error without causing no breaking changes, either always or just indirect case, we can do so by introducing a second, stricter, validity check in
ty::ConstWell-Formed rules (which we should be able to post-#70107).That check should enforce that the value is a tree of constructors (
&_would be treated as a constructor) with integer leaves (no relocations, i.e. no raw/fnpointers), where any user ADTs are structurally-matchable, and all padding bytes (not occupied by leaves) are "undef".cc @rust-lang/wg-const-eval @varkor @yodaldevoid