Skip to content

Commit 1979772

Browse files
authored
Rollup merge of rust-lang#115634 - nnethercote:IntVid-FloatVid, r=oli-obk
Use `newtype_index` for `IntVid` and `FloatVid`. `TyVid` already uses `newtype_index`.
2 parents 38adedc + a932990 commit 1979772

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,13 @@ impl<'tcx> InferCtxt<'tcx> {
764764
.collect();
765765
vars.extend(
766766
(0..inner.int_unification_table().len())
767-
.map(|i| ty::IntVid { index: i as u32 })
767+
.map(|i| ty::IntVid::from_u32(i as u32))
768768
.filter(|&vid| inner.int_unification_table().probe_value(vid).is_none())
769769
.map(|v| Ty::new_int_var(self.tcx, v)),
770770
);
771771
vars.extend(
772772
(0..inner.float_unification_table().len())
773-
.map(|i| ty::FloatVid { index: i as u32 })
773+
.map(|i| ty::FloatVid::from_u32(i as u32))
774774
.filter(|&vid| inner.float_unification_table().probe_value(vid).is_none())
775775
.map(|v| Ty::new_float_var(self.tcx, v)),
776776
);

compiler/rustc_type_ir/src/lib.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,16 @@ rustc_index::newtype_index! {
574574
pub struct TyVid {}
575575
}
576576

577-
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
578-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
579-
pub struct IntVid {
580-
pub index: u32,
577+
rustc_index::newtype_index! {
578+
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
579+
#[debug_format = "?{}i"]
580+
pub struct IntVid {}
581581
}
582582

583-
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
584-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
585-
pub struct FloatVid {
586-
pub index: u32,
583+
rustc_index::newtype_index! {
584+
/// A **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
585+
#[debug_format = "?{}f"]
586+
pub struct FloatVid {}
587587
}
588588

589589
/// A placeholder for a type that hasn't been inferred yet.
@@ -645,11 +645,11 @@ impl UnifyKey for IntVid {
645645
type Value = Option<IntVarValue>;
646646
#[inline] // make this function eligible for inlining - it is quite hot.
647647
fn index(&self) -> u32 {
648-
self.index
648+
self.as_u32()
649649
}
650650
#[inline]
651651
fn from_index(i: u32) -> IntVid {
652-
IntVid { index: i }
652+
IntVid::from_u32(i)
653653
}
654654
fn tag() -> &'static str {
655655
"IntVid"
@@ -662,11 +662,11 @@ impl UnifyKey for FloatVid {
662662
type Value = Option<FloatVarValue>;
663663
#[inline]
664664
fn index(&self) -> u32 {
665-
self.index
665+
self.as_u32()
666666
}
667667
#[inline]
668668
fn from_index(i: u32) -> FloatVid {
669-
FloatVid { index: i }
669+
FloatVid::from_u32(i)
670670
}
671671
fn tag() -> &'static str {
672672
"FloatVid"
@@ -770,18 +770,6 @@ impl fmt::Debug for FloatVarValue {
770770
}
771771
}
772772

773-
impl fmt::Debug for IntVid {
774-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
775-
write!(f, "?{}i", self.index)
776-
}
777-
}
778-
779-
impl fmt::Debug for FloatVid {
780-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
781-
write!(f, "?{}f", self.index)
782-
}
783-
}
784-
785773
impl fmt::Debug for Variance {
786774
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
787775
f.write_str(match *self {

0 commit comments

Comments
 (0)