Forbid the upper indices of IndexVec indices to allow for niche optimizations

This commit is contained in:
Oliver Schneider 2018-09-07 15:28:23 +02:00
parent d272e2f6e2
commit 06a041cbd3
5 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,20 @@
#![feature(rustc_attrs, step_trait, rustc_private)]
#[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);
}