-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add forever unstable attribute to allow specifying arbitrary scalar ranges #54032
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
Merged
+279
−161
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d272e2f
Get rid of the `non_zero` lang item in favour of arbitrary range spec…
oli-obk 06a041c
Forbid the upper indices of `IndexVec` indices to allow for niche opt…
oli-obk 3828e9e
Use the same way to specifiy the `SCOPE_DATA_*` constants as used for…
oli-obk a2c924b
Satisfy tidy
oli-obk 833dc7e
Address attribute naming and use `Bound` enum
oli-obk 88ebb95
only allow restricting scalar layouts
oli-obk 24dca6a
Simplify Scope/ScopeData to have less chance of introducing UB or siz…
oli-obk d1b5231
Fix const eval of ZST index operations to make the static assertion work
oli-obk 1ec8670
Split `CrateNum` into an enum instead of having magic constants
oli-obk 8053f63
Rebase fallout
oli-obk 68298a5
Use assertion-like static assertions
oli-obk 5f42a0f
Change debug printing to print in the old concise style
oli-obk f3417c5
Properly access `std::mem::size_of`
oli-obk 79f2cc0
Silence dead code warning for the assertion statics
oli-obk a94c166
Add missing #![feature(min_const_fn)] to the newtype_index test.
eddyb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,8 @@ macro_rules! newtype_index { | |
newtype_index!( | ||
// Leave out derives marker so we can use its absence to ensure it comes first | ||
@type [$name] | ||
@max [::std::u32::MAX - 1] | ||
// shave off 256 indices at the end to allow space for packing these indices into enums | ||
@max [0xFFFF_FF00] | ||
@vis [$v] | ||
@debug_format ["{}"]); | ||
); | ||
|
@@ -82,7 +83,8 @@ macro_rules! newtype_index { | |
newtype_index!( | ||
// Leave out derives marker so we can use its absence to ensure it comes first | ||
@type [$name] | ||
@max [::std::u32::MAX - 1] | ||
// shave off 256 indices at the end to allow space for packing these indices into enums | ||
@max [0xFFFF_FF00] | ||
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. Ohhhh, this is clever! |
||
@vis [$v] | ||
@debug_format ["{}"] | ||
$($tokens)+); | ||
|
@@ -97,6 +99,7 @@ macro_rules! newtype_index { | |
@vis [$v:vis] | ||
@debug_format [$debug_format:tt]) => ( | ||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)] | ||
#[rustc_layout_scalar_valid_range_end($max)] | ||
$v struct $type { | ||
private: u32 | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![feature(min_const_fn, rustc_attrs, rustc_private, step_trait)] | ||
|
||
#[macro_use] extern crate rustc_data_structures; | ||
extern crate rustc_serialize; | ||
|
||
use rustc_data_structures::indexed_vec::Idx; | ||
|
||
newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA }); | ||
|
||
use std::mem::size_of; | ||
|
||
fn main() { | ||
assert_eq!(size_of::<MyIdx>(), 4); | ||
assert_eq!(size_of::<Option<MyIdx>>(), 4); | ||
assert_eq!(size_of::<Option<Option<MyIdx>>>(), 4); | ||
assert_eq!(size_of::<Option<Option<Option<MyIdx>>>>(), 4); | ||
assert_eq!(size_of::<Option<Option<Option<Option<MyIdx>>>>>(), 4); | ||
assert_eq!(size_of::<Option<Option<Option<Option<Option<MyIdx>>>>>>(), 4); | ||
assert_eq!(size_of::<Option<Option<Option<Option<Option<Option<MyIdx>>>>>>>(), 8); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// compile-pass | ||
|
||
static ASSERT: () = [()][!(std::mem::size_of::<u32>() == 4) as usize]; | ||
|
||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You probably want to use the
fmt.debug_struct
wrapper, to automate this.