-
-
Notifications
You must be signed in to change notification settings - Fork 15k
change newtype_index! to use Nonzero #45842
Copy link
Copy link
Closed
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.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.
Metadata
Metadata
Assignees
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
So now that @spastorino and @Nashenas88 have converted so much of the compiler to use
newtype_index!, I was thinking that we could change the implementation of all these index types fromstruct Foo(u32)tostruct Foo(Nonzero<u32>). This would require adding (and subtracting) 1 internally to convert from the actual index into its internal representation, but it would have the bonus that we couldOption<I>for some index typeIwould still be a single u32-sized value.This is somewhat hindered by the fact that at least one of these "newtype'd index" types has a public field. We should see if we can change that.
(And , of course, what I really want is something like
Nonmaxthat usesu32::MAXas the sentinel value, since that is not a useful index.)cc @arielb1, with whom I was discussing this general theme before. Think this could be a good idea? I'm not sure how much people really use
Option<I>.