Skip to content

Commit 50d50ab

Browse files
committed
Restrict access to the private field of newtype indexes
1 parent b055a05 commit 50d50ab

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

compiler/rustc_macros/src/newtype.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Parse for Newtype {
9393
}
9494
impl<E: ::rustc_serialize::Encoder> ::rustc_serialize::Encodable<E> for #name {
9595
fn encode(&self, e: &mut E) {
96-
e.emit_u32(self.private);
96+
e.emit_u32(self.as_u32());
9797
}
9898
}
9999
}
@@ -150,7 +150,7 @@ impl Parse for Newtype {
150150
#[inline]
151151
fn eq(l: &Option<Self>, r: &Option<Self>) -> bool {
152152
if #max_val < u32::MAX {
153-
l.map(|i| i.private).unwrap_or(#max_val+1) == r.map(|i| i.private).unwrap_or(#max_val+1)
153+
l.map(|i| i.as_u32()).unwrap_or(#max_val+1) == r.map(|i| i.as_u32()).unwrap_or(#max_val+1)
154154
} else {
155155
match (l, r) {
156156
(Some(l), Some(r)) => r == l,
@@ -174,7 +174,7 @@ impl Parse for Newtype {
174174
#[rustc_layout_scalar_valid_range_end(#max)]
175175
#[rustc_pass_by_value]
176176
#vis struct #name {
177-
private: u32,
177+
private_use_as_methods_instead: u32,
178178
}
179179

180180
#(#consts)*
@@ -224,7 +224,7 @@ impl Parse for Newtype {
224224
/// Prefer using `from_u32`.
225225
#[inline]
226226
#vis const unsafe fn from_u32_unchecked(value: u32) -> Self {
227-
Self { private: value }
227+
Self { private_use_as_methods_instead: value as _ }
228228
}
229229

230230
/// Extracts the value of this index as a `usize`.
@@ -236,7 +236,7 @@ impl Parse for Newtype {
236236
/// Extracts the value of this index as a `u32`.
237237
#[inline]
238238
#vis const fn as_u32(self) -> u32 {
239-
self.private
239+
self.private_use_as_methods_instead as u32
240240
}
241241

242242
/// Extracts the value of this index as a `usize`.

compiler/rustc_type_ir/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,20 +819,20 @@ impl UniverseIndex {
819819
/// name the region `'a`, but that region was not nameable from
820820
/// `U` because it was not in scope there.
821821
pub fn next_universe(self) -> UniverseIndex {
822-
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
822+
UniverseIndex::from_u32(self.as_u32().checked_add(1).unwrap())
823823
}
824824

825825
/// Returns `true` if `self` can name a name from `other` -- in other words,
826826
/// if the set of names in `self` is a superset of those in
827827
/// `other` (`self >= other`).
828828
pub fn can_name(self, other: UniverseIndex) -> bool {
829-
self.private >= other.private
829+
self >= other
830830
}
831831

832832
/// Returns `true` if `self` cannot name some names from `other` -- in other
833833
/// words, if the set of names in `self` is a strict subset of
834834
/// those in `other` (`self < other`).
835835
pub fn cannot_name(self, other: UniverseIndex) -> bool {
836-
self.private < other.private
836+
self < other
837837
}
838838
}

0 commit comments

Comments
 (0)