-
Notifications
You must be signed in to change notification settings - Fork 13.9k
a collection of simple const changes #146600
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ macro_rules! define_valid_range_type { | |
$(#[$m:meta])* | ||
$vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal); | ||
)+) => {$( | ||
#[derive(Clone, Copy, Eq)] | ||
#[derive(Copy)] | ||
#[derive_const(Clone, Eq)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do that after the pattern types refactor lands. Otherwise I may just have to temporarily remove it again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ironically, this is the only change I actually need to constify all the slice and array types and their dependents. Are you sure this is blocked? I'll file a separate PR with that enablement path made obvious and request you as reviewer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I may have resolved this problem. |
||
#[repr(transparent)] | ||
#[rustc_layout_scalar_valid_range_start($low)] | ||
#[rustc_layout_scalar_valid_range_end($high)] | ||
|
@@ -67,21 +68,24 @@ macro_rules! define_valid_range_type { | |
// by <https://github.com/rust-lang/compiler-team/issues/807>. | ||
impl StructuralPartialEq for $name {} | ||
|
||
impl PartialEq for $name { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] | ||
impl const PartialEq for $name { | ||
#[inline] | ||
fn eq(&self, other: &Self) -> bool { | ||
self.as_inner() == other.as_inner() | ||
} | ||
} | ||
|
||
impl Ord for $name { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] | ||
impl const Ord for $name { | ||
#[inline] | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
Ord::cmp(&self.as_inner(), &other.as_inner()) | ||
} | ||
} | ||
|
||
impl PartialOrd for $name { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] | ||
impl const PartialOrd for $name { | ||
#[inline] | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(Ord::cmp(self, other)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ use crate::pin::Pin; | |
/// This enum is returned from the `Coroutine::resume` method and indicates the | ||
/// possible return values of a coroutine. Currently this corresponds to either | ||
/// a suspension point (`Yielded`) or a termination point (`Complete`). | ||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] | ||
#[derive(Copy, Debug, Hash)] | ||
#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
#[lang = "coroutine_state"] | ||
#[unstable(feature = "coroutine_trait", issue = "43122")] | ||
pub enum CoroutineState<Y, R> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coroutines have no support for getting polled in const code. Let's pair this constification with actual coroutine constifications |
||
|
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.
Doing anything const in this module is a bit confusing as we can't actually make anything interesting const. I'd rather not change anything in the fmt machinery that isn't clearly connected to a use case