提交 6ccf9b81 编写于 作者: N Niko Matsakis

change from tuple struct to brace struct

上级 5aee959e
......@@ -44,7 +44,7 @@ pub struct DepNodeIndex { .. }
}
impl DepNodeIndex {
const INVALID: DepNodeIndex = DepNodeIndex(::std::u32::MAX);
const INVALID: DepNodeIndex = DepNodeIndex { private: ::std::u32::MAX };
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
......@@ -1127,14 +1127,14 @@ fn get(&self, index: SerializedDepNodeIndex) -> Option<DepNodeColor> {
match self.values[index] {
COMPRESSED_NONE => None,
COMPRESSED_RED => Some(DepNodeColor::Red),
value => Some(DepNodeColor::Green(DepNodeIndex(value - COMPRESSED_FIRST_GREEN)))
value => Some(DepNodeColor::Green(DepNodeIndex { private: value - COMPRESSED_FIRST_GREEN })),
}
}
fn insert(&mut self, index: SerializedDepNodeIndex, color: DepNodeColor) {
self.values[index] = match color {
DepNodeColor::Red => COMPRESSED_RED,
DepNodeColor::Green(index) => index.0 + COMPRESSED_FIRST_GREEN,
DepNodeColor::Green(index) => index.private + COMPRESSED_FIRST_GREEN,
}
}
}
......@@ -41,15 +41,15 @@ pub struct CrateNum {
impl CrateNum {
pub fn new(x: usize) -> CrateNum {
assert!(x < (u32::MAX as usize));
CrateNum(x as u32)
CrateNum { private: x as u32 }
}
pub fn from_u32(x: u32) -> CrateNum {
CrateNum(x)
CrateNum { private: x }
}
pub fn as_usize(&self) -> usize {
self.0 as usize
self.private as usize
}
pub fn as_u32(&self) -> u32 {
......@@ -61,7 +61,7 @@ pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX
impl fmt::Display for CrateNum {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
fmt::Display::fmt(&self.private, f)
}
}
......
......@@ -165,7 +165,7 @@ pub struct FirstStatementIndex {
}
}
impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
impl From<ScopeData> for Scope {
#[inline]
......
......@@ -132,7 +132,7 @@ pub struct Mir<'tcx> {
}
/// where execution begins
pub const START_BLOCK: BasicBlock = BasicBlock(0);
pub const START_BLOCK: BasicBlock = BasicBlock { private: 0 };
impl<'tcx> Mir<'tcx> {
pub fn new(
......@@ -239,7 +239,7 @@ pub fn dominators(&self) -> Dominators<BasicBlock> {
#[inline]
pub fn local_kind(&self, local: Local) -> LocalKind {
let index = local.0 as usize;
let index = local.private as usize;
if index == 0 {
debug_assert!(
self.local_decls[local].mutability == Mutability::Mut,
......
......@@ -1274,7 +1274,7 @@ impl DebruijnIndex {
/// you would need to shift the index for `'a` into 1 new binder.
#[must_use]
pub const fn shifted_in(self, amount: u32) -> DebruijnIndex {
DebruijnIndex(self.0 + amount)
DebruijnIndex { private: self.private + amount }
}
/// Update this index in place by shifting it "in" through
......@@ -1287,7 +1287,7 @@ pub fn shift_in(&mut self, amount: u32) {
/// `amount` number of new binders.
#[must_use]
pub const fn shifted_out(self, amount: u32) -> DebruijnIndex {
DebruijnIndex(self.0 - amount)
DebruijnIndex { private: self.private - amount }
}
/// Update in place by shifting out from `amount` binders.
......@@ -1316,11 +1316,11 @@ pub fn shift_out(&mut self, amount: u32) {
/// bound by one of the binders we are shifting out of, that is an
/// error (and should fail an assertion failure).
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self {
self.shifted_out((to_binder.0 - INNERMOST.0) as u32)
self.shifted_out((to_binder.private - INNERMOST.private) as u32)
}
}
impl_stable_hash_for!(tuple_struct DebruijnIndex { index });
impl_stable_hash_for!(struct DebruijnIndex { private });
/// Region utilities
impl RegionKind {
......
......@@ -97,7 +97,9 @@ fn index(self) -> usize { self as usize }
@vis [$v:vis]
@debug_format [$debug_format:tt]) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
$v struct $type(u32);
$v struct $type {
private: u32
}
impl $type {
/// Extract value of this index as an integer.
......@@ -111,12 +113,12 @@ impl Idx for $type {
#[inline]
fn new(value: usize) -> Self {
assert!(value < ($max) as usize);
$type(value as u32)
$type { private: value as u32 }
}
#[inline]
fn index(self) -> usize {
self.0 as usize
self.private as usize
}
}
......@@ -151,13 +153,13 @@ fn add_usize(&self, u: usize) -> Option<Self> {
impl From<$type> for u32 {
fn from(v: $type) -> u32 {
v.0
v.private
}
}
impl From<$type> for usize {
fn from(v: $type) -> usize {
v.0 as usize
v.private as usize
}
}
......@@ -193,7 +195,7 @@ fn from(v: u32) -> Self {
@debug_format [$debug_format:tt]) => (
impl ::std::fmt::Debug for $type {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(fmt, $debug_format, self.0)
write!(fmt, $debug_format, self.private)
}
}
);
......@@ -376,7 +378,7 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
const $name:ident = $constant:expr,
$($tokens:tt)*) => (
$(#[doc = $doc])*
pub const $name: $type = $type($constant);
pub const $name: $type = $type { private: $constant };
newtype_index!(
@derives [$($derives,)*]
@type [$type]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册