Skip to content

Commit 6ccf9b8

Browse files
committed
change from tuple struct to brace struct
1 parent 5aee959 commit 6ccf9b8

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ newtype_index! {
4444
}
4545

4646
impl DepNodeIndex {
47-
const INVALID: DepNodeIndex = DepNodeIndex(::std::u32::MAX);
47+
const INVALID: DepNodeIndex = DepNodeIndex { private: ::std::u32::MAX };
4848
}
4949

5050
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@@ -1127,14 +1127,14 @@ impl DepNodeColorMap {
11271127
match self.values[index] {
11281128
COMPRESSED_NONE => None,
11291129
COMPRESSED_RED => Some(DepNodeColor::Red),
1130-
value => Some(DepNodeColor::Green(DepNodeIndex(value - COMPRESSED_FIRST_GREEN)))
1130+
value => Some(DepNodeColor::Green(DepNodeIndex { private: value - COMPRESSED_FIRST_GREEN })),
11311131
}
11321132
}
11331133

11341134
fn insert(&mut self, index: SerializedDepNodeIndex, color: DepNodeColor) {
11351135
self.values[index] = match color {
11361136
DepNodeColor::Red => COMPRESSED_RED,
1137-
DepNodeColor::Green(index) => index.0 + COMPRESSED_FIRST_GREEN,
1137+
DepNodeColor::Green(index) => index.private + COMPRESSED_FIRST_GREEN,
11381138
}
11391139
}
11401140
}

src/librustc/hir/def_id.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ newtype_index! {
4141
impl CrateNum {
4242
pub fn new(x: usize) -> CrateNum {
4343
assert!(x < (u32::MAX as usize));
44-
CrateNum(x as u32)
44+
CrateNum { private: x as u32 }
4545
}
4646

4747
pub fn from_u32(x: u32) -> CrateNum {
48-
CrateNum(x)
48+
CrateNum { private: x }
4949
}
5050

5151
pub fn as_usize(&self) -> usize {
52-
self.0 as usize
52+
self.private as usize
5353
}
5454

5555
pub fn as_u32(&self) -> u32 {
@@ -61,7 +61,7 @@ impl CrateNum {
6161

6262
impl fmt::Display for CrateNum {
6363
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64-
fmt::Display::fmt(&self.0, f)
64+
fmt::Display::fmt(&self.private, f)
6565
}
6666
}
6767

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ newtype_index! {
165165
}
166166
}
167167

168-
impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
168+
impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
169169

170170
impl From<ScopeData> for Scope {
171171
#[inline]

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct Mir<'tcx> {
132132
}
133133

134134
/// where execution begins
135-
pub const START_BLOCK: BasicBlock = BasicBlock(0);
135+
pub const START_BLOCK: BasicBlock = BasicBlock { private: 0 };
136136

137137
impl<'tcx> Mir<'tcx> {
138138
pub fn new(
@@ -239,7 +239,7 @@ impl<'tcx> Mir<'tcx> {
239239

240240
#[inline]
241241
pub fn local_kind(&self, local: Local) -> LocalKind {
242-
let index = local.0 as usize;
242+
let index = local.private as usize;
243243
if index == 0 {
244244
debug_assert!(
245245
self.local_decls[local].mutability == Mutability::Mut,

src/librustc/ty/sty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ impl DebruijnIndex {
12741274
/// you would need to shift the index for `'a` into 1 new binder.
12751275
#[must_use]
12761276
pub const fn shifted_in(self, amount: u32) -> DebruijnIndex {
1277-
DebruijnIndex(self.0 + amount)
1277+
DebruijnIndex { private: self.private + amount }
12781278
}
12791279

12801280
/// Update this index in place by shifting it "in" through
@@ -1287,7 +1287,7 @@ impl DebruijnIndex {
12871287
/// `amount` number of new binders.
12881288
#[must_use]
12891289
pub const fn shifted_out(self, amount: u32) -> DebruijnIndex {
1290-
DebruijnIndex(self.0 - amount)
1290+
DebruijnIndex { private: self.private - amount }
12911291
}
12921292

12931293
/// Update in place by shifting out from `amount` binders.
@@ -1316,11 +1316,11 @@ impl DebruijnIndex {
13161316
/// bound by one of the binders we are shifting out of, that is an
13171317
/// error (and should fail an assertion failure).
13181318
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self {
1319-
self.shifted_out((to_binder.0 - INNERMOST.0) as u32)
1319+
self.shifted_out((to_binder.private - INNERMOST.private) as u32)
13201320
}
13211321
}
13221322

1323-
impl_stable_hash_for!(tuple_struct DebruijnIndex { index });
1323+
impl_stable_hash_for!(struct DebruijnIndex { private });
13241324

13251325
/// Region utilities
13261326
impl RegionKind {

src/librustc_data_structures/indexed_vec.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ macro_rules! newtype_index {
9797
@vis [$v:vis]
9898
@debug_format [$debug_format:tt]) => (
9999
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
100-
$v struct $type(u32);
100+
$v struct $type {
101+
private: u32
102+
}
101103

102104
impl $type {
103105
/// Extract value of this index as an integer.
@@ -111,12 +113,12 @@ macro_rules! newtype_index {
111113
#[inline]
112114
fn new(value: usize) -> Self {
113115
assert!(value < ($max) as usize);
114-
$type(value as u32)
116+
$type { private: value as u32 }
115117
}
116118

117119
#[inline]
118120
fn index(self) -> usize {
119-
self.0 as usize
121+
self.private as usize
120122
}
121123
}
122124

@@ -151,13 +153,13 @@ macro_rules! newtype_index {
151153

152154
impl From<$type> for u32 {
153155
fn from(v: $type) -> u32 {
154-
v.0
156+
v.private
155157
}
156158
}
157159

158160
impl From<$type> for usize {
159161
fn from(v: $type) -> usize {
160-
v.0 as usize
162+
v.private as usize
161163
}
162164
}
163165

@@ -193,7 +195,7 @@ macro_rules! newtype_index {
193195
@debug_format [$debug_format:tt]) => (
194196
impl ::std::fmt::Debug for $type {
195197
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
196-
write!(fmt, $debug_format, self.0)
198+
write!(fmt, $debug_format, self.private)
197199
}
198200
}
199201
);
@@ -376,7 +378,7 @@ macro_rules! newtype_index {
376378
const $name:ident = $constant:expr,
377379
$($tokens:tt)*) => (
378380
$(#[doc = $doc])*
379-
pub const $name: $type = $type($constant);
381+
pub const $name: $type = $type { private: $constant };
380382
newtype_index!(
381383
@derives [$($derives,)*]
382384
@type [$type]

0 commit comments

Comments
 (0)