-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Should enum discriminants have generics in scope? #70453
Copy link
Copy link
Closed
Labels
P-mediumMedium priorityMedium priorityT-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.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
P-mediumMedium priorityMedium priorityT-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.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
What are our options?
rustc_resolve) to hideenumgeneric parameters from the discriminant expression!=bounds# by using the same approach as in typeck: always expose repeat countAnonConsts' parent ingenerics_of. #70452, asenums are in a similar situation that shouldn't cause query cyclesAnonConsts' parent ingenerics_of. #70825 for thisExamples of current behavior:
Note:
#![feature(const_generics)]is used below so that this special-case kicks in:rust/src/librustc_typeck/collect.rs
Lines 1183 to 1185 in 62c6006
Also, note that the reason for the uniform current treatment (which doesn't consider
enumparameters as not in scope of discriminants), is becauserustc_resolvetreats surrounding generics as being in scope ofAnonConsts, always - all the bugs later in compilation are due to the lack of lazy normalization (see #43408).This ICEs currently (playground):
with
Same thing happens if a
constparameter is used instead ofsize_of::<T>().If we choose option 2, this ICE will turn into a regular error.
EDIT: and this currently compiles on nightly (playground):
And using
*mut *mut Tinstead of*mut Twould make it work even whenT: Sizedisn't known.(If not for the substitution failure, you could remove
#![feature(const_generics)])cc @rust-lang/compiler @rust-lang/lang