-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup const_fn! #255
Cleanup const_fn! #255
Conversation
Fixes #222 The following methods can be made `const` on stable: - `GlobalDescriptorTable::from_raw_slice` - `MappedFrame::{start_address, size}` - `Page<Size4KiB>::p1_index` The remaining functions still need `const_fn` because: - Some GDT methods use `&mut self` - The IDT uses function pointers as a type argument - The PageSize marker trait is used all over Comments were updated where appropriate. Signed-off-by: Joe Richey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks a lot!
Signed-off-by: Joe Richey <[email protected]>
#[cfg(feature = "const_fn")] | ||
assert!( | ||
next_free <= 8, | ||
"initializing a GDT from a slice requires it to be **at most** 8 elements." | ||
); | ||
#[cfg(not(feature = "const_fn"))] | ||
table[next_free]; // Will fail if slice.len() > 8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use assert!
in every case? Also, table[next_free]
panics if slice.len() >= 8
, not slice.len() > 8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert!
doesn't work as const panics are not yet stable. See: rust-lang/rust#85194
Good pont on the off-by-one error though, i'll fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephlr Did we end up fixing this yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I forgot about this. PR for fix: #269
I tried to remove the |
No, that's the right function. Building the crate with:
|
Ah, I didn't enable that feature and misunderstood the |
Fixes #222
The following methods can be made
const
on stable:GlobalDescriptorTable::from_raw_slice
MappedFrame::{start_address, size}
Page<Size4KiB>::p1_index
The remaining functions still need
const_fn
because:&mut self
Comments were updated where appropriate.
Signed-off-by: Joe Richey [email protected]