-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Allow calling const unsafe fn
in const fn
behind a feature gate
#55635
Changes from all commits
f2ae7b7
906a49e
cc3470c
02b2232
ec6573f
693c553
8bdb11c
14218e3
c4a8500
081c497
1894a5f
55abc0b
e5d9065
4497ff3
37ef5e4
3ce211d
137a640
ae0b00c
b75d5f1
932dbe8
b779694
f411576
cb71752
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 |
---|---|---|
|
@@ -98,12 +98,18 @@ macro_rules! newtype_index { | |
@max [$max:expr] | ||
@vis [$v:vis] | ||
@debug_format [$debug_format:tt]) => ( | ||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)] | ||
#[derive(Copy, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)] | ||
#[rustc_layout_scalar_valid_range_end($max)] | ||
$v struct $type { | ||
private: u32 | ||
} | ||
|
||
impl Clone for $type { | ||
fn clone(&self) -> Self { | ||
*self | ||
} | ||
} | ||
|
||
impl $type { | ||
$v const MAX_AS_U32: u32 = $max; | ||
|
||
|
@@ -145,7 +151,7 @@ macro_rules! newtype_index { | |
|
||
#[inline] | ||
$v const unsafe fn from_u32_unchecked(value: u32) -> Self { | ||
$type { private: value } | ||
unsafe { $type { private: value } } | ||
} | ||
|
||
/// Extract value of this index as an integer. | ||
|
@@ -328,12 +334,13 @@ macro_rules! newtype_index { | |
derive [$($derives:ident,)+] | ||
$($tokens:tt)*) => ( | ||
newtype_index!( | ||
@derives [$($derives,)+ RustcDecodable, RustcEncodable,] | ||
@derives [$($derives,)+ RustcEncodable,] | ||
@type [$type] | ||
@max [$max] | ||
@vis [$v] | ||
@debug_format [$debug_format] | ||
$($tokens)*); | ||
newtype_index!(@decodable $type); | ||
); | ||
|
||
// The case where no derives are added, but encodable is overridden. Don't | ||
|
@@ -360,12 +367,29 @@ macro_rules! newtype_index { | |
@debug_format [$debug_format:tt] | ||
$($tokens:tt)*) => ( | ||
newtype_index!( | ||
@derives [RustcDecodable, RustcEncodable,] | ||
@derives [RustcEncodable,] | ||
@type [$type] | ||
@max [$max] | ||
@vis [$v] | ||
@debug_format [$debug_format] | ||
$($tokens)*); | ||
newtype_index!(@decodable $type); | ||
); | ||
|
||
(@decodable $type:ident) => ( | ||
impl $type { | ||
fn __decodable__impl__hack() { | ||
mod __more_hacks_because__self_doesnt_work_in_functions { | ||
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. Heh, feel free to add a comment about using 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. If you use 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. Well... I wouldn't bank on 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. absolute paths don't work, because not all crates have 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. Right, I was hoping that wouldn't be a problem but... we'll have to wait for serde/some rustc-specific custom serialization solution, post-#49219. |
||
extern crate serialize; | ||
use self::serialize::{Decodable, Decoder}; | ||
impl Decodable for super::$type { | ||
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> { | ||
d.read_u32().map(Self::from) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
// Rewrite final without comma to one that includes comma | ||
|
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.
Glad this is not exported anymore!